UNPKG

stringify-object-strings

Version:
80 lines (59 loc) 1.66 kB
# stringify-object-strings [![Build Status](https://img.shields.io/travis/MeisterLabs/stringify-object-strings.svg)](https://travis-ci.org/MeisterLabs/stringify-object-strings) > Stringify an object’s strings Useful when using [webpack’s `DefinePlugin`](https://webpack.js.org/plugins/define-plugin/) or [rollup-plugin-replace](https://github.com/rollup/rollup-plugin-replace). ## Installation ``` $ npm install stringify-object-strings ``` ## Usage ```js 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 ```js 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 ```js 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](http://semver.org). ## License MIT © [MeisterLabs GmbH](https://www.meisterlabs.com)