stringify-object-strings

0.1.0 • Public • Published

stringify-object-strings Build Status

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

Package Sidebar

Install

npm i stringify-object-strings

Weekly Downloads

178

Version

0.1.0

License

MIT

Last publish

Collaborators

  • meisterlabs