0.0.2 • Published 6 years ago

replace-in-js v0.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
6 years ago

replace-in-js

Source Map aware replace for JS files. Dedicated for quick adjustments of values inside bundles or compile-time function execution (especially translation inlining).

Works in O(n) (where n is source file size).

API

const replace = require('replace-in-js');

replace(/foo/g, 'bar', options);

First two arguments mimic String.prototype.replace behavior.

options allow you to specify in and out file (work in progress, see example for currently working version).

Use-cases

The main motivation is inlining translations in the bundles, so replacing const copy = t('button_cta'); with const copy = 'Click me!'.

Using AST based tools is super slow on big files, and to out knowledge there is no source-map aware replace implementation.