Ai
2 Star 0 Fork 0

mirrors_WebReflection/node-strings

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
index.js 1.14 KB
一键复制 编辑 原始数据 按行查看 历史
'use strict';
var
colors = require('util').inspect.colors,
defineProperty = Object.defineProperty || function (t, k, d) {
t[k] = d.value;
},
extras = {
blink: [5, 25],
hidden: [8, 28],
strike: [9, 29]
},
transform = {}
;
Object.keys(colors).forEach(function (key) {
extras[key] = colors[key];
});
Object.keys(extras).forEach(function (key) {
var
prefix = '\x1B[' + extras[key][0] + 'm',
suffix = '\x1B[' + extras[key][1] + 'm',
method = String.prototype[key]
;
function override() {
return transformer(this);
}
function transformer(value) {
return prefix + String(value) + suffix;
}
transformer.boundaries = [prefix, suffix];
transform[key] = transformer;
override.original = method;
if (method && method.original) return;
defineProperty(String.prototype, key, {
configurable: true,
writable: true,
value: override
});
});
transform.clean = function (value) {
return String(value).replace(
/\x1B\[\d+m([\s\S]*?)\x1B\[\d+m/g,
'$1'
);
};
module.exports = transform;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_WebReflection/node-strings.git
git@gitee.com:mirrors_WebReflection/node-strings.git
mirrors_WebReflection
node-strings
node-strings
master

搜索帮助