@teambit/toolbox.path.match-patterns
Advanced tools
Comparing version
"use strict"; | ||
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; } }); | ||
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; | ||
} | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const chai_1 = require("chai"); | ||
const match_patterns_1 = require("./match-patterns"); | ||
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; | ||
} | ||
describe('Match patterns', () => { | ||
const patterns = ['**/*.ts', '**/*.js', '!**/*.md', '!**/*.json']; | ||
it('it should split patterns between include & exclude', () => __awaiter(void 0, void 0, void 0, function* () { | ||
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', () => __awaiter(void 0, void 0, void 0, function* () { | ||
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', () => __awaiter(void 0, void 0, void 0, function* () { | ||
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; | ||
})); | ||
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; | ||
}); | ||
}); | ||
//# sourceMappingURL=match-pattern.spec.js.map |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.matchPatterns = matchPatterns; | ||
exports.splitPatterns = splitPatterns; | ||
const minimatch_1 = __importDefault(require("minimatch")); | ||
function _minimatch() { | ||
const data = _interopRequireDefault(require("minimatch")); | ||
_minimatch = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } | ||
/** | ||
@@ -13,10 +20,11 @@ * Checks if a string matches a list of patterns. | ||
function matchPatterns(filePath, includePatterns, excludePatterns) { | ||
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; | ||
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; | ||
} | ||
/** | ||
@@ -27,7 +35,8 @@ * 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.17", | ||
"version": "0.0.18", | ||
"homepage": "https://bit.cloud/teambit/toolbox/path/match-patterns", | ||
@@ -9,3 +9,3 @@ "main": "dist/index.js", | ||
"name": "path/match-patterns", | ||
"version": "0.0.17" | ||
"version": "0.0.18" | ||
}, | ||
@@ -20,4 +20,3 @@ "dependencies": { | ||
"@types/mocha": "9.1.0", | ||
"@types/jest": "26.0.20", | ||
"@types/node": "22.10.5" | ||
"@teambit/node.envs.node-babel-mocha": "0.1.4" | ||
}, | ||
@@ -24,0 +23,0 @@ "peerDependencies": {}, |
@@ -8,8 +8,8 @@ declare module '*.png' { | ||
export const ReactComponent: FunctionComponent<SVGProps<SVGSVGElement> & { title?: string }>; | ||
export const ReactComponent: FunctionComponent< | ||
SVGProps<SVGSVGElement> & { title?: string } | ||
>; | ||
const src: string; | ||
export default src; | ||
} | ||
// @TODO Gilad | ||
declare module '*.jpg' { | ||
@@ -31,1 +31,13 @@ const value: any; | ||
} | ||
declare module '*.otf' { | ||
const value: any; | ||
export = value; | ||
} | ||
declare module '*.woff' { | ||
const value: any; | ||
export = value; | ||
} | ||
declare module '*.woff2' { | ||
const value: any; | ||
export = value; | ||
} |
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
16491
18.43%5
-16.67%243
20.9%17
-5.56%