JSPM

  • Created
  • Published
  • Downloads 11
  • Score
    100M100P100Q65716F
  • License ISC

replace spaces with hyphens, lowercase all characters

Package Exports

  • spacesjs

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (spacesjs) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

##SpacesJS

This is a little Node.js program for renaming files in the current working directory. It replaces spaces with hyphens and converts all uppercase characters to lowercase ones.

Technically, the regular expression selects all whitespace (spaces, tabs, linefeeds, and carriage returns) and hyphens in any order. These groups of characters will be replaced with a SINGLE hyphen, and then JavaScript converts all uppercase characters to lowercase ones. This RegEx pattern accounts for the use-case in which a hyphen precedes or follows a space, for example feminism -lol.png. A previous iteration of this program did not account for this scenario, so it could potentially produce filenames such as feminism--lol.png which is not horrible, but it is certainly more cumbersome than a file that doesn't contain consecutive hyphens.

###Instructions

Install node. After this, install SpacesJS:

npm install -g spacesjs

Then, simply run the command spacesjs in the target directory.

###Other Features:

With the help of yargs, we can pass SpacesJS a flag if we need to remove additional characters (any arbitrary string) from our set of filenames. After the spacesjs command, include the --remove flag and set it equal to the string you wish to remove.

spacesjs --remove="th-"

note: It appears that the above quotation marks are optional, but it might be a good idea to include them.

###Future Additions:

  • error handling and unique messages (no files renamed, # of files renamed, etc.)
  • the ability to anticipate duplicate filenames
  • the elimination of additional (potentially detrimental) special characters
  • the elimination of hyphens just before the extension (image-.png)
  • prevent file extensions from being modified
  • improve program architecture to reduce redundancy and improve readability

Thanks to Tim Spinks for making valuable RegEx suggestions.