Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add isPublished function #7

Merged
merged 2 commits into from
May 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@ typings/
# dotenv environment variables file
.env

# Webstorm
.idea
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ npm install --save clayutils
* **isDefaultComponent** [(code|tests|docs)](https://github.com/clay/clayutils/tree/master/lib/isDefaultComponent)
* **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)
* **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 @@ -9,6 +9,7 @@ module.exports.getPrefix = require('./lib/getPrefix');
module.exports.isComponent = require('./lib/isComponent');
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.isUser = require('./lib/isUser');
module.exports.replaceVersion = require('./lib/replaceVersion');
Expand Down
20 changes: 20 additions & 0 deletions lib/isPublished/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
### isPublished

Check if '@published' is in the uri

#### Params

* `uri` _string_

**Returns** _boolean_

#### Example

```js
isPublished('nymag.com/press/_components/base/instances/foobarbaz@published')
//=> true

isPublished('nymag.com/press/_components/base/instances/foobarbaz')
//=> false

```
14 changes: 14 additions & 0 deletions lib/isPublished/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 '@published' is in the string.
* Otherwise, throw an error.
* @param {string} uri
* @return {Boolean}
*/
module.exports = function (uri) {
isUriStringCheck.strCheck(uri);
return uri.indexOf('@published') !== -1;
};
23 changes: 23 additions & 0 deletions lib/isPublished/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

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

describe('isPublished', () => {
it('returns true if the reference is published', () => {
expect(fn('domain.com/_components/foo/instances/bar@published')).to.equal(true);
});

it('returns false if the reference is not published', () => {
expect(fn('domain.com/_components/foo/instances/bar')).to.equal(false);
});

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);
});
});