repattern

0.1.0 • Public • Published

README

repattern

A library for centralizing and organizing string replacement functions.

Built-ins:

  • 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.

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") // FavoriteColor

make 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"); // 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'}

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 repattern

use

var repattern = require('repattern');

Package Sidebar

Install

npm i repattern

Weekly Downloads

0

Version

0.1.0

License

MIT

Last publish

Collaborators

  • xianwill