stringify-object-strings
Stringify an object’s strings
Useful when using webpack’s DefinePlugin
or rollup-plugin-replace.
Installation
$ npm install stringify-object-strings
Usage
const stringify = require('stringify-object-strings');
stringify({
ENVIRONMENT: 'development',
FEATURE_FLAG: true,
FIBONACCI: [0, 1, 1, 2, 3],
// Also supports nested objects.
API: {
BASE_URL: 'https://api.example.com'
}
});
// => {
// ENVIRONMENT: '"development"',
// FEATURE_FLAG: true,
// FIBONACCI: [0, 1, 1, 2, 3],
// API: {
// BASE_URL: '"https://api.example.com"'
// }
// }
With webpack’s DefinePlugin
const stringify = require('stringify-object-strings');
const definitions = {
ENVIRONMENT: 'development',
VERSION: '1.0.0',
NICE_FEATURE: true
};
new webpack.DefinePlugin(stringify(definitions));
With rollup-plugin-replace
import replace from 'rollup-plugin-replace';
import stringify from 'stringify-object-strings';
const values = {
ENVIRONMENT: 'development',
VERSION: '1.0.0',
NICE_FEATURE: true
};
export default {
plugins: [
replace({
values: stringify(values)
})
]
};
Changelog
This project follows Semantic Versioning 2.
License
MIT © MeisterLabs GmbH