-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from nymag/is-page
isPage util
- Loading branch information
Showing
5 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |