{"id":18048538,"url":"https://github.com/bent10/glob-reader","last_synced_at":"2025-04-10T09:51:56.686Z","repository":{"id":37984722,"uuid":"490230189","full_name":"bent10/glob-reader","owner":"bent10","description":"Iterative file and text processing","archived":false,"fork":false,"pushed_at":"2023-12-19T08:15:33.000Z","size":912,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2023-12-20T13:30:51.963Z","etag":null,"topics":["async","expand","files","filesystem","fs","generator","glob","globs","match","multi","paths","pattern","patterns","promise","traverse","util","utility","wildcards"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/glob-reader","language":"TypeScript","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/bent10.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2022-05-09T10:09:48.000Z","updated_at":"2024-01-08T02:29:35.571Z","dependencies_parsed_at":"2024-01-08T02:29:17.106Z","dependency_job_id":"c3ff489b-0d07-4e76-a86d-50a07ab148bd","html_url":"https://github.com/bent10/glob-reader","commit_stats":{"total_commits":121,"total_committers":5,"mean_commits":24.2,"dds":0.4380165289256198,"last_synced_commit":"b57dfd592f3e352bf45a5c683c21d7edd9653763"},"previous_names":[],"tags_count":21,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bent10%2Fglob-reader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bent10%2Fglob-reader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bent10%2Fglob-reader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bent10%2Fglob-reader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bent10","download_url":"https://codeload.github.com/bent10/glob-reader/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248197986,"owners_count":21063623,"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":["async","expand","files","filesystem","fs","generator","glob","globs","match","multi","paths","pattern","patterns","promise","traverse","util","utility","wildcards"],"created_at":"2024-10-30T20:13:18.229Z","updated_at":"2025-04-10T09:51:56.659Z","avatar_url":"https://github.com/bent10.png","language":"TypeScript","readme":"# glob-reader\n\nIterative file and text processing.\n\n## Install\n\n```bash\nnpm i glob-reader\n```\n\n## Usage\n\nThis package is pure ESM, please read the\n[esm-package](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).\n\n```js\nimport { readGlobSync } from 'glob-reader'\n\nconst files = readGlobSync('./src/**/*.md')\nfor (const file of files) {\n  // processing file here (i.e. transforms markdown to html)\n  console.log(file.toString())\n  // rename file\n  file.rename({ extname: '.html', dirname: './dist' })\n  // writes .html file to ./dist directory\n  file.writeSync()\n}\n```\n\nSee the [File](#file) section for more information.\n\n## API\n\n### readGlob\n\n▸ **readGlob**(`patterns`, `options?`): `AsyncGenerator`\u003c[`File`](#file)\u003e\n\nAsynchronously expands glob patterns for iterative file and text processing.\n\n```js\nimport { readGlob } from 'glob-reader'\nimport { transform } from '@swc/core'\n\nconst files = readGlob('./src/**/*.{ts,tsx}', 'utf8')\nfor await (const file of files) {\n  // transform ts/tsx to js using `swc`\n  const { code } = await transform(file.value)\n\n  file.value = code\n  file.rename({ extname: '.js', dirname: './dist' })\n\n  // writes .js file to ./dist directory\n  await file.write()\n}\n```\n\n#### Parameters\n\n| Name       | Type                                                 |\n| :--------- | :--------------------------------------------------- |\n| `patterns` | `string` \\| readonly `string`[]                      |\n| `options?` | `BufferEncoding` \\| [`Options`](#options-properties) |\n\n#### Returns\n\n`AsyncGenerator`\u003c[`File`](#file)\u003e\n\n### readGlobSync\n\n▸ **readGlobSync**(`patterns`, `options?`): `Generator`\u003c[`File`](#file)\u003e\n\nExpands glob patterns for iterative file and text processing.\n\n```js\nimport { readGlob } from 'glob-reader'\nimport sass from 'sass'\n\nconst files = readGlobSync('./src/**/*.scss')\nfor (const file of files) {\n  // compile scss to css\n  const { css, sourceMap } = sass.compileString(file.toString(), {\n    sourceMap: true,\n    style: 'expanded'\n  })\n\n  // NOTE: We doesn't automatically add a `sourceMappingURL` comment to the `file.value`.\n  // It's up to setters to do that, since setters have full knowledge of where the `file.value`\n  // and the `file.map` will exist in relation to one another and how they'll be served.\n  file.value = `${css}\\n//# sourceMappingURL=${file.path}.map\\n`\n  file.map = sourceMap\n  file.rename({ extname: '.css', dirname: './dist' })\n\n  // writes .css and .css.map file to ./dist directory\n  file.writeSync()\n}\n```\n\n#### Parameters\n\n| Name       | Type                                                 |\n| :--------- | :--------------------------------------------------- |\n| `patterns` | `string` \\| readonly `string`[]                      |\n| `options?` | `BufferEncoding` \\| [`Options`](#options-properties) |\n\n#### Returns\n\n`Generator`\u003c[`File`](#file)\u003e\n\n### `Options`: Properties\n\n#### cwd\n\n• `Optional` **cwd**: `string`\n\nBase of path.\n\n**`default`** process.cwd()\n\n#### concurrency\n\n• `Optional` **concurrency**: `number`\n\nSpecifies the maximum number of concurrent requests from a reader to read directories.\n\n\u003e The higher the number, the higher the performance and load on the file system.\n\u003e If you want to read in quiet mode, set the value to a comfortable number or 1.\n\n**`default`** os.cpu().length\n\n#### caseSensitiveMatch\n\n• `Optional` **caseSensitiveMatch**: `boolean`\n\nEnables a [case-sensitive](https://en.wikipedia.org/wiki/Case_sensitivity) mode for matching files.\n\n**`default`** true\n\n#### ignore\n\n• `Optional` **ignore**: `string[]`\n\nAn array of glob patterns to exclude matches.\n\n**`default`** []\n\n#### encoding\n\n• `Optional` **encoding**: `BufferEncoding`\n\nThe buffer encoding to use when reading files.\n\n**`default`** Buffer\n\n#### stripMatter\n\n• `Optional` **stripMatter**: `boolean`\n\nIf `true`, it will removes the YAML front matter from the `file.value`.\n\n**`default`** false\n\n#### fsStats\n\n• `Optional` **fsStats**: `boolean`\n\nIf `true`, the file will provides information about the [`fs.Stats`](https://nodejs.org/api/fs.html#class-fsstats).\n\n**`default`** false\n\n#### dry\n\n• `Optional` **dry**: `boolean`\n\nIf `true`, it will not read the file contents and stat, also it will prevent write and delete method.\n\n**`default`** false\n\n### `File`\n\nVirtual file object.\n\n```js\nconst analyze = readGlob('./src/foo.md', { dry: true })\n\nfor await (const file of analyze) {\n  // raw value\n  file.value // =\u003e Buffer|string|null\n  // encoded value\n  file.toString() // =\u003e empty string due to `dry: true` option.\n  // the byte length of file\n  file.bytes // =\u003e 0 due to `dry: true` option.\n  // human readable byte length of file\n  file.size // =\u003e '0B'\n\n  // base of path\n  file.cwd // =\u003e process.cwd() value\n  // path of file, can be set using file `path` or file `URL`\n  file.path // =\u003e './src/foo.md'\n  // current name (including extension) of file\n  file.basename // =\u003e 'foo.md'\n  // name (without extension) of file\n  file.stem // =\u003e 'foo'\n  // extension (with dot) of file\n  file.extname // =\u003e '.md'\n  // path to parent directory of file\n  file.dirname // =\u003e './src'\n\n  // renames and mutates the file internally.\n  file.rename({ extname: '.html', dirname: './dist' })\n  // list of file-paths the file moved between\n  file.history // =\u003e ['./src/foo.md', './dist/foo.html']\n\n  // place to store custom information.\n  file.data // =\u003e { matter: {}, stat: {} }\n  file.data.stat // =\u003e empty data stat due to `dry: true` option.\n  // add custom data to file.\n  file.data.foo = 'bar' // =\u003e { matter: {}, stat: {}, foo: 'bar' }\n\n  // diagnostics storage\n  file.messages // =\u003e []\n  // associates an informational message with the file\n  file.info('some information')\n  // associates a message with the file\n  file.message('`gloob` is misspelt; did you mean `glob`?', {\n    line: 2,\n    column: 4\n  })\n\n  // writes to ./dist/foo.html\n  await file.write()\n  // removes ./dist/foo.html\n  await file.remove()\n  // writes to ./dist/foo.html synchronously\n  file.writeSync()\n  // removes ./dist/foo.html synchronously\n  file.removeSync()\n\n  // prints diagnostics to console\n  console.log(file.reporter())\n  // src/foo.md\n  //   1:1  info     some message\n  //   2:4  warning  `gloob` is misspelt; did you mean `glob`?\n  //\n  // 2 messages (⚠ 1 warning)\n}\n```\n\nRead more information about the file below.\n\n#### `file.dry`\n\nEnable/disable `dry` run for specific file.\n\n```js\nconst analyze = readGlob('./src/*')\n\n// writes all files to ./dist directory except for foo.md\nfor await (const file of analyze) {\n  // prevent `foo` file from being written but keep processing\n  if (file.is('foo')) {\n    file.dry = true\n  }\n\n  // processing file here...\n\n  file.rename({ extname: '.html', dirname: './dist' })\n  await file.write()\n}\n```\n\n#### `file#is(check)`\n\nTests if file passes the given `check`.\n\n```js\n// file.path = './src/foo.md'\nfile.is('.md') // =\u003e true\nfile.is('*.md') // =\u003e false\nfile.is('**/*.md') // =\u003e true\nfile.is('**/*.{md,html}') // =\u003e true\nfile.is('**/*.{mdx,jsx}') // =\u003e false\n\nfile.is({ stem: 'foo' }) // =\u003e true\nfile.is({ stem: { suffix: 'oo' } }) // =\u003e true\nfile.is({ stem: 'bar' }) // =\u003e false\n```\n\n#### `file#fail(reason[, position][, origin])`\n\nAssociates a fatal message with the file, then immediately throws it. Note: fatal errors mean a file is no longer processable.\n\n```js\n// use try/catch to handle fatal errors\ntry {\n  file.fail(new ReferenceError('foo is not defined'))\n} catch {}\n\nconsole.log(file.reporter({ defaultName: 'Oh snap!' }))\n// Oh snap!\n//  1:1  error  ReferenceError: foo is not defined\n//  at foo.js:1:1\n//  at ...\n```\n\n#### `file#reporter(options?)`\n\nReturns diagnostic information about the file.\n\n\u003cdetails\u003e\n\u003csummary\u003ereporter `Options` interface\u003c/summary\u003e\n\n```ts\n{\n  /**\n   * Label to use for file without `file.path`. If no `file.path` and no\n   * `defaultName` is given, `no name` will show up in the report.\n   */\n  defaultName?: string\n\n  /**\n   * Output long form descriptions of messages, if applicable.\n   *\n   * @default false\n   */\n  verbose?: boolean\n\n  /**\n   * Do not output anything for a file which has no warnings or errors.\n   * The default behavior is to show a success message.\n   *\n   * @default false\n   */\n  quiet?: boolean\n\n  /**\n   * Only output messages with fatal error. Also sets `quiet` to `true`.\n   *\n   * @default false\n   */\n  silent?: boolean\n\n  /**\n   * Whether to use color. The default behavior is the check if color is\n   * supported.\n   */\n  color?: boolean\n}\n```\n\n\u003c/details\u003e\n\n## Benchmarks\n\n```bash\nRunning glob-reader...\nreadGlob x 2,034 ops/sec ±3.28% (75 runs sampled)\nreadGlobSync x 6,599 ops/sec ±2.48% (79 runs sampled)\nFastest: readGlobSync\n```\n\n## Contributing\n\nWe 💛\u0026nbsp; issues.\n\nWhen committing, please conform to [the semantic-release commit standards](https://www.conventionalcommits.org/). Please install `commitizen` and the adapter globally, if you have not already.\n\n```bash\nnpm i -g commitizen cz-conventional-changelog\n```\n\nNow you can use `git cz` or just `cz` instead of `git commit` when committing. You can also use `git-cz`, which is an alias for `cz`.\n\n```bash\ngit add . \u0026\u0026 git cz\n```\n\n## License\n\n![GitHub](https://img.shields.io/github/license/bent10/glob-reader)\n\nA project by [Stilearning](https://stilearning.com) \u0026copy; 2022-2023.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbent10%2Fglob-reader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbent10%2Fglob-reader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbent10%2Fglob-reader/lists"}