Skip to content

Latest commit

 

History

History
85 lines (54 loc) · 1.84 KB

.verb.md

File metadata and controls

85 lines (54 loc) · 1.84 KB

Usage

var startsWith = require('{%= name %}');

console.log(startsWith('foo/bar', 'foo')); //=> true
console.log(startsWith('foo/bar', 'bar')); //=> false

Negation

Prefix the substring with ! to return true when the path does not start with the substring.

console.log(startsWith('foo/bar', '!foo')); //=> false
console.log(startsWith('foo/bar', '!bar')); //=> true

options

options.nocase

Type: boolean

Default: false

Disable case sensitivity.

startsWith('foo/bar', 'FOO');                 
//=> false
startsWith('foo/bar', 'FOO', {nocase: true}); 
//=> true

options.partialMatch

Type: boolean

Default: false

Allow partial matches:

startsWith('foobar', 'foo');  //=> false                 
startsWith('foo.bar', 'foo'); //=> false                 

startsWith('foobar', 'foo', {partialMatch: true});  //=> true 
startsWith('foo.bar', 'foo', {partialMatch: true}); //=> true 

Comparison behavior

Windows paths

Backslashes are converted to forward slashes before the comparison is done. Thus, both of the following would be true:

console.log(startsWith('foo\\bar', 'foo/bar')); //=> true
console.log(startsWith('foo/bar', 'foo\\bar')); //=> true

Leading dot-slash

Leading ./ is stripped from both the filepath and substring. Thus, both of the following would be true:

console.log(startsWith('./foo/bar', 'foo')); //=> true
console.log(startsWith('foo/bar', './foo')); //=> true

Leading slashes

When the substring is prefixed with leading slashes, the number of leading slashes must match exactly.

console.log(startsWith('/foo', '/foo'));      //=> true
console.log(startsWith('/foo/bar', '/foo'));  //=> true

console.log(startsWith('/foo/bar', '//foo')); //=> false
console.log(startsWith('//foo/bar', '/foo')); //=> false