string format

Format a string with '{0}','{1}'...

当前为 2022-10-28 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/scripts/453846/1110440/string%20format.js

  1. (function () {
  2. "use strict";
  3. if (!String.prototype.format) {
  4. String.prototype.format = function () {
  5. var args = arguments;
  6. return this.replace(/{(\d+)}/g, (match, number) => {
  7. return typeof args[number] != 'undefined' ? args[number] : match;
  8. });
  9. };
  10. } else {
  11. throw 'String.prototype.format defined.';
  12. }
  13. })();