{"name":"ignore","version":"7.0.3","description":"Ignore is a manager and filter for .gitignore rules, the one used by eslint, gitbook and many others.","types":"index.d.ts","scripts":{"prepublishOnly":"npm run build","build":"babel -o legacy.js index.js","==================== linting ======================":"","lint":"eslint .","===================== import ======================":"","ts":"npm run test:ts && npm run test:16","test:ts":"ts-node ./test/import/simple.ts","test:16":"npm run test:ts:16 && npm run test:cjs:16 && npm run test:mjs:16","test:ts:16":"ts-node --compilerOptions '{\"moduleResolution\": \"Node16\", \"module\": \"Node16\"}' ./test/import/simple.ts && tsc ./test/import/simple.ts --lib ES6 --moduleResolution Node16 --module Node16 && node ./test/import/simple.js","test:cjs:16":"ts-node --compilerOptions '{\"moduleResolution\": \"Node16\", \"module\": \"Node16\"}' ./test/import/simple.cjs","test:mjs:16":"ts-node --compilerOptions '{\"moduleResolution\": \"Node16\", \"module\": \"Node16\"}' ./test/import/simple.mjs && babel -o ./test/import/simple-mjs.js ./test/import/simple.mjs && node ./test/import/simple-mjs.js","===================== cases =======================":"","test:cases":"npm run tap test/*.test.js -- --coverage","tap":"tap --reporter classic","===================== debug =======================":"","test:git":"npm run tap test/git-check-ignore.test.js","test:ignore":"npm run tap test/ignore.test.js","test:ignore:only":"IGNORE_ONLY_IGNORES=1 npm run tap test/ignore.test.js","test:others":"npm run tap test/others.test.js","test:no-coverage":"npm run tap test/*.test.js -- --no-check-coverage","test":"npm run lint && npm run ts && npm run build && npm run test:cases","test:win32":"IGNORE_TEST_WIN32=1 npm run test","report":"tap --coverage-report=html"},"repository":{"type":"git","url":"git+ssh://git@github.com/kaelzhang/node-ignore.git"},"keywords":["ignore",".gitignore","gitignore","npmignore","rules","manager","filter","regexp","regex","fnmatch","glob","asterisks","regular-expression"],"author":{"name":"kael"},"license":"MIT","bugs":{"url":"https://github.com/kaelzhang/node-ignore/issues"},"devDependencies":{"@babel/cli":"^7.22.9","@babel/core":"^7.22.9","@babel/preset-env":"^7.22.9","@typescript-eslint/eslint-plugin":"^8.19.1","codecov":"^3.8.3","debug":"^4.3.4","eslint":"^8.46.0","eslint-config-ostai":"^3.0.0","eslint-plugin-import":"^2.28.0","mkdirp":"^3.0.1","pre-suf":"^1.1.1","rimraf":"^6.0.1","spawn-sync":"^2.0.0","tap":"^16.3.9","tmp":"0.2.3","ts-node":"^10.9.2","typescript":"^5.6.2"},"engines":{"node":">= 4"},"_id":"ignore@7.0.3","gitHead":"f0bd5340a18a45433f231523c1604a36e18a5931","homepage":"https://github.com/kaelzhang/node-ignore#readme","_nodeVersion":"22.8.0","_npmVersion":"10.8.2","dist":{"integrity":"sha512-bAH5jbK/F3T3Jls4I0SO1hmPR0dKU0a7+SY6n1yzRtG54FLO8d6w/nxLFX2Nb7dBu6cCWXPaAME6cYqFUMmuCA==","shasum":"397ef9315dfe0595671eefe8b633fec6943ab733","tarball":"http://registry-npm.ywwl.com/ignore/download/ignore-7.0.3.tgz","fileCount":6,"unpackedSize":63148,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCf+xD/td3ut8+nqNebo96773yMc3NKNz0lJMNOvbu28wIgSeFamXXPPFbewYRHDOvMsfAniVHvCFLQmBAUBdHfqRQ="}],"size":17205,"noattachment":false,"key":"/ignore/-/ignore-7.0.3.tgz"},"_npmUser":{"name":"kael","email":"i@kael.me"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/ignore_7.0.3_1736826761173_0.4683158000951846"},"_hasShrinkwrap":false,"readme":"| Linux / MacOS / Windows | Coverage | Downloads |\n| ----------------------- | -------- | --------- |\n| [![build][bb]][bl]      | [![coverage][cb]][cl] | [![downloads][db]][dl] |\n\n[bb]: https://github.com/kaelzhang/node-ignore/actions/workflows/nodejs.yml/badge.svg\n[bl]: https://github.com/kaelzhang/node-ignore/actions/workflows/nodejs.yml\n\n[cb]: https://codecov.io/gh/kaelzhang/node-ignore/branch/master/graph/badge.svg\n[cl]: https://codecov.io/gh/kaelzhang/node-ignore\n\n[db]: http://img.shields.io/npm/dm/ignore.svg\n[dl]: https://www.npmjs.org/package/ignore\n\n# ignore\n\n`ignore` is a manager, filter and parser which implemented in pure JavaScript according to the [.gitignore spec 2.22.1](http://git-scm.com/docs/gitignore).\n\n`ignore` is used by eslint, gitbook and [many others](https://www.npmjs.com/browse/depended/ignore).\n\nPay **ATTENTION** that [`minimatch`](https://www.npmjs.org/package/minimatch) (which used by `fstream-ignore`) does not follow the gitignore spec.\n\nTo filter filenames according to a .gitignore file, I recommend this npm package, `ignore`.\n\nTo parse an `.npmignore` file, you should use `minimatch`, because an `.npmignore` file is parsed by npm using `minimatch` and it does not work in the .gitignore way.\n\n### Tested on\n\n`ignore` is fully tested, and has more than **five hundreds** of unit tests.\n\n- Linux + Node: `0.8` - `7.x`\n- Windows + Node: `0.10` - `7.x`, node < `0.10` is not tested due to the lack of support of appveyor.\n\nActually, `ignore` does not rely on any versions of node specially.\n\nSince `4.0.0`, ignore will no longer support `node < 6` by default, to use in node < 6, `require('ignore/legacy')`. For details, see [CHANGELOG](https://github.com/kaelzhang/node-ignore/blob/master/CHANGELOG.md).\n\n## Table Of Main Contents\n\n- [Usage](#usage)\n- [`Pathname` Conventions](#pathname-conventions)\n- See Also:\n  - [`glob-gitignore`](https://www.npmjs.com/package/glob-gitignore) matches files using patterns and filters them according to gitignore rules.\n- [Upgrade Guide](#upgrade-guide)\n\n## Install\n\n```sh\nnpm i ignore\n```\n\n## Usage\n\n```js\nimport ignore from 'ignore'\nconst ig = ignore().add(['.abc/*', '!.abc/d/'])\n```\n\n### Filter the given paths\n\n```js\nconst paths = [\n  '.abc/a.js',    // filtered out\n  '.abc/d/e.js'   // included\n]\n\nig.filter(paths)        // ['.abc/d/e.js']\nig.ignores('.abc/a.js') // true\n```\n\n### As the filter function\n\n```js\npaths.filter(ig.createFilter()); // ['.abc/d/e.js']\n```\n\n### Win32 paths will be handled\n\n```js\nig.filter(['.abc\\\\a.js', '.abc\\\\d\\\\e.js'])\n// if the code above runs on windows, the result will be\n// ['.abc\\\\d\\\\e.js']\n```\n\n## Why another ignore?\n\n- `ignore` is a standalone module, and is much simpler so that it could easy work with other programs, unlike [isaacs](https://npmjs.org/~isaacs)'s [fstream-ignore](https://npmjs.org/package/fstream-ignore) which must work with the modules of the fstream family.\n\n- `ignore` only contains utility methods to filter paths according to the specified ignore rules, so\n  - `ignore` never try to find out ignore rules by traversing directories or fetching from git configurations.\n  - `ignore` don't cares about sub-modules of git projects.\n\n- Exactly according to [gitignore man page](http://git-scm.com/docs/gitignore), fixes some known matching issues of fstream-ignore, such as:\n  - '`/*.js`' should only match '`a.js`', but not '`abc/a.js`'.\n  - '`**/foo`' should match '`foo`' anywhere.\n  - Prevent re-including a file if a parent directory of that file is excluded.\n  - Handle trailing whitespaces:\n    - `'a '`(one space) should not match `'a  '`(two spaces).\n    - `'a \\ '` matches `'a  '`\n  - All test cases are verified with the result of `git check-ignore`.\n\n# Methods\n\n## .add(pattern: string | Ignore): this\n## .add(patterns: Array<string | Ignore>): this\n## .add({pattern: string, mark?: string}): this  since 7.0.0\n\n- **pattern** `string | Ignore` An ignore pattern string, or the `Ignore` instance\n- **patterns** `Array<string | Ignore>` Array of ignore patterns.\n- **mark?** `string` Pattern mark, which is used to associate the pattern with a certain marker, such as the line no of the `.gitignore` file. Actually it could be an arbitrary string and is optional.\n\nAdds a rule or several rules to the current manager.\n\nReturns `this`\n\nNotice that a line starting with `'#'`(hash) is treated as a comment. Put a backslash (`'\\'`) in front of the first hash for patterns that begin with a hash, if you want to ignore a file with a hash at the beginning of the filename.\n\n```js\nignore().add('#abc').ignores('#abc')    // false\nignore().add('\\\\#abc').ignores('#abc')   // true\n```\n\n`pattern` could either be a line of ignore pattern or a string of multiple ignore patterns, which means we could just `ignore().add()` the content of a ignore file:\n\n```js\nignore()\n.add(fs.readFileSync(filenameOfGitignore).toString())\n.filter(filenames)\n```\n\n`pattern` could also be an `ignore` instance, so that we could easily inherit the rules of another `Ignore` instance.\n\n## .ignores(pathname: [Pathname](#pathname-conventions)): boolean\n\n> new in 3.2.0\n\nReturns `Boolean` whether `pathname` should be ignored.\n\n```js\nig.ignores('.abc/a.js')    // true\n```\n\nPlease **PAY ATTENTION** that `.ignores()` is **NOT** equivalent to `git check-ignore` although in most cases they return equivalent results.\n\nHowever, for the purposes of imitating the behavior of `git check-ignore`, please use `.checkIgnore()` instead.\n\n### `Pathname` Conventions:\n\n#### 1. `Pathname` should be a `path.relative()`d pathname\n\n`Pathname` should be a string that have been `path.join()`ed, or the return value of `path.relative()` to the current directory,\n\n```js\n// WRONG, an error will be thrown\nig.ignores('./abc')\n\n// WRONG, for it will never happen, and an error will be thrown\n// If the gitignore rule locates at the root directory,\n// `'/abc'` should be changed to `'abc'`.\n// ```\n// path.relative('/', '/abc')  -> 'abc'\n// ```\nig.ignores('/abc')\n\n// WRONG, that it is an absolute path on Windows, an error will be thrown\nig.ignores('C:\\\\abc')\n\n// Right\nig.ignores('abc')\n\n// Right\nig.ignores(path.join('./abc'))  // path.join('./abc') -> 'abc'\n```\n\nIn other words, each `Pathname` here should be a relative path to the directory of the gitignore rules.\n\nSuppose the dir structure is:\n\n```\n/path/to/your/repo\n    |-- a\n    |   |-- a.js\n    |\n    |-- .b\n    |\n    |-- .c\n         |-- .DS_store\n```\n\nThen the `paths` might be like this:\n\n```js\n[\n  'a/a.js'\n  '.b',\n  '.c/.DS_store'\n]\n```\n\n#### 2. filenames and dirnames\n\n`node-ignore` does NO `fs.stat` during path matching, so `node-ignore` treats\n- `foo` as a file\n- **`foo/` as a directory**\n\nFor the example below:\n\n```js\n// First, we add a ignore pattern to ignore a directory\nig.add('config/')\n\n// `ig` does NOT know if 'config', in the real world,\n//   is a normal file, directory or something.\n\nig.ignores('config')\n// `ig` treats `config` as a file, so it returns `false`\n\nig.ignores('config/')\n// returns `true`\n```\n\nSpecially for people who develop some library based on `node-ignore`, it is important to understand that.\n\nUsually, you could use [`glob`](http://npmjs.org/package/glob) with `option.mark = true` to fetch the structure of the current directory:\n\n```js\nimport glob from 'glob'\n\nglob('**', {\n  // Adds a / character to directory matches.\n  mark: true\n}, (err, files) => {\n  if (err) {\n    return console.error(err)\n  }\n\n  let filtered = ignore().add(patterns).filter(files)\n  console.log(filtered)\n})\n```\n\n\n## .filter(paths: Array&lt;Pathname&gt;): Array&lt;Pathname&gt;\n\n```ts\ntype Pathname = string\n```\n\nFilters the given array of pathnames, and returns the filtered array.\n\n- **paths** `Array.<Pathname>` The array of `pathname`s to be filtered.\n\n## .createFilter()\n\nCreates a filter function which could filter an array of paths with `Array.prototype.filter`.\n\nReturns `function(path)` the filter function.\n\n## .test(pathname: Pathname): TestResult\n\n> New in 5.0.0\n\nReturns `TestResult`\n\n```ts\n// Since 5.0.0\ninterface TestResult {\n  ignored: boolean\n  // true if the `pathname` is finally unignored by some negative pattern\n  unignored: boolean\n  // The `IgnoreRule` which ignores the pathname\n  rule?: IgnoreRule\n}\n\n// Since 7.0.0\ninterface IgnoreRule {\n  // The original pattern\n  pattern: string\n  // Whether the pattern is a negative pattern\n  negative: boolean\n  // Which is used for other packages to build things upon `node-ignore`\n  mark?: string\n}\n```\n\n- `{ignored: true, unignored: false}`: the `pathname` is ignored\n- `{ignored: false, unignored: true}`: the `pathname` is unignored\n- `{ignored: false, unignored: false}`: the `pathname` is never matched by any ignore rules.\n\n## .checkIgnore(target: string): TestResult\n\n> new in 7.0.0\n\nDebugs gitignore / exclude files, which is equivalent to `git check-ignore -v`. Usually this method is used for other packages to implement the function of `git check-ignore -v` upon `node-ignore`\n\n- **target** `string` the target to test.\n\nReturns `TestResult`\n\n```js\nig.add({\n  pattern: 'foo/*',\n  mark: '60'\n})\n\nconst {\n  ignored,\n  rule\n} = checkIgnore('foo/')\n\nif (ignored) {\n  console.log(`.gitignore:${result}:${rule.mark}:${rule.pattern} foo/`)\n}\n\n// .gitignore:60:foo/* foo/\n```\n\nPlease pay attention that this method does not have a strong built-in cache mechanism.\n\nThe purpose of introducing this method is to make it possible to implement the `git check-ignore` command in JavaScript based on `node-ignore`.\n\nSo do not use this method in those situations where performance is extremely important.\n\n## static `isPathValid(pathname): boolean` since 5.0.0\n\nCheck whether the `pathname` is an valid `path.relative()`d path according to the [convention](#1-pathname-should-be-a-pathrelatived-pathname).\n\nThis method is **NOT** used to check if an ignore pattern is valid.\n\n```js\nimport {isPathValid} from 'ignore'\n\nisPathValid('./foo')  // false\n```\n\n## <strike>.addIgnoreFile(path)</strike>\n\nREMOVED in `3.x` for now.\n\nTo upgrade `ignore@2.x` up to `3.x`, use\n\n```js\nimport fs from 'fs'\n\nif (fs.existsSync(filename)) {\n  ignore().add(fs.readFileSync(filename).toString())\n}\n```\n\ninstead.\n\n## ignore(options)\n\n### `options.ignorecase` since 4.0.0\n\nSimilar as the `core.ignorecase` option of [git-config](https://git-scm.com/docs/git-config), `node-ignore` will be case insensitive if `options.ignorecase` is set to `true` (the default value), otherwise case sensitive.\n\n```js\nconst ig = ignore({\n  ignorecase: false\n})\n\nig.add('*.png')\n\nig.ignores('*.PNG')  // false\n```\n\n### `options.ignoreCase?: boolean` since 5.2.0\n\nWhich is alternative to `options.ignoreCase`\n\n### `options.allowRelativePaths?: boolean` since 5.2.0\n\nThis option brings backward compatibility with projects which based on `ignore@4.x`. If `options.allowRelativePaths` is `true`, `ignore` will not check whether the given path to be tested is [`path.relative()`d](#pathname-conventions).\n\nHowever, passing a relative path, such as `'./foo'` or `'../foo'`, to test if it is ignored or not is not a good practise, which might lead to unexpected behavior\n\n```js\nignore({\n  allowRelativePaths: true\n}).ignores('../foo/bar.js') // And it will not throw\n```\n\n****\n\n# Upgrade Guide\n\n## Upgrade 4.x -> 5.x\n\nSince `5.0.0`, if an invalid `Pathname` passed into `ig.ignores()`, an error will be thrown, unless `options.allowRelative = true` is passed to the `Ignore` factory.\n\nWhile `ignore < 5.0.0` did not make sure what the return value was, as well as\n\n```ts\n.ignores(pathname: Pathname): boolean\n\n.filter(pathnames: Array<Pathname>): Array<Pathname>\n\n.createFilter(): (pathname: Pathname) => boolean\n\n.test(pathname: Pathname): {ignored: boolean, unignored: boolean}\n```\n\nSee the convention [here](#1-pathname-should-be-a-pathrelatived-pathname) for details.\n\nIf there are invalid pathnames, the conversion and filtration should be done by users.\n\n```js\nimport {isPathValid} from 'ignore' // introduced in 5.0.0\n\nconst paths = [\n  // invalid\n  //////////////////\n  '',\n  false,\n  '../foo',\n  '.',\n  //////////////////\n\n  // valid\n  'foo'\n]\n.filter(isPathValid)\n\nig.filter(paths)\n```\n\n## Upgrade 3.x -> 4.x\n\nSince `4.0.0`, `ignore` will no longer support node < 6, to use `ignore` in node < 6:\n\n```js\nvar ignore = require('ignore/legacy')\n```\n\n## Upgrade 2.x -> 3.x\n\n- All `options` of 2.x are unnecessary and removed, so just remove them.\n- `ignore()` instance is no longer an [`EventEmitter`](nodejs.org/api/events.html), and all events are unnecessary and removed.\n- `.addIgnoreFile()` is removed, see the [.addIgnoreFile](#addignorefilepath) section for details.\n\n****\n\n# Collaborators\n\n- [@whitecolor](https://github.com/whitecolor) *Alex*\n- [@SamyPesse](https://github.com/SamyPesse) *Samy Pessé*\n- [@azproduction](https://github.com/azproduction) *Mikhail Davydov*\n- [@TrySound](https://github.com/TrySound) *Bogdan Chadkin*\n- [@JanMattner](https://github.com/JanMattner) *Jan Mattner*\n- [@ntwb](https://github.com/ntwb) *Stephen Edgar*\n- [@kasperisager](https://github.com/kasperisager) *Kasper Isager*\n- [@sandersn](https://github.com/sandersn) *Nathan Shively-Sanders*\n","publish_time":1736826761363,"maintainers":[{"name":"kael","email":"i@kael.me"}],"_cnpm_publish_time":1736826761363,"dist-tags":{"latest":"7.0.17"}}