str-js

0.0.4 • Public • Published

str-js

npm install str-js

A simple string store with nesting, singular and plural selection, and string formating.

Call str.print('with.delineated.keys'); and str will return the formatted string. If you dont want to use . a different delimiter can be set with str.delimiter = '_';.

Strings can be added to the str-js at anytime by calling str.extend({ the_new: 'strings' });

Basic Example

str.extend({
    foo: {
        bar: 'hello'
    },
    baz: {
        plur: 'worlds',
        sing: 'world'
    }
});
 
str.print('foo.bar'); // => 'hello'
str.print('baz'); // => 'world'
str(3).print('baz'); // => 'worlds'
str.print('does_not_exist'); // => ''

Example with Formatting

str.extend({
    via_arguments: 'hello {0}',
    via_array: 'hello {0}',
    via_object: 'hello {place}'
});
 
// all print 'hello world'
str.print('via_arguments', 'world');
str.print('via_array', 'world');
str.print('via_object', { place: 'world' });
 
str.globals = { place: 'other world' };
str.print('via_object'); // => 'hello other world'

Readme

Keywords

none

Package Sidebar

Install

npm i str-js

Weekly Downloads

0

Version

0.0.4

License

MIT

Last publish

Collaborators

  • josephclay