Skip to content

Commit

Permalink
add isRelativeModule
Browse files Browse the repository at this point in the history
  • Loading branch information
yiminghe committed Jun 29, 2015
1 parent cd2611b commit 82b5e13
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
9 changes: 8 additions & 1 deletion index.js
Expand Up @@ -47,8 +47,15 @@ function splitPackageName(moduleName) {
}
}

function startsWith(str, prefix) {
return str.slice(0, prefix.length) === prefix;
}

module.exports = {
findAll: findAll,
replaceAll: replaceAll,
splitPackageName: splitPackageName
splitPackageName: splitPackageName,
isRelativeModule: function (dep) {
return startsWith(dep, './') || startsWith(dep, '../');
}
};
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "match-require",
"version": "1.0.1",
"version": "1.0.2",
"description": "find require calls from string using regexp",
"keywords": [
"require",
Expand Down
14 changes: 14 additions & 0 deletions tests/spec/index.js
Expand Up @@ -80,4 +80,18 @@ describe('match require', function () {
});
});
});

describe('isRelativeModule',function(){
it('works for xx',function(){
expect(matchRequire.isRelativeModule('xx')).to.be(false);
});

it('works for ../x',function(){
expect(matchRequire.isRelativeModule('../xx')).to.be(true);
});

it('works for ./x',function(){
expect(matchRequire.isRelativeModule('./xx')).to.be(true);
});
});
});

0 comments on commit 82b5e13

Please sign in to comment.