Last active
October 31, 2018 15:22
-
-
Save andreidmt/34c9f64f477fbce220a26de03f0369f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const { sep } = require("path") | |
| const { trim, split, push, join, dropLast } = require("@codemachiner/m") | |
| const removeTrailingSlash = source => | |
| source[source.length - 1] === sep ? source.slice(0, -1) : source | |
| /** | |
| * Rename a file. Removes trailing slashes. | |
| * | |
| * @param {string} newName New file name | |
| * @param {string} currentPath Current absolute file path | |
| * | |
| * @return {string} | |
| */ | |
| const renameFile = newName => currentPath => | |
| currentPath | |
| |> removeTrailingSlash | |
| |> split(sep) | |
| |> dropLast | |
| |> push(trim(sep)(newName)) | |
| |> join(sep) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment