Skip to content

Commit

Permalink
Merge pull request #27 from nymag/is-page
Browse files Browse the repository at this point in the history
isPage util
  • Loading branch information
Allyson Young authored Apr 28, 2017
2 parents a1f50e6 + 5838d5e commit ae30af9
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ npm install --save clay-utils
* **getPageInstance** [(code|tests|docs)](https://github.com/nymag/clay-utils/tree/master/lib/getPageInstance)
* **isComponent** [(code|tests|docs)](https://github.com/nymag/clay-utils/tree/master/lib/isComponent)
* **isDefaultComponent** [(code|tests|docs)](https://github.com/nymag/clay-utils/tree/master/lib/isDefaultComponent)
* **isPage** [(code|tests|docs)](https://github.com/nymag/clay-utils/tree/master/lib/isPage)
* **replaceVersion** [(code|tests|docs)](https://github.com/nymag/clay-utils/tree/master/lib/replaceVersion)
2 changes: 1 addition & 1 deletion lib/isComponent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ const isUriStringCheck = require('../strCheck');
*/
module.exports = function (uri) {
isUriStringCheck.strCheck(uri);
return uri.toLowerCase().indexOf('/components/') >= 0;
return uri.toLowerCase().indexOf('/components/') > -1;
};
17 changes: 17 additions & 0 deletions lib/isPage/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
### isPage

Check if '/pages/' is in the uri

#### Params

* `uri` _string_

**Returns** _boolean_

#### Example

```js
isPage('nymag.com/scienceofus/pages/foobarbaz@published')
//=> true

```
14 changes: 14 additions & 0 deletions lib/isPage/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

const isUriStringCheck = require('../strCheck');

/**
* First test if argument is a String. If true, test if '/pages/' is in the string.
* Otherwise, throw an error.
* @param {string} uri
* @return {Boolean}
*/
module.exports = function (uri) {
isUriStringCheck.strCheck(uri);
return uri.toLowerCase().indexOf('/pages/') > -1;
};
28 changes: 28 additions & 0 deletions lib/isPage/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

const name = __filename.split('/').pop().split('.').shift(),
fn = require('./' + name),
expect = require('chai').expect;

describe('isPage', () => {
it('returns true if page reference', () => {
expect(fn('domain.com/pages/foo')).to.equal(true);
});

it('returns true if page instance reference', () => {
expect(fn('nymag.com/scienceofus/pages/foobarbaz@published')).to.equal(true);
});

it('throws an error if the URI passed in is not a string', () => {
const nonStringArgument = function () {
return fn([0, 1, 2, 3]);
};

expect(nonStringArgument).to.throw(Error);
});

it('returns false if non-page reference', () => {
expect(fn('domain.com/users/foo')).to.equal(false);
expect(fn('domain.com/components/foo')).to.equal(false);
});
});

0 comments on commit ae30af9

Please sign in to comment.