How to use the sprintf-js.sprintf.parse function in sprintf-js

To help you get started, we’ve selected a few sprintf-js 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 getsentry / sentry / src / sentry / static / sentry / app / locale.tsx View on Github external
function formatForReact(formatString: string, args: FormatArg[]) {
  const nodes: React.ReactNodeArray = [];
  let cursor = 0;

  // always re-parse, do not cache, because we change the match
  sprintf.parse(formatString).forEach((match: any, idx: number) => {
    if (isString(match)) {
      nodes.push(match);
      return;
    }

    let arg: FormatArg = null;

    if (match[2]) {
      arg = (args[0] as ComponentMap)[match[2][0]];
    } else if (match[1]) {
      arg = args[parseInt(match[1], 10) - 1];
    } else {
      arg = args[cursor++];
    }

    // this points to a react element!
github NetEaseGame / Sentry / src / sentry / static / sentry / app / locale.jsx View on Github external
function formatForReact(formatString, args) {
  let rv = [];
  let cursor = 0;

  // always re-parse, do not cache, because we change the match
  sprintf.parse(formatString).forEach((match, idx) => {
    if (typeof match === 'string') {
      rv.push(match);
    } else {
      let arg = null;
      if (match[2]) {
        arg = args[0][match[2][0]];
      } else if (match[1]) {
        arg = args[parseInt(match[1], 10) - 1];
      } else {
        arg = args[cursor++];
      }

      // this points to a react element!
      if (React.isValidElement(arg)) {
        rv.push(React.cloneElement(arg, {key: idx}));
      // not a react element, fuck around with it so that sprintf.format
github getsentry / sentry / src / sentry / static / sentry / app / locale.jsx View on Github external
function formatForReact(formatString, args) {
  const rv = [];
  let cursor = 0;

  // always re-parse, do not cache, because we change the match
  sprintf.parse(formatString).forEach((match, idx) => {
    if (_.isString(match)) {
      rv.push(match);
    } else {
      let arg = null;
      if (match[2]) {
        arg = args[0][match[2][0]];
      } else if (match[1]) {
        arg = args[parseInt(match[1], 10) - 1];
      } else {
        arg = args[cursor++];
      }

      // this points to a react element!
      if (React.isValidElement(arg)) {
        rv.push(React.cloneElement(arg, {key: idx}));
        // not a react element, fuck around with it so that sprintf.format
github apache / incubator-superset / superset / assets / src / locales.jsx View on Github external
function formatForReact(formatString, args) {
  const rv = [];
  let cursor = 0;
  sprintf.parse(formatString).forEach((match, idx) => {
    const cpoyMatch = match;
    let copyIdx = idx;
    if (typeof match === 'string') {
      rv.push(match);
    } else {
      let arg = null;
      if (match[2]) {
        arg = args[0][match[2][0]];
      } else if (match[1]) {
        arg = args[parseInt(match[1], 10) - 1];
      } else {
        arg = args[cursor++];
      }
      if (React.isValidElement(arg)) {
        rv.push(React.cloneElement(arg, { key: idx }));
      } else {

sprintf-js

JavaScript sprintf implementation

BSD-3-Clause
Latest version published 1 year ago

Package Health Score

68 / 100
Full package analysis

Similar packages