string format

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

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

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

  1. // ==UserScript==
  2. // @name string format
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Format a string with '{0}','{1}'...
  6. // @license MIT
  7. // @author 捈荼
  8. // ==/UserScript==
  9.  
  10. (function () {
  11. "use strict";
  12.  
  13. if (!String.prototype.format) {
  14. String.prototype.format = function () {
  15. var args = arguments;
  16. return this.replace(/{(\d+)}/g, (match, number) => {
  17. return typeof args[number] != 'undefined' ? args[number] : match;
  18. });
  19. };
  20. } else {
  21. throw 'String.prototype.format defined.';
  22. }
  23. })();