How to use sprintf-js - 10 common examples

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 thiagodp / concordialang / src / modules / testscript / PluginInputProcessor.ts View on Github external
private drawSinglePlugin = ( p: TestScriptPluginData ): void => {
        const format = "  - %-12s: %s"; // util.format does not support padding :(
        this.write( 'Plugin ' + chalk.yellow( p.name ) );
        this.write( sprintf( format, 'version', p.version ) );
        this.write( sprintf( format, 'description', p.description ) );
        this.write( sprintf( format, 'targets', p.targets.join( ', ' ) ) );
        const authors = p.authors.map( ( a, idx ) => 0 === idx ? a : sprintf( '%-17s %s', '', a ) );
        this.write( sprintf( format, 'authors', authors.join( '\n') ) );        
        this.write( sprintf( format, 'fake', p.isFake ? 'yes': 'no' ) );        
        this.write( sprintf( format, 'file', p.file ) );
        this.write( sprintf( format, 'class', p.class ) );        
    };
github TrigenSoftware / i18n-for-browser / src / index.js View on Github external
function postProcess(_text, namedValues, params, count) {

	let text = _text;

	// test for parsable interval string
	if (/\|/.test(text)) {
		text = parsePluralInterval(text, count);
	}

	// replace the counter
	if (typeof count == 'number') {
		text = vsprintf(text, [parseInt(count, 10)]);
	}

	// if the text string contains {{Mustache}} patterns we render it as a mini tempalate
	if (/\{\{.*\}\}/.test(text)) {
		text = Mustache.render(text, namedValues);
	}

	// if we have extra arguments with values to get replaced,
	// an additional substition injects those strings afterwards
	if (/%/.test(text) && params.length) {
		text = vsprintf(text, params);
	}

	return text;
}
github TrigenSoftware / i18n-for-browser / src / index.js View on Github external
}

	// replace the counter
	if (typeof count == 'number') {
		text = vsprintf(text, [parseInt(count, 10)]);
	}

	// if the text string contains {{Mustache}} patterns we render it as a mini tempalate
	if (/\{\{.*\}\}/.test(text)) {
		text = Mustache.render(text, namedValues);
	}

	// if we have extra arguments with values to get replaced,
	// an additional substition injects those strings afterwards
	if (/%/.test(text) && params.length) {
		text = vsprintf(text, params);
	}

	return text;
}
github mashpie / i18n-node / i18n.js View on Github external
var postProcess = function(msg, namedValues, args, count) {

    // test for parsable interval string
    if ((/\|/).test(msg)) {
      msg = parsePluralInterval(msg, count);
    }

    // replace the counter
    if (typeof count === 'number') {
      msg = vsprintf(msg, [parseInt(count, 10)]);
    }

    // if the msg string contains {{Mustache}} patterns we render it as a mini tempalate
    if ((/{{.*}}/).test(msg)) {
      msg = Mustache.render(msg, namedValues);
    }

    // if we have extra arguments with values to get replaced,
    // an additional substition injects those strings afterwards
    if ((/%/).test(msg) && args && args.length > 0) {
      msg = vsprintf(msg, args);
    }

    return msg;
  };
github laurent22 / joplin / ReactNativeClient / lib / services / RevisionService.js View on Github external
if (rev) this.logger().debug(sprintf('RevisionService::collectRevisions: Saved revision %s (old note)', rev.id));
							}

							const rev = await this.createNoteRevision_(note);
							if (rev) this.logger().debug(sprintf('RevisionService::collectRevisions: Saved revision %s (Last rev was more than %d ms ago)', rev.id, Setting.value('revisionService.intervalBetweenRevisions')));
							doneNoteIds.push(noteId);
							this.isOldNotesCache_[noteId] = false;
						}
					}

					if (change.type === ItemChange.TYPE_DELETE && !!change.before_change_item) {
						const note = JSON.parse(change.before_change_item);
						const revExists = await Revision.revisionExists(BaseModel.TYPE_NOTE, note.id, note.updated_time);
						if (!revExists) {
							const rev = await this.createNoteRevision_(note);
							if (rev) this.logger().debug(sprintf('RevisionService::collectRevisions: Saved revision %s (for deleted note)', rev.id));
						}
						doneNoteIds.push(noteId);
					}

					Setting.setValue('revisionService.lastProcessedChangeId', change.id);
				}
			}
		} catch (error) {
			if (error.code === 'revision_encrypted') {
				// One or more revisions are encrypted - stop processing for now
				// and these revisions will be processed next time the revision
				// collector runs.
				this.logger().info('RevisionService::collectRevisions: One or more revision was encrypted. Processing was stopped but will resume later when the revision is decrypted.', error);
			} else {
				this.logger().error('RevisionService::collectRevisions:', error);
			}
github fengari-lua / fengari / src / lstrlib.js View on Github external
if (Object.is(x, -0))
            zero = "-" + zero;
        return to_luastring(zero);
    } else {
        let buff = "";
        let fe = frexp(x);  /* 'x' fraction and exponent */
        let m = fe[0];
        let e = fe[1];
        if (m < 0) {  /* is number negative? */
            buff += '-';  /* add signal */
            m = -m;  /* make it positive */
        }
        buff += "0x";  /* add "0x" */
        buff += (m * (1<
github cloudera / hue / desktop / core / src / desktop / js / ko / bindings / ko.simplesize.js View on Github external
humanSize: function(bytes) {
      const isNumber = !isNaN(parseFloat(bytes)) && isFinite(bytes);
      if (!isNumber) {
        return '';
      }

      // Special case small numbers (including 0), because they're exact.
      if (bytes < 1000) {
        return sprintf.sprintf('%d', bytes);
      }

      let index = Math.floor(that.getBaseLog(bytes, 1000));
      index = Math.min(that.units.length - 1, index);
      return sprintf.sprintf('%.1f %s', bytes / Math.pow(1000, index), that.units[index]);
    }
  });
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

sprintf-js

JavaScript sprintf implementation

BSD-3-Clause
Latest version published 8 months ago

Package Health Score

79 / 100
Full package analysis

Similar packages