string format

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

目前為 2022-10-28 提交的版本,檢視 最新版本

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.gf.qytechs.cn/scripts/453846/1110442/string%20format.js

// ==UserScript==
// @name string format
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Format a string with '{0}','{1}'...
// @license MIT
// @author 捈荼
// ==/UserScript==

(function () {
    "use strict";
    
    if (!String.prototype.format) {
        String.prototype.format = function () {
            var args = arguments;
            return this.replace(/{(\d+)}/g, (match, number) => {
                return typeof args[number] != 'undefined' ? args[number] : match;
            });
        };
    } else {
        throw 'String.prototype.format defined.';
    }
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址