sprintf.js.flow 607 B

12345678910111213141516171819202122232425
  1. /**
  2. * Copyright (c) 2013-present, Facebook, Inc.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @providesModule sprintf
  8. * @typechecks
  9. */
  10. /**
  11. * Simple function for formatting strings.
  12. *
  13. * Replaces placeholders with values passed as extra arguments
  14. *
  15. * @param {string} format the base string
  16. * @param ...args the values to insert
  17. * @return {string} the replaced string
  18. */
  19. function sprintf(format, ...args) {
  20. let index = 0;
  21. return format.replace(/%s/g, match => args[index++]);
  22. }
  23. module.exports = sprintf;