@teambit/toolbox.path.match-patterns
Advanced tools
Comparing version 0.0.18 to 0.0.19
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, "matchPatterns", { | ||
enumerable: true, | ||
get: function () { | ||
return _matchPatterns().matchPatterns; | ||
} | ||
}); | ||
Object.defineProperty(exports, "splitPatterns", { | ||
enumerable: true, | ||
get: function () { | ||
return _matchPatterns().splitPatterns; | ||
} | ||
}); | ||
function _matchPatterns() { | ||
const data = require("./match-patterns"); | ||
_matchPatterns = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.matchPatterns = exports.splitPatterns = void 0; | ||
var match_patterns_1 = require("./match-patterns"); | ||
Object.defineProperty(exports, "splitPatterns", { enumerable: true, get: function () { return match_patterns_1.splitPatterns; } }); | ||
Object.defineProperty(exports, "matchPatterns", { enumerable: true, get: function () { return match_patterns_1.matchPatterns; } }); | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
function _chai() { | ||
const data = require("chai"); | ||
_chai = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _matchPatterns() { | ||
const data = require("./match-patterns"); | ||
_matchPatterns = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const chai_1 = require("chai"); | ||
const match_patterns_1 = require("./match-patterns"); | ||
describe('Match patterns', () => { | ||
const patterns = ['**/*.ts', '**/*.js', '!**/*.md', '!**/*.json']; | ||
it('it should split patterns between include & exclude', async () => { | ||
const { | ||
includePatterns, | ||
excludePatterns | ||
} = (0, _matchPatterns().splitPatterns)(patterns); | ||
(0, _chai().expect)(includePatterns).to.include.members(['**/*.ts', '**/*.js']); | ||
(0, _chai().expect)(excludePatterns).to.include.members(['!**/*.md', '!**/*.json']); | ||
}); | ||
it('it should match file patterns', async () => { | ||
const { | ||
includePatterns, | ||
excludePatterns | ||
} = (0, _matchPatterns().splitPatterns)(patterns); | ||
(0, _chai().expect)((0, _matchPatterns().matchPatterns)('some/path/file.ts', includePatterns, excludePatterns)).to.be.true; | ||
(0, _chai().expect)((0, _matchPatterns().matchPatterns)('some/path/file.js', includePatterns, excludePatterns)).to.be.true; | ||
(0, _chai().expect)((0, _matchPatterns().matchPatterns)('some/path/file.md', includePatterns, excludePatterns)).to.be.false; | ||
(0, _chai().expect)((0, _matchPatterns().matchPatterns)('some/path/file.json', includePatterns, excludePatterns)).to.be.false; | ||
(0, _chai().expect)((0, _matchPatterns().matchPatterns)('some/path/file.doc', includePatterns, excludePatterns)).to.be.false; | ||
}); | ||
it('it should match compositions', async () => { | ||
const compositionFilePattern = ['**/*.composition?(s).*']; | ||
const { | ||
includePatterns, | ||
excludePatterns | ||
} = (0, _matchPatterns().splitPatterns)(compositionFilePattern); | ||
(0, _chai().expect)((0, _matchPatterns().matchPatterns)('some/path/file.ts', includePatterns, excludePatterns)).to.be.false; | ||
(0, _chai().expect)((0, _matchPatterns().matchPatterns)('some/path/file.composition.ts', includePatterns, excludePatterns)).to.be.true; | ||
}); | ||
const patterns = ['**/*.ts', '**/*.js', '!**/*.md', '!**/*.json']; | ||
it('it should split patterns between include & exclude', async () => { | ||
const { includePatterns, excludePatterns } = (0, match_patterns_1.splitPatterns)(patterns); | ||
(0, chai_1.expect)(includePatterns).to.include.members(['**/*.ts', '**/*.js']); | ||
(0, chai_1.expect)(excludePatterns).to.include.members(['!**/*.md', '!**/*.json']); | ||
}); | ||
it('it should match file patterns', async () => { | ||
const { includePatterns, excludePatterns } = (0, match_patterns_1.splitPatterns)(patterns); | ||
(0, chai_1.expect)((0, match_patterns_1.matchPatterns)('some/path/file.ts', includePatterns, excludePatterns)).to.be.true; | ||
(0, chai_1.expect)((0, match_patterns_1.matchPatterns)('some/path/file.js', includePatterns, excludePatterns)).to.be.true; | ||
(0, chai_1.expect)((0, match_patterns_1.matchPatterns)('some/path/file.md', includePatterns, excludePatterns)).to.be.false; | ||
(0, chai_1.expect)((0, match_patterns_1.matchPatterns)('some/path/file.json', includePatterns, excludePatterns)).to.be.false; | ||
(0, chai_1.expect)((0, match_patterns_1.matchPatterns)('some/path/file.doc', includePatterns, excludePatterns)).to.be.false; | ||
}); | ||
it('it should match compositions', async () => { | ||
const compositionFilePattern = ['**/*.composition?(s).*']; | ||
const { includePatterns, excludePatterns } = (0, match_patterns_1.splitPatterns)(compositionFilePattern); | ||
(0, chai_1.expect)((0, match_patterns_1.matchPatterns)('some/path/file.ts', includePatterns, excludePatterns)).to.be.false; | ||
(0, chai_1.expect)((0, match_patterns_1.matchPatterns)('some/path/file.composition.ts', includePatterns, excludePatterns)).to.be.true; | ||
}); | ||
}); | ||
//# sourceMappingURL=match-pattern.spec.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.matchPatterns = matchPatterns; | ||
exports.splitPatterns = splitPatterns; | ||
function _minimatch() { | ||
const data = _interopRequireDefault(require("minimatch")); | ||
_minimatch = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } | ||
const minimatch_1 = __importDefault(require("minimatch")); | ||
/** | ||
@@ -20,11 +13,10 @@ * Checks if a string matches a list of patterns. | ||
function matchPatterns(filePath, includePatterns, excludePatterns) { | ||
const included = includePatterns.some(pattern => { | ||
return (0, _minimatch().default)(filePath, pattern); | ||
}); | ||
const excluded = excludePatterns.every(pattern => { | ||
return (0, _minimatch().default)(filePath, pattern); | ||
}); | ||
return included && excluded; | ||
const included = includePatterns.some((pattern) => { | ||
return (0, minimatch_1.default)(filePath, pattern); | ||
}); | ||
const excluded = excludePatterns.every((pattern) => { | ||
return (0, minimatch_1.default)(filePath, pattern); | ||
}); | ||
return included && excluded; | ||
} | ||
/** | ||
@@ -35,8 +27,7 @@ * Given a list of patterns, returns include and exclude patterns. | ||
function splitPatterns(patterns) { | ||
return { | ||
includePatterns: patterns.filter(pattern => !pattern.startsWith('!')), | ||
excludePatterns: patterns.filter(pattern => pattern.startsWith('!')) | ||
}; | ||
return { | ||
includePatterns: patterns.filter((pattern) => !pattern.startsWith('!')), | ||
excludePatterns: patterns.filter((pattern) => pattern.startsWith('!')), | ||
}; | ||
} | ||
//# sourceMappingURL=match-patterns.js.map |
{ | ||
"name": "@teambit/toolbox.path.match-patterns", | ||
"version": "0.0.18", | ||
"version": "0.0.19", | ||
"homepage": "https://bit.cloud/teambit/toolbox/path/match-patterns", | ||
@@ -9,3 +9,3 @@ "main": "dist/index.js", | ||
"name": "path/match-patterns", | ||
"version": "0.0.18" | ||
"version": "0.0.19" | ||
}, | ||
@@ -20,3 +20,3 @@ "dependencies": { | ||
"@types/mocha": "9.1.0", | ||
"@teambit/node.envs.node-babel-mocha": "0.1.4" | ||
"@teambit/node.envs.node-typescript-mocha": "0.0.1" | ||
}, | ||
@@ -23,0 +23,0 @@ "peerDependencies": {}, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
13010
200