{"id":13658986,"url":"https://github.com/popomore/rename","last_synced_at":"2025-10-17T14:10:44.258Z","repository":{"id":15846647,"uuid":"18586759","full_name":"popomore/rename","owner":"popomore","description":"Rename files using some transformers.","archived":false,"fork":false,"pushed_at":"2016-12-27T11:15:50.000Z","size":19,"stargazers_count":17,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T18:21:16.464Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/popomore.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-04-09T05:49:59.000Z","updated_at":"2021-09-03T11:32:11.000Z","dependencies_parsed_at":"2022-09-26T20:32:01.459Z","dependency_job_id":null,"html_url":"https://github.com/popomore/rename","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/popomore%2Frename","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/popomore%2Frename/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/popomore%2Frename/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/popomore%2Frename/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/popomore","download_url":"https://codeload.github.com/popomore/rename/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248606859,"owners_count":21132428,"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":[],"created_at":"2024-08-02T05:01:04.315Z","updated_at":"2025-10-17T14:10:39.223Z","avatar_url":"https://github.com/popomore.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# rename\n\nRename files using some transformers.\n\n---\n\n[![NPM version](https://img.shields.io/npm/v/rename.svg?style=flat)](https://npmjs.org/package/rename)\n[![Build Status](https://img.shields.io/travis/popomore/rename.svg?style=flat)](https://travis-ci.org/popomore/rename)\n[![Build Status](https://img.shields.io/coveralls/popomore/rename.svg?style=flat)](https://coveralls.io/r/popomore/rename)\n[![NPM downloads](http://img.shields.io/npm/dm/rename.svg?style=flat)](https://npmjs.org/package/rename)\n\n**NOTE: Rename \u003c 0.2.0 is not the same lib, you can see [renamer](https://www.npmjs.org/package/renamer). 1.0.0 have a big change.**\n\n## Install\n\n```\n$ npm install rename -g\n```\n\n## Usage\n\nRename file using another filepath.\n\n```js\nrename('a.js', 'b.js');\n// =\u003e b.js\n```\n\nRename file using a _transform object_ that contain some property.\n\n```\n{\n  dirname: \"replace dirname\",\n  prefix: \"add prefix before basename\",\n  basename: \"replace dirname\",\n  suffix: \"add prefix after basename\",\n  extname: \"replace extname\"\n}\n```\n\nAdd `-debug` suffix\n\n```js\nrename('a.js', {suffix: '-debug'});\n// =\u003e a-debug.js\n```\n\nAlso can use a _transform function_ that could return a _transform object_.\n\n```js\nrename('a.js', function() {\n  return {suffix: '-debug'};\n});\n// =\u003e a-debug.js\n```\n\n## API\n\n### rename(filepath, transformer)\n\n#### filepath\n\nFilepath can be a string or object. Parse the filepath to _file object_ if it's a string.\n\n_File object_ should contain property dirname, basename and extname.\n\n```js\nrename({\n  basename: 'a',\n  extname: '.js'\n}, 'b.js');\n// =\u003e b.js\n```\n\n#### transformer\n\nTransformer can be a function, string or object.\n\nSimple example about _transform function_ using custom property.\n\n```js\nfunction transformer(fileObj) {\n  return {\n    suffix: fileObj.hash || '-debug'\n  };\n}\n\nrename({\n  basename: 'a',\n  extname: '.js'\n}, transformer);\n// =\u003e a-debug.js\n\nrename({\n  basename: 'a',\n  extname: '.js',\n  hash: '-123'\n}, transformer);\n// =\u003e a-123.js\n```\n\nThe value of _transform object_ can be template that parsed from _file object_.\n\n```\nrename({\n  basename: 'c',\n  extname: '.js',\n  hash: '111'\n}, {\n  suffix: '-${hash}',\n}).should.eql('c-111.js');\n```\n\n### rename.parse\n\nGenerate a _file object_ from a string or object.\n\n### rename.stringify\n\nGenerate a filepath from _file object_.\n\n## LISENCE\n\nCopyright (c) 2017 popomore. Licensed under the MIT license.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpopomore%2Frename","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpopomore%2Frename","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpopomore%2Frename/lists"}