path-rebuild

0.3.0 • Public • Published

path-rebuild

Transform a file path by splitting the original path into an array of parts and defining a new path in terms of indices of the parts:

       "some/path/to/a/file.js"
                  ↓
["some", "path", "to", "a", "file", ".js"]  +  "new_root/{0}_new/{1..-3}/{-2}.json"
                                            ↓
                          "new_root/some_new/path/to/a/file.json"

Installation

npm i path-rebuild

Example

const { createTransform } = require("path-rebuild");

const transform = createTransform("{0..-2}.json");
console.log(transform("path/file.js")); // -> path/file.json

API

createTransform(pattern: string): (sourcePath: string) => string

Creates a transform function. Throws a error if the pattern is incorrect.

The transform function takes a sourcePath and returns a path transformed according to the pattern.

For the pattern syntax documentation go here.

Readme

Keywords

Package Sidebar

Install

npm i path-rebuild

Weekly Downloads

1

Version

0.3.0

License

MIT

Unpacked Size

15.4 kB

Total Files

4

Last publish

Collaborators

  • pozadi