Skip to content

Commit

Permalink
isUri (#8)
Browse files Browse the repository at this point in the history
* adding test for Uri

* fix name
  • Loading branch information
jonwinton authored Jun 18, 2018
1 parent 78ca414 commit 7158854
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ npm install --save clayutils
* **isList** [(code|tests|docs)](https://github.com/clay/clayutils/tree/master/lib/isList)
* **isPage** [(code|tests|docs)](https://github.com/clay/clayutils/tree/master/lib/isPage)
* **isPublished** [(code|tests|docs)](https://github.com/clay/clayutils/tree/master/lib/isPublished)
* **isUri** [(code|tests|docs)](https://github.com/clay/clayutils/tree/master/lib/isUri)
* **isUser** [(code|tests|docs)](https://github.com/clay/clayutils/tree/master/lib/isUser)
* **jsonPrefixToSlug** [(code|tests|docs)](https://github.com/clay/clayutils/tree/master/lib/jsonPrefixToSlug)
* **jsonSlugToPrefix** [(code|tests|docs)](https://github.com/clay/clayutils/tree/master/lib/jsonSlugToPrefix)
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports.isDefaultComponent = require('./lib/isDefaultComponent');
module.exports.isPage = require('./lib/isPage');
module.exports.isPublished = require('./lib/isPublished');
module.exports.isList = require('./lib/isList');
module.exports.isUri = require('./lib/isUri');
module.exports.isUser = require('./lib/isUser');
module.exports.replaceVersion = require('./lib/replaceVersion');
module.exports.uriPrefixToSlug = require('./lib/uriPrefixToSlug');
Expand Down
17 changes: 17 additions & 0 deletions lib/isUri/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
### isUri

Check if '/_uris/' is in the uri

#### Params

* `uri` _string_

**Returns** _boolean_

#### Example

```js
isUri('nymag.com/_uris/someuriid')
//=> true

```
14 changes: 14 additions & 0 deletions lib/isUri/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 '/_uris/' is in the string.
* Otherwise, throw an error.
* @param {string} uri
* @return {Boolean}
*/
module.exports = function (uri) {
isUriStringCheck.strCheck(uri);
return uri.toLowerCase().indexOf('/_uris/') > -1;
};
28 changes: 28 additions & 0 deletions lib/isUri/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('isUri', () => {
it('returns true if uri reference', () => {
expect(fn('domain.com/_uris/foo')).to.equal(true);
});

it('returns true if uri instance reference', () => {
expect(fn('nymag.com/scienceofus/_uris/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-uri reference', () => {
expect(fn('domain.com/_users/foo')).to.equal(false);
expect(fn('domain.com/_components/foo')).to.equal(false);
});
});

0 comments on commit 7158854

Please sign in to comment.