rescript-path-rebuild

0.3.0 • Public • Published

rescript-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 rescript-path-rebuild

In your bsconfig.json add it to bs-dependencies

{
  ...,
  "bs-dependencies": [..., "rescript-path-rebuild"],
}

Example

let transform = PathRebuild.make("{0..-2}.json")->Belt.Result.getExn
transform("path/file.js")->Js.log // -> path/file.json

API

make: string => result<string => string, string>

Turns a pattern into a transform function, which takes a source path and returns a path transformed according to the pattern.

Returns a result because parsing a pattern may produce a error.

For the pattern syntax documentation go here.

Package Sidebar

Install

npm i rescript-path-rebuild

Weekly Downloads

10

Version

0.3.0

License

MIT

Unpacked Size

9.98 kB

Total Files

6

Last publish

Collaborators

  • pozadi