subsy
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

Subsy

A tool that allows you to replace strings with values from JSON object.

Install

    npm install subsy --save-dev

How to use

With String.replace()

    var subsy = require('subsy');
 
    var introduction = "Hello, my name is @name.full@. You can call me @name.short@";
    var profile = {
        "name": {
            "short": "James",
            "full": "James Roland"
        }
    };
 
    //output: Hello, my name is James Roland. You can call me James
    console.log(introduction.replace(/@+[\w.]+@/g, subsy.json(profile));

With gulp-replace

var replace = require('gulp-replace');
var en = require('./locale/en.json');
 
gulp.task('localize', function() {
    gulp.src('app/**')
        .pipe(replace(/@+[\w.]+@/g, subsy.json(en), {skipBinary: true})
        .pipe(gulp.dest('bundle/en'));
})

Package Sidebar

Install

npm i subsy

Weekly Downloads

2

Version

1.0.2

License

MIT

Last publish

Collaborators

  • staticfunction