{"id":28566431,"url":"https://github.com/js-devtools/file-path-filter","last_synced_at":"2025-06-10T15:10:54.183Z","repository":{"id":57122417,"uuid":"192344985","full_name":"JS-DevTools/file-path-filter","owner":"JS-DevTools","description":"Filters file paths using globs, regular expressions, or custom criteria","archived":false,"fork":false,"pushed_at":"2020-07-16T13:52:50.000Z","size":204,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-03T21:58:05.265Z","etag":null,"topics":["file-path","filepath","filesystem","filter","glob","globstar","javascript","nodejs","regular-expression"],"latest_commit_sha":null,"homepage":"https://jstools.dev/file-path-filter/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JS-DevTools.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-17T12:42:57.000Z","updated_at":"2023-09-08T17:54:56.000Z","dependencies_parsed_at":"2022-08-24T14:59:28.686Z","dependency_job_id":null,"html_url":"https://github.com/JS-DevTools/file-path-filter","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":"JS-DevTools/template-node-typescript","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JS-DevTools%2Ffile-path-filter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JS-DevTools%2Ffile-path-filter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JS-DevTools%2Ffile-path-filter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JS-DevTools%2Ffile-path-filter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JS-DevTools","download_url":"https://codeload.github.com/JS-DevTools/file-path-filter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JS-DevTools%2Ffile-path-filter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259098639,"owners_count":22804794,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["file-path","filepath","filesystem","filter","glob","globstar","javascript","nodejs","regular-expression"],"created_at":"2025-06-10T15:10:52.301Z","updated_at":"2025-06-10T15:10:54.169Z","avatar_url":"https://github.com/JS-DevTools.png","language":"JavaScript","readme":"# File Path Filter\nFilters file paths using globs, regular expressions, or custom criteria\n\n[![Cross-Platform Compatibility](https://jstools.dev/img/badges/os-badges.svg)](https://github.com/JS-DevTools/file-path-filter/actions)\n[![Build Status](https://github.com/JS-DevTools/file-path-filter/workflows/CI-CD/badge.svg)](https://github.com/JS-DevTools/file-path-filter/actions)\n\n[![Coverage Status](https://coveralls.io/repos/github/JS-DevTools/file-path-filter/badge.svg?branch=master)](https://coveralls.io/github/JS-DevTools/file-path-filter)\n[![Dependencies](https://david-dm.org/JS-DevTools/file-path-filter.svg)](https://david-dm.org/JS-DevTools/file-path-filter)\n\n[![npm](https://img.shields.io/npm/v/@jsdevtools/file-path-filter.svg)](https://www.npmjs.com/package/@jsdevtools/file-path-filter)\n[![License](https://img.shields.io/npm/l/@jsdevtools/file-path-filter.svg)](LICENSE)\n[![Buy us a tree](https://img.shields.io/badge/Treeware-%F0%9F%8C%B3-lightgreen)](https://plant.treeware.earth/JS-DevTools/file-path-filter)\n\n\n\nExample\n--------------------------\n\n```javascript\nconst filePathFilter = require(\"@jsdevtools/file-path-filter\");\n\nconst paths = [\n  \"/some/path/index.html\",\n  \"/some/path/contact.html\",\n  \"/some/path/about.html\",\n  \"/some/path/favicon.ico\",\n  \"/some/path/img/logo.png\",\n];\n\n// Filter using a glob pattern\npaths.filter(filePathFilter(\"**/*.html\"));\n\n// Exclude glob patterns with \"!\"\npaths.filter(filePathFilter(\"**/*.html\", \"!**/index.html\"));\n\n// Filter using a regular expression\npaths.filter(filePathFilter(/\\.(ico|png)$/));\n\n// Filter using custom criteria\npaths.filter(filePathFilter(path =\u003e path.length === 23));\n\n// Use any combination of filters\npaths.filter(filePathFilter([\n  \"**/*.html\",\n  \"!**/index.html\",\n  /\\.(ico|png)$/,\n  path =\u003e path.length === 23\n]));\n\n// Explicitly specify include and exclude criteria\npaths.filter(filePathFilter({\n  include:  [\n    \"**/*.html\",\n    /\\.(ico|png)$/,\n    path =\u003e path.length === 23\n  ],\n  exclude: \"**/index.html\",\n));\n\n```\n\n\n\nInstallation\n--------------------------\nYou can install File Path Filter via [npm](https://docs.npmjs.com/about-npm/).\n\n```bash\nnpm install @jsdevtools/file-path-filter\n```\n\n\n\nUsage\n--------------------------\n\n### filePathFilter(criteria)\n\n- **`criteria`** - The filter criteria. This can be any of the following:\n  - A boolean. `true` will match all files. `false` will not match any files.\n  - A [glob pattern](https://en.wikipedia.org/wiki/Glob_(programming)). If the pattern starts with `!`, then it will be treated as an `exclude` pattern (see below)\n  - A [regular expression](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp)\n  - A [filter function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter#Syntax) that accepts a file path and returns `true` if the file should be matched\n  - An array containing any combination of the above types\n  - An object with `include` and `exclude` properties. Each of these properties can be any of the above types.  File paths will be matched if they match any of the `include` criteria and do not match any of the `exclude` criteria.\n\n- **`return value`** - A [filter function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter#Syntax) that matches file paths that meet the specified criteria\n\n\n### createFilter(options, criteria)\n\n- **`options`** - An object with some or all of the following properties:\n  - `map` - A function that maps filtered items to file paths\n  - `sep` - A custom path separator, such as `\\` or `/`\n\n- **`criteria`** - The filter criteria. See the [`filePathFilter`](#filepathfiltercriteria) for details.\n\n- **`return value`** - A [filter function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter#Syntax) that matches file paths that meet the specified criteria\n\nThe `createFilter` function is an alternative to the `filePathFilter` function that allows you to customize the behavior to suit your needs.\n\n#### Filtering objects\nThe `filePathFilter` function creates a function that filters arrays of strings, but what if you need to filter an array of objects instead?  That's where the `map` option comes in handy. You can use it to map objects (or any other value) to file paths.  Here's an example:\n\n```javascript\nconst { createFilter } = require(\"@jsdevtools/file-path-filter\");\nconst path = require(\"path\");\n\nconst files = [\n  { dir: \"/my/website\", filename: \"index.html\" },\n  { dir: \"/my/website\", filename: \"contact.html\" },\n  { dir: \"/my/website/blog\", filename: \"post-1.html\" },\n  { dir: \"/my/website/blog\", filename: \"post-2.html\" },\n];\n\n// A function to returns the path of each file\nfunction map(file) {\n  return path.join(file.dir, file.filename);\n}\n\n// Filter the file objects - return all HTML files except the blog posts\nfiles.filter(createFilter({ map }, \"**/*.html\", \"!**/blog/*.html\"));\n```\n\n\nContributing\n--------------------------\nContributions, enhancements, and bug-fixes are welcome!  [Open an issue](https://github.com/JS-DevTools/file-path-filter/issues) on GitHub and [submit a pull request](https://github.com/JS-DevTools/file-path-filter/pulls).\n\n#### Building\nTo build the project locally on your computer:\n\n1. __Clone this repo__\u003cbr\u003e\n`git clone https://github.com/JS-DevTools/file-path-filter.git`\n\n2. __Install dependencies__\u003cbr\u003e\n`npm install`\n\n3. __Build the code__\u003cbr\u003e\n`npm run build`\n\n4. __Run the tests__\u003cbr\u003e\n`npm test`\n\n\n\nLicense\n--------------------------\nFile Path Filter is 100% free and open-source, under the [MIT license](LICENSE). Use it however you want.\n\nThis package is [Treeware](http://treeware.earth). If you use it in production, then we ask that you [**buy the world a tree**](https://plant.treeware.earth/JS-DevTools/file-path-filter) to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.\n\n\n\nBig Thanks To\n--------------------------\nThanks to these awesome companies for their support of Open Source developers ❤\n\n[![Travis CI](https://jstools.dev/img/badges/travis-ci.svg)](https://travis-ci.com)\n[![SauceLabs](https://jstools.dev/img/badges/sauce-labs.svg)](https://saucelabs.com)\n[![Coveralls](https://jstools.dev/img/badges/coveralls.svg)](https://coveralls.io)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjs-devtools%2Ffile-path-filter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjs-devtools%2Ffile-path-filter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjs-devtools%2Ffile-path-filter/lists"}