How to use js-string-escape - 10 common examples

To help you get started, we’ve selected a few js-string-escape 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 cerner / kaiju / node / service / kaiju_plugins / default / code / generator.js View on Github external
Object.keys(object).forEach((key) => {
      const { type, value } = object[key];
      if (value === undefined || value === null) {
        // No value was provided. Do not generate props
      } else if (key === 'children') {
        parameters[key] = type === 'String' ? value : generateProperties(value).join('');
      } else if (value.type === 'kaiju::Text') {
        // Custom code to convert the Kaiju text component into raw text
        const text = stringEscape(value.properties.text.value);
        parameters[key] = `'${text}'`;
      } else if (type === 'Array') {
        parameters[key] = `[${generateProperties(value).join(', ')}]`;
      } else if (type === 'Hash') {
        const hash = generateProperties(value);
        parameters[key] = `{ ${Object.keys(hash).map(k => `${k}: ${hash[k]}`).join(', ')} }`;
      } else if (type === 'Component') {
        const properties = generateProperties(value.properties);
        imports.add(`import ${value.import} from '${value.import_from}';`);

        let props = '';
        Object.keys(properties).forEach((prop) => {
          if (prop !== 'children') {
            props += ` ${prop}={${properties[prop]}}`;
          }
        });
github denali-js / core / lib / cli / lint-tree.js View on Github external
testGenerator(relativePath, errors) {
    let passed = errors.length === 0;
    let messages = `${ relativePath } should pass ESLint`;
    if (!passed) {
      messages += '\n\n';
      messages += errors.map((error) => {
        return `${ error.line }:${ error.column } - ${ error.message } (${ error.ruleId })`;
      }).join('\n');
    }
    let output = "import test from 'ava';\ntest((t) => {";
    if (passed) {
      output += "  t.pass('Linting passed.')\n";
    } else {
      output += `  t.fail('${ escape(messages) }');\n`;
    }
    output += '});\n';
    return output;
  }
github Evaneos / vitaminjs / packages / vitaminjs-runtime / src / server / components / App.jsx View on Github external
const App = ({ store, insertCss, renderProps, mainEntry }) => (
    
        
        
    
);
App.propTypes = propTypes;
github doczjs / docz / core / docz-utils / src / jsx.ts View on Github external
export const sanitizeCode = (code: string) => {
  const trimmed = strip(code).trim()
  const newCode =
    trimmed.startsWith('{') && trimmed.endsWith('}')
      ? trimmed.substr(1, trimmed.length - 2).trim()
      : trimmed

  return escapeJS(strip(newCode))
}
github denali-js / core / lib / cli / lint-tree.js View on Github external
testGenerator(relativePath, errors) {
    let passed = errors.length === 0;
    let messages = `${ relativePath } should pass ESLint`;
    if (!passed) {
      messages += '\n\n';
      messages += errors.map((error) => {
        return `${ error.line }:${ error.column } - ${ error.message } (${ error.ruleId })`;
      }).join('\n');
    }
    let output = '';
    if (passed) {
      output += "  t.pass('${ relativePath } passed ESLint')\n";
    } else {
      output += `  t.fail('${ escape(messages) }');\n`;
    }
    return output;
  }
github electron-userland / electron-compilers / src / js / typescript.js View on Github external
addHotModuleLoadingRegistration(sourceCode, fileName, exports) {
    if (exports.length < 1) return sourceCode;

    let registrations = exports.map(x => {
      let id = `${x}` == 'default' ? '(typeof _default !== \'undefined\' ? _default : exports.default)' : `${x}`;
      let name = `"${x}"`;
      return `__REACT_HOT_LOADER__.register(${id}, ${name}, __FILENAME__);\n`;
    });

    let tmpl = `
${sourceCode}

if (typeof __REACT_HOT_LOADER__ !== 'undefined') {
  const __FILENAME__ = "${jsEscape(fileName)}";
  ${registrations}
}`;

    return tmpl;
  }
github cerner / kaiju / node / service / kaiju_plugins / default / code / generator.js View on Github external
} else if (type === 'Component') {
        const properties = generateProperties(value.properties);
        imports.add(`import ${value.import} from '${value.import_from}';`);

        let props = '';
        Object.keys(properties).forEach((prop) => {
          if (prop !== 'children') {
            props += ` ${prop}={${properties[prop]}}`;
          }
        });

        parameters[key] = `<${value.code_name}${props}>${properties.children || ''}`;
      } else if (type === 'Number') {
        parameters[key] = Number(value);
      } else if (type === 'String') {
        parameters[key] = `'${stringEscape(value)}'`;
      } else {
        parameters[key] = value;
      }
    });
github plnkr / runtime / dist / css.js View on Github external
var _loop_1 = function () {
        var _a = queue.shift(), parent_1 = _a.parent, node_1 = _a.node, i = _a.i;
        if (typeof node_1 === 'string') {
            parent_1.children[i] = escapeString(node_1);
            return "continue";
        }
        node_1.children.forEach(function (child, i) {
            return queue.push({ parent: node_1, node: child, i: i });
        });
    };
    while (queue.length) {
github javascript-obfuscator / javascript-obfuscator / src / node-transformers / preparing-transformers / EvaCallExpressionTransformer.ts View on Github external
public restoreNode (evalRootAstHostNode: ESTree.FunctionExpression, parentNode: ESTree.Node): ESTree.Node {
        const targetAst: ESTree.Statement[] = evalRootAstHostNode.body.body;
        const obfuscatedCode: string = NodeUtils.convertStructureToCode(targetAst);

        return NodeFactory.callExpressionNode(
            NodeFactory.identifierNode('eval'),
            [
                NodeFactory.literalNode(jsStringEscape(obfuscatedCode))
            ]
        );
    }

js-string-escape

Escape strings for use as JavaScript string literals

MIT
Latest version published 8 years ago

Package Health Score

67 / 100
Full package analysis

Popular js-string-escape functions