How to use json-stringify-pretty-compact - 10 common examples

To help you get started, we’ve selected a few json-stringify-pretty-compact 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 mapbox / mapbox-gl-js / test / integration / lib / expression.js View on Github external
function stringify(v) {
    let s = compactStringify(v);
    // http://timelessrepo.com/json-isnt-a-javascript-subset
    if (s.indexOf('\u2028') >= 0) {
        s = s.replace(/\u2028/g, '\\u2028');
    }
    if (s.indexOf('\u2029') >= 0) {
        s = s.replace(/\u2029/g, '\\u2029');
    }
    return s;
}
github elastic / kibana / src / legacy / core_plugins / vis_type_vega / public / data_model / utils.js View on Github external
static formatWarningToStr(value) {
    if (arguments.length >= 2) {
      try {
        if (typeof arguments[1] === 'string') {
          value += `\n${arguments[1]}`;
        } else {
          value += '\n' + compactStringify(arguments[1], { maxLength: 70 });
        }
      } catch (err) {
        // ignore
      }
    }
    return value;
  }
github grommet / jsx-to-string / src / index.js View on Github external
if (isImmutable(item)) {
    result = serializeItem(item.toJS(), options, delimit);
  } else if (typeof item === 'string') {
    result = delimit ? `'${item}'` : item;
  } else if (typeof item === 'number' || typeof item === 'boolean') {
    result = `${item}`;
  } else if (Array.isArray(item)) {
    var indentation = new Array(options.spacing + 1).join(' ');
    const delimiter = delimit ? ', ' : `\n${indentation}`;
    const items = item.map(i => serializeItem(i, options)).join(delimiter);
    result = delimit ? `[${items}]` : `${items}` ;
  } else if (isValidElement(item)) {
    result = jsxToString(item, options);
  } else if (typeof item === 'object') {
    result = stringify(stringifyObject(item, options));
    // remove string quotes from embeded JSX values
    result = result.replace(_JSX_REGEXP, function (match) {
      return match.slice(1, match.length - 1);
    });
  } else if (typeof item === 'function') {
    result = options.useFunctionCode ?
      options.functionNameOnly ?
        item.name.toString() : item.toString() : `...`;
  }
  return result;
}
github FrediBach / Blowson / src / blowson.js View on Github external
// Convert this type array to an object with this key
    for (type in data) {
        for (entry in data[type]) {
            for (field in data[type][entry]) {
                if (objKeys.indexOf(`${type}.${field}`) > -1) {
                    if (Array.isArray(data[type])) {
                        data[type] = arrayToObject(data[type], field);
                    }
                }
            }
        }
    }

    if (dataIsJSON) {
        return stringify(data);
    }

    return data;
}
github mapbox / mapbox-gl-js / test / integration / lib / expression.js View on Github external
if (compileOk && !evalOk) {
                const differences = `Original\n${diffOutputs(result.outputs)}\n`;
                diffOutput.text += differences;
                diffOutput.html += differences;
            }
            if (recompileOk && !roundTripOk) {
                const differences = `\nRoundtripped through serialize()\n${diffOutputs(result.roundTripOutputs)}\n`;
                diffOutput.text += differences;
                diffOutput.html += differences;
            }

            params.difference = diffOutput.html;
            if (diffOutput.text) { console.log(diffOutput.text); }

            params.expression = compactStringify(fixture.expression);
            params.serialized = compactStringify(result.serialized);

            done();
        } catch (e) {
            done(e);
        }
    });
}
github loyd / flow2schema / src / cli.js View on Github external
function run(file: string, args: Args): string {
    const {types, schema} = collect(file);

    switch (args.type) {
        case 'intermediate':
            return yaml.dump(types, null, null, {
                indent: args.indent,
                width: args.maxWidth,
            }).trimRight();
        case 'json-schema':
        default:
            return stringifyJson(schema, {
                indent: args.indent,
                maxLength: args.maxWidth,
            });
    }
}
github TRON-US / tronweb / examples / node / pages / index.js View on Github external
<div>
                            <input value="getAccountResources" type="button">this.getAccountResources()}/&gt;
                        </div>
                        <div>
                            <input value="getChainParameters" type="button">this.getChainParameters()}/&gt;
                        </div>
                        <div>
                            <input value="listSuperRepresentatives" type="button">this.listSuperRepresentatives()}/&gt;
                        </div>


                    
                

                <div style="{{position:'fixed',left:0,top:0}}">
                    <textarea value="{stringify(data)}" rows="10" cols="100">{}}&gt;</textarea>
                </div>
                <style>{`

                    label{
                        display:inline-block;
                        width:150px;
                    }

                `}
                </style>

            

        )
    }
}
github vega / vega-lite / site / static / index.ts View on Github external
.on('click', function() {
        post(window, editorURL, {
          mode: 'vega-lite',
          spec: compactStringify(spec),
          config: vgSpec.config,
          renderer: 'svg'
        });
        event.preventDefault();
      });
  }
github grommet / grommet-docs / src / docs / components / box / BoxingGymDoc.js View on Github external
_renderRaw () {
    const { boxes, rawBoxes } = this.state;
    return (
      <div>
        <header size="large">
          Raw
          <button>}
            onClick={() =&gt; {
              this.setState({ raw: false, rawBoxes: undefined });
            }} /&gt;
        </button></header>
        
          
            <textarea value="{rawBoxes" rows="20"> {
                this.setState({ rawBoxes: event.target.value });
              }} /&gt;
          &lt;/FormField&gt;
        &lt;/FormFields&gt;
        &lt;Footer pad='medium'&gt;
          &lt;Button label='Submit' primary={true}
            onClick={() =&gt; {
              const nextBoxes = JSON.parse(this.state.rawBoxes);
              this.setState({
                boxes: nextBoxes, raw: false, rawBoxes: undefined,
                activeId: this.state.rootId
              });
            }} /&gt;
        &lt;/Footer&gt;
      &lt;/div&gt;</textarea></div>
github grommet / grommet-site / src / components / Doc.js View on Github external
))
          ) : (
            
          )}
        
      );
    });
  }
  if (
    format !== 'function' &amp;&amp;
    syntax[0] !== '(' &amp;&amp;
    syntax[0] !== '&lt;' &amp;&amp;
    syntax[0] !== '['
  ) {
    content = stringify(syntax, { maxLength: 40 });
    content = <code>{content}</code>;
  }
  if (defaultValue !== undefined &amp;&amp; syntax === defaultValue) {
    content = <strong>{content}</strong>;
  }
  return <pre style="{{">{content}</pre>;
};

json-stringify-pretty-compact

The best of both `JSON.stringify(obj)` and `JSON.stringify(obj, null, indent)`.

MIT
Latest version published 3 years ago

Package Health Score

69 / 100
Full package analysis

Popular json-stringify-pretty-compact functions