string format

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

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

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/scripts/453846/1110441/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. // @author 捈荼
  7. // ==/UserScript==
  8.  
  9. (function () {
  10. "use strict";
  11. if (!String.prototype.format) {
  12. String.prototype.format = function () {
  13. var args = arguments;
  14. return this.replace(/{(\d+)}/g, (match, number) => {
  15. return typeof args[number] != 'undefined' ? args[number] : match;
  16. });
  17. };
  18. } else {
  19. throw 'String.prototype.format defined.';
  20. }
  21. })();