Centralizes common string transformations and keeps them organized by name.
npm install repatternA library for centralizing and organizing string replacement functions.
* convert camelCasing to underscore_casing - cam$_
* convert underscore_casing to camelCasing - _$cam
* convert underscore_casing or camelCasing to Title_Casing/TitleCasing - title
* convert underscore_casing or camelCasing to PascalCasing - pascal
* strip whitespace - strip
* remove underscores - rm_
Small right now. The built-in library will grow.
// granted, you could get this effect with repattern('pascal', 'favoriteColor') but you get the idea.
repattern(["cam$_", "title", "rm_"], "favoriteColor") // FavoriteColor
var titleCase = repattern.make('cam$_');
titleCase('favoriteColor'); // 'favorite_color'
var clean = repattern.make(['strip', 'rm_']);
clean("consistently in_consistent"); // consistentlyinconsistent
FYI - repattern.make is a nice complement to simple-map
var map = require('simple-map');
var repattern = require('repattern');
var columnCase = repattern.make('cam$_');
map({'firstName': 'John', 'lastName': 'Doe'}, columnCase); // {'first_name': 'John', 'last_name': 'Doe'}
repattern.use("path$pkg", /\//gi, "-");
repattern.use("words$title", /(\s+|^)([a-z])/g, "$1$2");
adding duplicate keys will throw an error with use. If you want to override a _built-in_ use override instead:
repattern.override("prop$col", /^[a-z]/, function(v) {return v.toUpperCase();});
npm install repattern
var repattern = require('repattern');