Socket
Socket
Sign inDemoInstall

wpapi

Package Overview
Dependencies
10
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.9.0-1 to 0.9.0-2

3

lib/resource-handler-spec.js

@@ -26,5 +26,4 @@ 'use strict';

node.names.forEach(function( name ) {
// camel-case the setter name
// Convert from snake_case to camelCase
var setterFnName = name
.toLowerCase()
.replace( /_\w/g, function( match ) {

@@ -31,0 +30,0 @@ return match.replace( '_', '' ).toUpperCase();

@@ -7,3 +7,3 @@ {

"name": "wpapi",
"version": "0.9.0-1",
"version": "0.9.0-2",
"description": "A client for interacting with the WordPress REST API",

@@ -10,0 +10,0 @@ "main": "wp.js",

@@ -391,4 +391,21 @@ A WordPress REST API client for JavaScript

Auto-discovery of all available routes will be supported in the near future, as will re-utilizing existing mixins (like `.search()`) on custom routes.
Re-utilizing existing mixins (like `.search()`) on custom routes will be supported in the near future.
#### Setter method naming for named route components
In the example above, registering the route string `'/author/(?P<id>\\d+)'` results in the creation of an `.id()` method on the resulting resource handler:
```js
site.myCustomResource().id( 7 ); // => myplugin/v1/author/7
```
If a named route component (e.g. `(?P<id>\\d+)`, above) is in `snake_case`, then that setter will be converted to camelCase instead, as with `some_part` below:
```js
site.myCustomResource = site.registerRoute( 'myplugin/v1', '/resource/(?P<some_part>\\d+)' );
site.myCustomResource().somePart( 7 ); // => myplugin/v1/resource/7
```
Non-snake_cased route parameter names will be unaffected.
## Embedding data

@@ -395,0 +412,0 @@

@@ -10,3 +10,2 @@ 'use strict';

var expect = chai.expect;
var sinon = require( 'sinon' );

@@ -13,0 +12,0 @@ /*jshint -W079 */// Suppress warning about redefiniton of `Promise`

@@ -70,3 +70,2 @@ 'use strict';

// custom route example for wp-api.org
describe( 'handler for /a/(?P<snake_cased_path_setter>\\d+)', function() {

@@ -90,3 +89,20 @@ var handler;

// custom route example for wp-api.org
describe( 'handler for /a/(?P<camelCasedPathSetter>\\d+)', function() {
var handler;
beforeEach(function() {
var factory = registerRoute( 'ns', '/a/(?P<camelCasedPathSetter>\\d+)' );
handler = factory({
endpoint: '/'
});
});
it( 'does not mutate the setter name', function() {
expect( handler ).not.to.have.property( 'camelcasedpathsetter' );
expect( handler ).to.have.property( 'camelCasedPathSetter' );
expect( handler.camelCasedPathSetter ).to.be.a( 'function' );
});
});
describe( 'handler for route with capture group named identically to existing method', function() {

@@ -110,2 +126,46 @@ var handler;

describe( 'handler for consecutive dynamic route segments', function() {
var handler;
beforeEach(function() {
var factory = registerRoute( 'ns', '/resource/(?P<part1>\\d+)/(?P<part2>\\d+)' );
handler = factory({
endpoint: '/'
});
});
describe( 'part1 method', function() {
it( 'is defined', function() {
expect( handler ).to.have.property( 'part1' );
});
it( 'is a function', function() {
expect( handler.part1 ).to.be.a( 'function' );
});
it( 'sets the part1 component of the path', function() {
expect( handler.part1( 12 )._renderURI() ).to.equal( '/ns/resource/12' );
});
});
describe( 'part2 method', function() {
it( 'is defined', function() {
expect( handler ).to.have.property( 'part2' );
});
it( 'is a function', function() {
expect( handler.part2 ).to.be.a( 'function' );
});
it( 'sets the part2 component of the path', function() {
expect( handler.part1( 12 ).part2( 34 )._renderURI() ).to.equal( '/ns/resource/12/34' );
});
});
});
describe( 'mixins', function() {

@@ -112,0 +172,0 @@ var handler;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc