0.1.0 • Published 11 years ago
repattern v0.1.0
README
repattern
A library for centralizing and organizing string replacement functions.
Built-ins:
- convert camelCasing to underscorecasing - cam$
- convert underscorecasing 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.
Examples
execute a pipeline of transformations by passing an array of names.
// granted, you could get this effect with `repattern('pascal', 'favoriteColor')` but you get the idea.
repattern(["cam$_", "title", "rm_"], "favoriteColor") // FavoriteColormake a named function and save it for later.
var titleCase = repattern.make('cam$_');
titleCase('favoriteColor'); // 'favorite_color'make also works with pipelines.
var clean = repattern.make(['strip', 'rm_']);
clean("consistently in_consistent"); // consistentlyinconsistentFYI - 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'}the library of functions is designed to be extended according to your own needs and expanded over time.
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();});install
npm install repatternuse
var repattern = require('repattern');