{"id":24859522,"url":"https://github.com/kolbasa/r-line","last_synced_at":"2025-03-26T16:15:16.163Z","repository":{"id":183679051,"uuid":"669125510","full_name":"kolbasa/r-line","owner":"kolbasa","description":"Simple node script for quickly modifying text files.","archived":false,"fork":false,"pushed_at":"2023-09-03T09:11:57.000Z","size":97,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-02T23:15:29.259Z","etag":null,"topics":["dryrun","line","preview","refactoring","replace","text","textfile"],"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/kolbasa.png","metadata":{"files":{"readme":"README.md","changelog":null,"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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-21T12:02:28.000Z","updated_at":"2023-07-25T11:08:48.000Z","dependencies_parsed_at":"2025-01-31T20:30:43.011Z","dependency_job_id":"44d4bb09-8b9c-4b4c-a143-89929e993e9f","html_url":"https://github.com/kolbasa/r-line","commit_stats":null,"previous_names":["kolbasa/r-line"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kolbasa%2Fr-line","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kolbasa%2Fr-line/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kolbasa%2Fr-line/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kolbasa%2Fr-line/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kolbasa","download_url":"https://codeload.github.com/kolbasa/r-line/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245689513,"owners_count":20656417,"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":["dryrun","line","preview","refactoring","replace","text","textfile"],"created_at":"2025-01-31T20:31:01.140Z","updated_at":"2025-03-26T16:15:16.146Z","avatar_url":"https://github.com/kolbasa.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## r-line\n\nThis node script is designed to allow quick and easy modification of text files.  \nFor this purpose, the script offers a simple preview mode for the changes before they are applied.  \n\nIt has no dependencies and can be integrated directly into your project even without npm.\n\n### Installation\n\n```bash\nnpm install r-line\n```\n\nAlternatively, simply use the script from `lib/r-line.js` as standalone.\n\n### Sample usage\n\n```node\nimport rl from 'r-line';\n\nrl.replaceLine('lib/r-line.js', (line) =\u003e {\n\n    if (line.includes('function preview(')) {\n        return line.replace('preview', 'foo'); // return string to change a line\n    }\n\n    if (line.includes('const stringUtils')) {\n        return false; // return \"false\" to delete a line\n    }\n\n}, {dryRun: true});\n```\n\nThis leads to the following output:\n\n```\n[INFO] Preview: 'lib/r-line.js'\n\n176   ┌  function preview(originalLines, changedLines, options) {\n    C └▷ function foo(originalLines, changedLines, options) {\n337 D ┤  const stringUtils = {\n\n```\n\nIf you remove `dryRun: true`, the changes will be applied.\n\n### Preview options\n\nYou can customise the preview with the following optional parameters:\n\n```node\nrl.replaceLine('your/file.js', (line) =\u003e {\n    //\n}, {\n    previewOptions: {\n        // Visualises whitespaces and tabs.\n        showSpaces: true / false, // default := false\n\n        // Previews the complete file content, not just the changed lines.\n        showUnchangedLines: true / false, // default := false\n\n        // Hides the original content of the changed lines.\n        hideOriginalLines: true / false, // default := false\n\n        // By default unnecessary indentation is removed.\n        // However, the behavior can be turned off.\n        keepOriginalIndentation: true / false // default := false\n    }\n});\n```\n\n### Line context\n\nThe callback function provides a `context` object as the second parameter.  \nThis contains the line number and previous or following lines.\n\n```node\nrl.replaceLine('your/file.js', (line, context) =\u003e {\n    context.lineNumber;     // number\n\n    context.next.line;      // String\n    context.next.lines;     // string[]\n\n    context.previous.line;  // String\n    context.previous.lines; // string[]\n});\n```\n\n### Listing files\n\nIf you are editing several files at once, then there is a helper function for this called `listFiles`.\n\n```node\nrl.listFiles('lib', (file) =\u003e rl.replaceLine(file, (line) =\u003e {\n    //\n}));\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkolbasa%2Fr-line","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkolbasa%2Fr-line","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkolbasa%2Fr-line/lists"}