How to use javascript-stringify - 10 common examples

To help you get started, we’ve selected a few javascript-stringify examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zalmoxisus / redux-devtools-test-generator / src / TestGenerator.js View on Github external
function generate({ type, newPath, newValue, newIndex }) {
    let curState;
    let path = fromPath(newPath);

    if (type === 'remove-item' || type === 'move-item') {
      if (paths.length && paths.indexOf(path) !== -1) return;
      paths.push(path);
      const v = objectPath.get(s2.state, newPath);
      curState = v.length;
      path += '.length';
    } else if (type === 'add-item') {
      generate({ type: 'move-item', newPath });
      path += `[${newIndex}]`;
      curState = stringify(newValue);
    } else {
      curState = stringify(newValue);
    }

    // console.log(`expect(store${path}).toEqual(${curState});`);
    cb({ path, curState });
  }
github reduxjs / redux-devtools / packages / redux-devtools-test-generator / src / TestGenerator.js View on Github external
function generate({ type, newPath, newValue, newIndex }) {
    let curState;
    let path = fromPath(newPath);

    if (type === 'remove-item' || type === 'move-item') {
      if (paths.length && paths.indexOf(path) !== -1) return;
      paths.push(path);
      const v = objectPath.get(s2.state, newPath);
      curState = v.length;
      path += '.length';
    } else if (type === 'add-item') {
      generate({ type: 'move-item', newPath });
      path += `[${newIndex}]`;
      curState = stringify(newValue);
    } else {
      curState = stringify(newValue);
    }

    // console.log(`expect(store${path}).toEqual(${curState});`);
    cb({ path, curState });
  }
github zalmoxisus / redux-devtools-test-generator / src / TestGenerator.js View on Github external
function generate({ type, newPath, newValue, newIndex }) {
    let curState;
    let path = fromPath(newPath);

    if (type === 'remove-item' || type === 'move-item') {
      if (paths.length && paths.indexOf(path) !== -1) return;
      paths.push(path);
      const v = objectPath.get(s2.state, newPath);
      curState = v.length;
      path += '.length';
    } else if (type === 'add-item') {
      generate({ type: 'move-item', newPath });
      path += `[${newIndex}]`;
      curState = stringify(newValue);
    } else {
      curState = stringify(newValue);
    }

    // console.log(`expect(store${path}).toEqual(${curState});`);
    cb({ path, curState });
  }
github neutrinojs / webpack-chain / test / Config.js View on Github external
// Nested rules
  config.module
    .rule('alpha')
    .rule('nested')
    .use('babel')
    .loader('babel-loader');

  // Default rules
  config.module
    .defaultRule('default')
    .rule('nested')
    .use('babel')
    .loader('babel-loader');

  const envPluginPath = require.resolve('webpack/lib/EnvironmentPlugin');
  const stringifiedEnvPluginPath = stringify(envPluginPath);

  class FooPlugin {}
  FooPlugin.__expression = `require('foo-plugin')`;

  config
    .plugin('env')
    .use(envPluginPath, [{ VAR: false }])
    .end()
    .plugin('gamma')
    .use(FooPlugin)
    .end()
    .plugin('delta')
    .use(class BarPlugin {}, ['bar'])
    .end()
    .plugin('epsilon')
    .use(class BazPlugin {}, [{ n: 1 }, [2, 3]]);
github jakoblind / webpack-autoconf / src / configurator / configurator.js View on Github external
entryExtension = 'tsx';
    } else {
      entryExtension = 'ts';
    }
  }

  let entry = `./src/index.${entryExtension}`;
  if (isHotReact) {
    entry = [
      'react-hot-loader/patch', // activate HMR for React
      `./src/index.${entryExtension}`,
    ];
  }
  const baseWebpackTsSupport = _.assignIn(baseWebpack, { entry });
  const base = configType === 'webpack' ? baseWebpackTsSupport : {};
  return jsStringify(
    _.reduce(
      configItems,
      (acc, currentValue) =>
        features[currentValue][configType](acc, configItems),
      base
    ),
    stringifyReplacer,
    2
  );
}
github styleguidist / react-styleguidist / src / client / rsg-components / Props / PropsRenderer.js View on Github external
color="light"
						underlined
						title={showSpaces(unquote(prop.defaultValue.value))}
					>
						Function
					
				);
			} else if (propName === 'shape' || propName === 'object') {
				try {
					// We eval source code to be able to format the defaultProp here. This
					// can be considered safe, as it is the source code that is evaled,
					// which is from a known source and safe by default
					// eslint-disable-next-line no-eval
					const object = eval(`(${prop.defaultValue.value})`);
					return (
						
					);
				} catch (e) {
					// eval will throw if it contains a reference to a property not in the
					// local scope. To avoid any breakage we fall back to rendering the
					// prop without any formatting
					return (
						
					);
				}
			}
		}
github universal-vue / uvue / packages / @uvue / vue-cli-plugin-ssr / generator / index.js View on Github external
if (name === 'cookie' && options.cookieSecret) {
          pluginOptions = { secret: options.cookieSecret };
        }

        if (pluginOptions) {
          serverConfig.plugins.push([pluginPath, pluginOptions]);
        } else {
          serverConfig.plugins.push(pluginPath);
        }
      }
    }

    fs.writeFileSync(
      api.resolve('server.config.js'),
      `export default ${stringify(serverConfig, null, 2)}`,
    );
  }

  // When this plugin is invoked
  api.onCreateComplete(async () => {
    await execCodeFixer(api);

    const { blue, underline, bold } = chalk;

    api.exitLog(
      `UVue installed, please read this before starting:\n${bold(
        underline(
          blue(
            'https://universal-vue.github.io/docs/guide/post-install.html#post-installation-notes',
          ),
        ),
github universal-vue / uvue / packages / @uvue / vue-cli-plugin-ssr / generator / index.js View on Github external
opts[optionName] = true;
            return opts;
          }, {});
        }

        if (pluginOptions) {
          uvueConfig.plugins.push([pluginPath, pluginOptions]);
        } else {
          uvueConfig.plugins.push(pluginPath);
        }
      }
    }

    fs.writeFileSync(
      api.resolve('uvue.config.js'),
      `export default ${stringify(uvueConfig, null, 2)}`,
    );

    // Server config
    const serverConfig = {
      plugins: [],
    };

    if (options.serverPlugins) {
      for (const name of options.serverPlugins) {
        const pluginPath = `@uvue/server/plugins/${name}`;
        let pluginOptions = null;

        if (name === 'cookie' && options.cookieSecret) {
          pluginOptions = { secret: options.cookieSecret };
        }
github amalto / platform6-ui-components / typescript / custom / PropsRenderer.tsx View on Github external
size="small"
                        color="light"
                        underlined
                        title={showSpaces(unquote(prop.defaultValue.value))}>
                        Function
                    
                } else if (propName === 'shape' || propName === 'object') {
                    try {
                        // We eval source code to be able to format the defaultProp here. This
                        // can be considered safe, as it is the source code that is evaled,
                        // which is from a known source and safe by default
                        // eslint-disable-next-line no-eval
                        const object = eval(`(${prop.defaultValue.value})`)

                        return (
                            
                        )
                    } catch (e) {
                        // eval will throw if it contains a reference to a property not in the
                        // local scope. To avoid any breakage we fall back to rendering the
                        // prop without any formatting
                        return (
                            
                        )
                    }
                }
            }
github zalmoxisus / redux-devtools-test-generator / src / TestGenerator.js View on Github external
const startIdx = i > 0 ? i : 1;

    const addAssertions = ({ path, curState }) => {
      r += space + assertion({ path, curState }) + '\n';
    };

    while (actions[i]) {
      if (!isVanilla || /^┗?\s?[a-zA-Z0-9_@.\[\]-]+?$/.test(actions[i].action.type)) {
        if (isFirst) isFirst = false;
        else r += space;
        if (!isVanilla || actions[i].action.type[0] !== '@') {
          r += dispatcher({
            action: !isVanilla ?
              this.getAction(actions[i].action) :
              this.getMethod(actions[i].action),
            prevState: i > 0 ? stringify(computedStates[i - 1].state) : undefined
          }) + '\n';
        }
        if (!isVanilla) {
          addAssertions({ path: '', curState: stringify(computedStates[i].state) });
        } else {
          compare(computedStates[i - 1], computedStates[i], addAssertions, isVanilla && {});
        }
      }
      i++;
      if (i > selectedActionId) break;
    }

    r = r.trim();
    if (wrap) {
      if (!isVanilla) r = wrap({ name, assertions: r });
      else {

javascript-stringify

Stringify is to `eval` as `JSON.stringify` is to `JSON.parse`

MIT
Latest version published 4 years ago

Package Health Score

67 / 100
Full package analysis