How to use the javascript-stringify function in javascript-stringify

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 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 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 {
github zalmoxisus / redux-devtools-test-generator / src / TestGenerator.js View on Github external
}
      }
      i++;
      if (i > selectedActionId) break;
    }

    r = r.trim();
    if (wrap) {
      if (!isVanilla) r = wrap({ name, assertions: r });
      else {
        r = wrap({
          name: /^[a-zA-Z0-9_-]+?$/.test(name) ? name : 'Store',
          actionName: (selectedActionId === null || selectedActionId > 0) && actions[startIdx] ?
            actions[startIdx].action.type.replace(/[^a-zA-Z0-9_-]+/, '') :
            'should return the initial state',
          initialState: stringify(computedStates[startIdx - 1].state),
          assertions: r
        });
      }
    }
    return r;
  }
github reduxjs / redux-devtools / packages / redux-devtools-test-generator / src / TestGenerator.js View on Github external
getAction(action) {
    if (action.type === '@@INIT') return '{}';
    return stringify(action);
  }
github zalmoxisus / redux-devtools-test-generator / src / TestGenerator.js View on Github external
getAction(action) {
    if (action.type === '@@INIT') return '{}';
    return stringify(action);
  }

javascript-stringify

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

MIT
Latest version published 3 years ago

Package Health Score

67 / 100
Full package analysis