Skip to content

Instantly share code, notes, and snippets.

@finalclass
Last active July 31, 2024 23:16
Show Gist options
  • Save finalclass/5697373 to your computer and use it in GitHub Desktop.
Save finalclass/5697373 to your computer and use it in GitHub Desktop.

Revisions

  1. finalclass revised this gist Jun 3, 2013. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions rename-camel-to-dash.js
    Original file line number Diff line number Diff line change
    @@ -11,15 +11,15 @@
    * @author Szymon Wygnański <[email protected]>
    */

    var ffs = require('../../node_modules/final-fs'),
    var fs = require('fs'),
    path = require('path');

    function camelToDash(text) {
    return text.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
    }

    function renameDir(dir) {
    var files = ffs.readdirSync(dir),
    var files = fs.readdirSync(dir),
    f,
    fileName,
    path,
    @@ -29,9 +29,9 @@ function renameDir(dir) {
    for (f = 0; f < files.length; f += 1) {
    fileName = files[f];
    path = dir + '/' + fileName;
    file = ffs.statSync(path);
    file = fs.statSync(path);
    newPath = dir + '/' + camelToDash(fileName);
    ffs.renameSync(path, newPath);
    fs.renameSync(path, newPath);
    if (file.isDirectory()) {
    renameDir(newPath);
    }
  2. finalclass created this gist Jun 3, 2013.
    41 changes: 41 additions & 0 deletions rename-camel-to-dash.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    /*jshint node:true*/
    'use strict';

    /**
    * This scripts recursively renames every file and directory in the script path
    * from camelCase and UpperCamelCase to dash-case
    *
    * Do a backup before executing this script
    *
    * @lecense MIT
    * @author Szymon Wygnański <[email protected]>
    */

    var ffs = require('../../node_modules/final-fs'),
    path = require('path');

    function camelToDash(text) {
    return text.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
    }

    function renameDir(dir) {
    var files = ffs.readdirSync(dir),
    f,
    fileName,
    path,
    newPath,
    file;

    for (f = 0; f < files.length; f += 1) {
    fileName = files[f];
    path = dir + '/' + fileName;
    file = ffs.statSync(path);
    newPath = dir + '/' + camelToDash(fileName);
    ffs.renameSync(path, newPath);
    if (file.isDirectory()) {
    renameDir(newPath);
    }
    }
    }

    renameDir(__dirname);