How to use jsesc - 10 common examples

To help you get started, we’ve selected a few jsesc 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 pocketjoso / penthouse / src / normalize-css.js View on Github external
.replace(/(content\s*:\s*)(['"])([^'"]*)(['"])/g, function (
        match,
        pre,
        quote,
        innerContent,
        quote2
      ) {
        if (quote !== quote2) {
          return
        }
        return pre + quote + jsesc(innerContent) + quote
      })
      // .. however it's not perfect for our needs,
github babel / babel / packages / babel-generator / src / generators / types.js View on Github external
export function StringLiteral(node: Object) {
  const raw = this.getPossibleRaw(node);
  if (!this.format.minified && raw != null) {
    this.token(raw);
    return;
  }

  // ensure the output is ASCII-safe
  const opts = this.format.jsescOption;
  if (this.format.jsonCompatibleStrings) {
    opts.json = true;
  }
  const val = jsesc(node.value, opts);

  return this.token(val);
}
github bodil / eulalie / test / parser.js View on Github external
check.it("parse a string", [gen.asciiString], (s) => {
    const qs = `"${jsesc(s, {quotes: "double"})}"`;
    const r = p.parse(p.quotedString, p.stream(qs));
    assert(p.isResult(r), `parser output is not ParseResult, s '${s}' qs '${qs}'`);
    assert.equal(r.value, s, `'${r.value}' did not match '${s}' - string was '${qs}'`);
  });
});
github magento / baler / src / transformAMD.ts View on Github external
export function wrapTextModule(id: string, source: string) {
    const [before, after] = `define('${id}', function() {
    return 'SPLIT';
});`.split('SPLIT');

    const escaped = jsesc(source);
    const str = new MagicString(source);
    const startPiece = escaped.slice(0, source.length);

    return str
        .overwrite(0, source.length, startPiece)
        .append(escaped.slice(source.length))
        .append(after)
        .prepend(before);
}
github expo / snack-web / server / src / pages / Document.js View on Github external
}

                button[disabled] {
                  cursor: default;
                }

                #root {
                  height: 100vh;
                }
              `,
            }}
          />
github downplay / jarl-react / demo / server / renderHtml.js View on Github external
const stringify = object =>
    `"${jsesc(JSON.stringify(object).replace(/
github react-static / react-static / packages / react-static / src / static / components / BodyWithMeta.js View on Github external
const generateRouteInformation = embeddedRouteInfo => ({
  __html: `
    window.__routeInfo = JSON.parse(${jsesc(JSON.stringify(embeddedRouteInfo), {
      isScriptContext: true,
      wrap: true,
      json: true,
    })});`,
})
github cyclosproject / ng-openapi-gen / lib / enum-value.ts View on Github external
constructor(public type: string, name: string | undefined, _value: any, public options: Options) {
    const value = String(_value);
    this.name = name || enumName(value, options);
    if (type === 'string') {
      this.value = `'${jsesc(value)}'`;
    } else {
      this.value = value;
    }
  }
}
github mdn / kuma / kuma / javascript / src / ssr.jsx View on Github external
function stringifySafely(obj) {
    return jsesc(JSON.stringify(obj), {
        json: true,
        isScriptContext: true
    });
}
/*
github ifiokjr / remirror / @remirror / cli / src / commands / bundle / cli-parcel.ts View on Github external
const createFile = (withAnnotation = false) => (script: string) => `export const createHTML = ${
  withAnnotation ? '(html: string)' : 'html'
} => \`

  
    
    
    
    <title>This is the webview</title>
  
  
    <div id="${REMIRROR_ID}">\${html}</div>
  

\`;
`;

jsesc

Given some data, jsesc returns the shortest possible stringified & ASCII-safe representation of that data.

MIT
Latest version published 3 years ago

Package Health Score

67 / 100
Full package analysis

Popular jsesc functions