Skip to content

Instantly share code, notes, and snippets.

@andreidmt
Last active October 31, 2018 15:22
Show Gist options
  • Select an option

  • Save andreidmt/34c9f64f477fbce220a26de03f0369f1 to your computer and use it in GitHub Desktop.

Select an option

Save andreidmt/34c9f64f477fbce220a26de03f0369f1 to your computer and use it in GitHub Desktop.
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