{"id":13826754,"url":"https://github.com/wj42ftns/replace-in-files","last_synced_at":"2026-01-12T02:17:56.286Z","repository":{"id":38240111,"uuid":"98084985","full_name":"wj42ftns/replace-in-files","owner":"wj42ftns","description":"Replace text in one or more files or globs.","archived":false,"fork":false,"pushed_at":"2023-01-06T01:56:51.000Z","size":2976,"stargazers_count":23,"open_issues_count":16,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-21T09:43:37.286Z","etag":null,"topics":["asynchronously","file","files","filesystem","glob","promise","replace","replacement","text"],"latest_commit_sha":null,"homepage":"","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/wj42ftns.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":"2017-07-23T08:35:17.000Z","updated_at":"2025-06-25T16:02:13.000Z","dependencies_parsed_at":"2023-02-05T02:15:36.227Z","dependency_job_id":null,"html_url":"https://github.com/wj42ftns/replace-in-files","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/wj42ftns/replace-in-files","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wj42ftns%2Freplace-in-files","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wj42ftns%2Freplace-in-files/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wj42ftns%2Freplace-in-files/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wj42ftns%2Freplace-in-files/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wj42ftns","download_url":"https://codeload.github.com/wj42ftns/replace-in-files/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wj42ftns%2Freplace-in-files/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28331902,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T00:36:25.062Z","status":"online","status_checked_at":"2026-01-12T02:00:08.677Z","response_time":98,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["asynchronously","file","files","filesystem","glob","promise","replace","replacement","text"],"created_at":"2024-08-04T09:01:43.589Z","updated_at":"2026-01-12T02:17:56.268Z","avatar_url":"https://github.com/wj42ftns.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# replace-in-files\nReplace text in one or more files or globs. Works asynchronously with promises.\n\n[![npm version](https://img.shields.io/npm/v/replace-in-files.svg)](https://www.npmjs.com/package/replace-in-files)\n[![dependencies Status](https://david-dm.org/wj42ftns/replace-in-files/status.svg)](https://david-dm.org/wj42ftns/replace-in-files)\n[![Build Status](https://travis-ci.org/wj42ftns/replace-in-files.svg?branch=master)](https://travis-ci.org/wj42ftns/replace-in-files)\n[![Coverage Status](https://coveralls.io/repos/github/wj42ftns/replace-in-files/badge.svg)](https://coveralls.io/github/wj42ftns/replace-in-files)\n\n## Installation\n```shell\n# Using npm\nnpm install replace-in-files\n\n# Using yarn\nyarn add replace-in-files\n```\n\n## Usage\n\n### Specify options\n\n```js\nconst replaceInFiles = require('replace-in-files');\n\nconst options = {\n  // See more: https://www.npmjs.com/package/globby\n  // Single file or glob\n  files: 'path/to/file',\n  // Multiple files or globs\n  files: [\n    'path/to/file',\n    'path/to/other/file',\n    'path/to/files/*.html',\n    'another/**/*.path',\n  ],\n\n\n  // See more: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace\n  // Replacement\n  from: /foo/g,  // string or regex\n  to: 'bar', // string or fn  (fn: carrying last argument - path to replaced file)\n\n\n  // See more: https://www.npmjs.com/package/glob\n  optionsForFiles: { // default\n    \"ignore\": [\n      \"**/node_modules/**\"\n    ]\n  }\n\n\n  // format: `${fileName}-${year}-${month}-${day}_${hour}:${minute}:${second}.{fileExtension}`\n  //            fileName-2017-11-01_21:29:55.js\n  // date of createFile old file or last modificate (if not find create date)\n  saveOldFile: false // default\n\n\n  //Character encoding for reading/writing files\n  encoding: 'utf8',  // default\n\n\n  shouldSkipBinaryFiles: true, // default\n  onlyFindPathsWithoutReplace: false // default\n  returnPaths: true // default\n  returnCountOfMatchesByPaths: true // default\n};\n```\n\n### Replacing multiple occurrences\nPlease note that the value specified in the `from` parameter is passed straight to the native [String replace method](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace). As such, if you pass a string as the `from` parameter, it will _only replace the first occurrence_.\n\nTo replace multiple occurrences at once, you must use a regular expression for the `from` parameter with the global flag enabled, e.g. `/foo/g`.\n\n### Asynchronous replacement with promises\n\n```js\nconst replaceInFiles = require('replace-in-files');\n\n// ...\n\nreplaceInFiles(options)\n  .then(({ changedFiles, countOfMatchesByPaths }) =\u003e {\n    console.log('Modified files:', changedFiles);\n    console.log('Count of matches by paths:', countOfMatchesByPaths);\n    console.log('was called with:', options);\n  })\n  .catch(error =\u003e {\n    console.error('Error occurred:', error);\n  });\n```\n\n### Asynchronous replacement with co yield\n\n```js\nconst replaceInFiles = require('replace-in-files');\nconst co = require('co');\n\n// ...\n\nco(function* () {\n  const {\n    changedFiles,\n    countOfMatchesByPaths,\n    replaceInFilesOptions\n  } = yield replaceInFiles(options);\n  console.log('Modified files:', changedFiles);\n  console.log('Count of matches by paths:', countOfMatchesByPaths);\n  console.log('was called with:', replaceInFilesOptions);\n}).catch((error) =\u003e {\n  console.log('Error occurred:', error);\n});\n```\n\n### Asynchronous replacement with async await (node 8+)\n\n```js\nconst replaceInFiles = require('replace-in-files');\n\n// ...\n\nasync function main() {\n  try {\n    const {\n      changedFiles,\n      countOfMatchesByPaths,\n      replaceInFilesOptions\n    } = await replaceInFiles(options);\n    console.log('Modified files:', changedFiles);\n    console.log('Count of matches by paths:', countOfMatchesByPaths);\n    console.log('was called with:', replaceInFilesOptions);\n  } catch (error) {\n    console.log('Error occurred:', error);\n  }\n}\n\nmain();\n```\n\n## Sequentially replacement\n\nuse .pipe  - will be replaced with only files found at first replacement\n\n.pipe supported only: { from, to } (the other options will be received from options in the first replacement)\n\n```js\nconst replaceInFiles = require('replace-in-files');\n\n// ...\n\nasync function main() {\n  try {\n    const {\n      changedFiles,\n      countOfMatchesByPaths,\n      replaceInFilesOptions\n    } = await replaceInFiles(options)\n      .pipe({ from: 'foo', to: 'bar' })\n      .pipe({ from: 'first', to: 'second' })\n      .pipe({ from: /const/g, to: () =\u003e 'var' });\n    console.log('Modified files:', changedFiles);\n    console.log('Count of matches by paths:', countOfMatchesByPaths);\n    console.log('was called with:', replaceInFilesOptions);\n  } catch (error) {\n    console.log('Error occurred:', error);\n  }\n}\n\nmain();\n```\n\n\n### Return value\n\nThe return value of the library is an object with: countOfMatchesByPaths and paths\n\nFor example:\n\n```js\nconst replaceInFiles = require('replace-in-files');\n\nconst data = replaceInFiles({\n  files: 'path/to/files/*.html',\n  from: 'a',\n  to: 'b',\n});\n\n// data could like:\n{\n  countOfMatchesByPaths: [\n    {\n      'path/to/files/file1.html': 5,\n      'path/to/files/file3.html': 1,\n      'path/to/files/file5.html': 3\n    }\n  ],\n  paths: [\n    'path/to/files/file1.html',\n    'path/to/files/file3.html',\n    'path/to/files/file5.html',\n  ],\n  replaceInFilesOptions: [\n    {\n      files: 'path/to/files/*.html',\n      from: 'a',\n      to: 'b',\n    }\n  ]\n}\n\n// if empty:\n{\n  countOfMatchesByPaths: [\n    {}\n  ],\n  paths: []\n}\n\n// if used 2 .pipe\n{\n  countOfMatchesByPaths: [\n    {\n      'path/to/files/file1.html': 5,\n      'path/to/files/file3.html': 1,\n      'path/to/files/file5.html': 3\n    },\n    {\n      'path/to/files/file5.html': 4\n    },\n    {\n      'path/to/files/file1.html': 2,\n      'path/to/files/file5.html': 4\n    }\n  ],\n  paths: [\n    'path/to/files/file1.html',\n    'path/to/files/file3.html',\n    'path/to/files/file5.html',\n  ],\n  replaceInFilesOptions: [\n    {\n      files: 'path/to/files/*.html',\n      from: 'a',\n      to: 'b',\n    },\n    {\n      from: 'c',\n      to: 'd',\n    },\n    {\n      from: 'e',\n      to: 'f',\n    }\n  ]\n}\n\n```\n\n## Version information\n* Replace in files requires Node 12 or higher. (v.3.0.0 +) potentially still supported earlier node, but in pipeline eslint required node \u003e=12\n* Replace in files requires Node 8 or higher. (v.2.0.3) - potentially still supported node 6, but in pipeline eslint required node 8\n* Replace in files requires Node 6 or higher. (v.1.1.4)\n\n## License\n(MIT License)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwj42ftns%2Freplace-in-files","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwj42ftns%2Freplace-in-files","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwj42ftns%2Freplace-in-files/lists"}