@brickify/m-string

1.0.0 • Public • Published

Module Hook

Strings manipulation API

Statistics

Github All Releases npm

Social

GitHub forks GitHub stars GitHub watchers Gitter

Project Health

Travis branch Codecov bitHound bitHound Website

Install

$ npm install @brickify/m-string

Usage

Add string

var add = require('@brickify/m-string/add');

var content = 'var foo = [0,1,0,1,0,1,0,1];';
var before = '/* Comment before */\n';
var after = '/* Comment after */\n';

add(content, /.+/, before);
// output: /* Comment before */\nvar foo = [0,1,0,1,0,1,0,1];

add(content, /.+/, null, after);
// output: var foo = [0,1,0,1,0,1,0,1];/* Comment after */\n

add(content, /.+/, before, after);
// output: /* Comment before */\nvar foo = [0,1,0,1,0,1,0,1];/* Comment after */\n

add(content, [/.+/], before, after);
// output: /* Comment before */\nvar foo = [0,1,0,1,0,1,0,1];/* Comment after */\n

Remove string

// TODO JSDOC
remove(content: String, before: String|null, after: String|null|undefined)
var remove = require('@brickify/m-string/remove');

var content = '//removeCode\nfoo = [0,1,0,1,0,1,0,1];\n//endRemoveCode';

remove(content, /\/\/removeCode(.|\s)+\/\/endRemoveCode/);
// output: ''

remove(content, [/\/\/removeCode(.|\s)+\/\/endRemoveCode/]);
// output: ''

Replace string

// TODO JSDOC
remove(content: String, before: String|null, after: String|null|undefined)
var remove = require('@brickify/m-string/replace');

var content = 'foo = [0,1,0,1,0,1,0,1];';

replace(content, /0/g, 1);
// output: foo = [1,1,1,1,1,1,1,1];

replace(content, [/0/g], 1);
// output: foo = [1,1,1,1,1,1,1,1];

Extract string

var extract = require('@brickify/m-string/extract');

var content = 'foo = [0,1,0,1,0,1,0,1];\nbar = [1,0,1,0,1,0,1,0];';

extract(content, /bar[^;]+;/);
// output: bar = [1,0,1,0,1,0,1,0];

extract(content, [/bar[^;]+;/]);
// output: bar = [1,0,1,0,1,0,1,0];

Chaining

var extract = require('@brickify/m-string/Chain');

var content = '//removeCode\nfoo = [0,1,0,1,0,1,0,1];\nbar = [1,0,1,0,1,0,1,0];\n//endRemoveCode';
var chain = new code.Chain(content);

chain
     .replace(/0/g, 1)
     .remove(/\/\/removeCode(.|\s)+\/\/endRemoveCode/)
     .add(/.*/, '/* Comment before */\n', '/* Comment after */\n')
     .extract(/(.|\s)+/g)
     .content;
    
// output : /* Comment before */\n/* Comment after */\n

Imports

// Import all methods
var lib = require('@brickify/m-string');

// Import add method
var add = require('@brickify/m-string/add');

// Import remove method
var remove = require('@brickify/m-string/remove');

// Import extract method
var add = require('@brickify/m-string/extract');

// Import Chain Class
var Chain = require('@brickify/m-string/Chain');

TODO

  • Add JSDoc, comment and Code Signature

Package Sidebar

Install

npm i @brickify/m-string

Weekly Downloads

2

Version

1.0.0

License

MIT

Last publish

Collaborators

  • nraibaud