diff options
Diffstat (limited to 'node_modules/fbjs/lib/sprintf.js')
-rw-r--r-- | node_modules/fbjs/lib/sprintf.js | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/node_modules/fbjs/lib/sprintf.js b/node_modules/fbjs/lib/sprintf.js new file mode 100644 index 000000000..98a65c61a --- /dev/null +++ b/node_modules/fbjs/lib/sprintf.js @@ -0,0 +1,34 @@ +"use strict"; + +/** + * Copyright (c) 2013-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * + * @typechecks + */ + +/** + * Simple function for formatting strings. + * + * Replaces placeholders with values passed as extra arguments + * + * @param {string} format the base string + * @param ...args the values to insert + * @return {string} the replaced string + */ +function sprintf(format) { + for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + args[_key - 1] = arguments[_key]; + } + + var index = 0; + return format.replace(/%s/g, function (match) { + return args[index++]; + }); +} + +module.exports = sprintf;
\ No newline at end of file |