prototype-helper
Advanced tools
Comparing version 0.2.6 to 0.3.1
@@ -0,0 +0,0 @@ { |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const deep_clone_1 = __importDefault(require("deep-clone")); | ||
Array.prototype.where = function (predicate) { | ||
@@ -85,2 +90,11 @@ return this.filter(predicate); | ||
}; | ||
// Array.prototype.deepClone = function (camelcase: boolean = false) { | ||
// return deepClone(this, camelcase ? camelCase : undefined); | ||
// } | ||
Array.prototype.deepClone = function () { | ||
return deep_clone_1.default(this); | ||
}; | ||
Array.prototype.toJson = function () { | ||
return JSON.stringify(this); | ||
}; | ||
//# sourceMappingURL=array.js.map |
@@ -0,3 +1,4 @@ | ||
import "./number"; | ||
import "./string"; | ||
import "./array"; | ||
import "./string"; | ||
import "./number"; | ||
import "./object"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
require("./number"); | ||
require("./string"); | ||
require("./array"); | ||
require("./string"); | ||
require("./number"); | ||
require("./object"); | ||
//# sourceMappingURL=index.js.map |
export {}; |
@@ -13,3 +13,3 @@ "use strict"; | ||
return "0"; | ||
return `${this}`.toComma(); | ||
return `${new decimal_js_1.default(Number(this)).toString()}`.toComma(); | ||
}; | ||
@@ -42,6 +42,6 @@ Number.prototype.mod = function (amp) { | ||
Number.prototype.fixNumber = function (length = 8) { | ||
return `${this}`.fixNumber(length); | ||
return `${new decimal_js_1.default(Number(this)).toString()}`.fixNumber(length); | ||
}; | ||
Number.prototype.fixPoint = function (length = 0) { | ||
return `${this}`.fixPoint(length); | ||
return `${new decimal_js_1.default(Number(this)).toString()}`.fixPoint(length); | ||
}; | ||
@@ -48,0 +48,0 @@ Number.prototype.abs = function () { |
import "../override/math"; | ||
import "./string"; | ||
import "./number"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -1,4 +0,1 @@ | ||
interface Object { | ||
deepClone(): Object; | ||
} | ||
declare function deepClone(obj: any): any; | ||
export {}; |
"use strict"; | ||
function deepClone(obj) { | ||
if (obj === null || typeof obj !== "object") { | ||
return obj; | ||
} | ||
const result = Array.isArray(obj) ? [] : {}; | ||
for (let key of Object.keys(obj)) { | ||
result[key] = deepClone(obj[key]); | ||
} | ||
return result; | ||
} | ||
Object.prototype.deepClone = deepClone(this); | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const deep_clone_1 = __importDefault(require("deep-clone")); | ||
Object.prototype.deepClone = function () { | ||
return deep_clone_1.default(this); | ||
}; | ||
Object.prototype.toString = function () { | ||
return JSON.stringify(this); | ||
}; | ||
//# sourceMappingURL=object.js.map |
@@ -8,2 +8,3 @@ interface StringConstructor { | ||
addSymbol(space?: string): string; | ||
fromJSON<T>(): T; | ||
} | ||
@@ -17,2 +18,3 @@ interface String { | ||
addSymbol(space?: string): string; | ||
fromJson<T>(): T; | ||
} |
@@ -27,6 +27,3 @@ "use strict"; | ||
return "0"; | ||
const tmp = this.split("."); | ||
let result = tmp[0].replace(/\B(?=(\d{3})+(?!\d))/g, ","); | ||
if (tmp.length != 1) | ||
result += `.${tmp[1]}`; | ||
let result = this.replace(/\B(?<!\.\d*)(?=(\d{3})+(?!\d))/g, ","); | ||
return result; | ||
@@ -40,2 +37,5 @@ }; | ||
}; | ||
String.prototype.fromJson = function () { | ||
return JSON.parse(`${this}`); | ||
}; | ||
//# sourceMappingURL=string.js.map |
import "./string"; | ||
import "./number"; |
@@ -0,0 +0,0 @@ "use strict"; |
import "./interface"; | ||
import "./extension"; | ||
import "./override"; |
@@ -0,0 +0,0 @@ "use strict"; |
interface Array<T> { | ||
single(predicate: (element: T, index: number) => boolean): T; | ||
singleOrDefault(predicate: (element: any, index: number) => boolean, defaultValue?: any): T; | ||
singleOrDefault(predicate: (element: T, index: number) => boolean, defaultValue?: any): T; | ||
where(predicate: (element: T, index: number) => boolean): T[]; | ||
@@ -17,2 +17,4 @@ skip(count: number): T[]; | ||
lastOrDefault(predicate?: (element: T, index: number) => boolean, defaultValue?: any): T; | ||
deepClone<T>(): T[]; | ||
toJson(): string; | ||
} |
"use strict"; | ||
//# sourceMappingURL=array.js.map |
import "./number"; | ||
import "./array"; | ||
import "./object"; |
@@ -5,2 +5,3 @@ "use strict"; | ||
require("./array"); | ||
require("./object"); | ||
//# sourceMappingURL=index.js.map |
@@ -0,0 +0,0 @@ declare interface Number { |
"use strict"; | ||
//# sourceMappingURL=number.js.map |
"use strict"; | ||
// export {}; | ||
// const consola = require("consola"); | ||
// interface ConsoleShowOption { | ||
// log: boolean; | ||
// info: boolean; | ||
// warn: boolean; | ||
// error: boolean; | ||
// } | ||
// interface ConsoleOption { | ||
// development: ConsoleShowOption; | ||
// production: ConsoleShowOption; | ||
// } | ||
// declare global { | ||
// interface Console { | ||
// option: ConsoleOption; | ||
// show(message?: any, ...optionalParams: any[]): void; | ||
// } | ||
// } | ||
// function getTime() { | ||
// const nowDate = new Date(); | ||
// return `${nowDate.getHours()}:${nowDate.getMinutes()}:${nowDate.getSeconds()}:${`${nowDate.getMilliseconds()}`.padStart( | ||
// 3, | ||
// "0" | ||
// )}`; | ||
// } | ||
// console.option = { | ||
// development: { | ||
// log: true, | ||
// info: true, | ||
// warn: true, | ||
// error: true, | ||
// }, | ||
// production: { | ||
// log: false, | ||
// info: false, | ||
// warn: true, | ||
// error: true, | ||
// }, | ||
// }; | ||
// function showMessage(type: "info" | "warn" | "error", ...message: any) { | ||
// consola[type](`\x1b[2m[${getTime()}]\x1b[0m\x1b[37m`, ...message); | ||
// } | ||
// console.show = console.log.bind(this); | ||
// console.log = function (...message: any) { | ||
// // if ( | ||
// // (process.env.NODE_ENV === "development" && console.option.development.log) || | ||
// // (process.env.NODE_ENV === "production" && console.option.production.log) | ||
// // ) | ||
// showMessage("info", ...message); | ||
// }; | ||
// console.info = function (...message: any) { | ||
// // if ( | ||
// // (process.env.NODE_ENV === "development" && console.option.development.info) || | ||
// // (process.env.NODE_ENV === "production" && console.option.production.info) | ||
// // ) | ||
// showMessage("info", ...message); | ||
// }; | ||
// console.warn = function (...message: any) { | ||
// // if ( | ||
// // (process.env.NODE_ENV === "development" && console.option.development.warn) || | ||
// // (process.env.NODE_ENV === "production" && console.option.production.warn) | ||
// // ) | ||
// showMessage("warn", ...message); | ||
// }; | ||
// console.error = function (...message: any) { | ||
// // if ( | ||
// // (process.env.NODE_ENV === "development" && console.option.development.error) || | ||
// // (process.env.NODE_ENV === "production" && console.option.production.error) | ||
// // ) | ||
// showMessage("error", ...message); | ||
// }; | ||
// globalThis.console = console; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const TH = this; | ||
const temp = { | ||
log: console.log.bind(TH), | ||
info: console.log.bind(TH), | ||
warn: console.log.bind(TH), | ||
error: console.log.bind(TH), | ||
}; | ||
// let leftLogList: any[] = []; | ||
// let rightLogList: any[] = []; | ||
function getTime() { | ||
const nowDate = new Date(); | ||
return `${nowDate.getHours()}:${nowDate.getMinutes()}:${nowDate.getSeconds()}:${`${nowDate.getMilliseconds()}`.padStart(3, "0")}`; | ||
} | ||
function showMessage(type, message, ...optionalParams) { | ||
let color = ["\x1b[2m"]; | ||
if (type == "info") | ||
color[0] = "\x1b[34m"; | ||
else if (type == "warn") | ||
color[0] = "\x1b[33m"; | ||
else if (type == "error") | ||
color[0] = "\x1b[31m"; | ||
// if (type == "info") | ||
// leftLogList.push([message, ...optionalParams]); | ||
// else if (type == "warn" || type == "error") | ||
// rightLogList.push([message, ...optionalParams]); | ||
temp[type](`${color[0]}[${getTime()}]\x1b[0m\x1b[37m`, message, ...optionalParams); | ||
} | ||
console.useTheme = useTheme; | ||
function useTheme(consoleOption = { | ||
development: { | ||
log: true, | ||
info: true, | ||
warn: true, | ||
error: true, | ||
}, | ||
production: { | ||
log: false, | ||
info: false, | ||
warn: true, | ||
error: true, | ||
}, | ||
}) { | ||
console.log = function (message, ...optionalParams) { | ||
if ((process.env.NODE_ENV === "development" && consoleOption.development.log) || | ||
(process.env.NODE_ENV === "production" && consoleOption.production.log) || | ||
!process.env.NODE_ENV) | ||
showMessage("log", message, ...optionalParams); | ||
}; | ||
console.info = function (message, ...optionalParams) { | ||
if ((process.env.NODE_ENV === "development" && consoleOption.development.info) || | ||
(process.env.NODE_ENV === "production" && consoleOption.production.info) || | ||
!process.env.NODE_ENV) | ||
showMessage("info", message, ...optionalParams); | ||
}; | ||
console.warn = function (message, ...optionalParams) { | ||
if ((process.env.NODE_ENV === "development" && consoleOption.development.warn) || | ||
(process.env.NODE_ENV === "production" && consoleOption.production.warn) || | ||
!process.env.NODE_ENV) | ||
showMessage("warn", message, ...optionalParams); | ||
}; | ||
console.error = function (message, ...optionalParams) { | ||
if ((process.env.NODE_ENV === "development" && consoleOption.development.error) || | ||
(process.env.NODE_ENV === "production" && consoleOption.production.error) || | ||
!process.env.NODE_ENV) | ||
showMessage("error", message, ...optionalParams); | ||
}; | ||
globalThis.console = console; | ||
} | ||
//# sourceMappingURL=console.js.map |
import "../extension"; | ||
import "./console"; | ||
import "./math"; |
@@ -0,0 +0,0 @@ "use strict"; |
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=linq.js.map |
@@ -0,0 +0,0 @@ export {}; |
@@ -0,0 +0,0 @@ "use strict"; |
import "./index"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
require("./index"); | ||
console.useTheme(); | ||
// import "../dist"; | ||
@@ -86,3 +87,13 @@ // console.log("hello"); | ||
console.log((300).per(10)); | ||
console.log((2 ** 256 + 0.213445).toComma().fixPoint(10)); | ||
console.info("test1"); | ||
console.warn("test2"); | ||
console.error("test3"); | ||
const aaa = [1, 2, 3, 4, 5]; | ||
console.log(aaa.toJson()); | ||
const bbb = aaa.deepClone(); | ||
const ccc = `[1,2,3,4,5]`; | ||
console.log(aaa, bbb, aaa === bbb); | ||
console.log(ccc.fromJson()); | ||
// hello.findIndex; | ||
//# sourceMappingURL=test.js.map |
{ | ||
"name": "prototype-helper", | ||
"version": "0.2.6", | ||
"version": "0.3.1", | ||
"private": false, | ||
@@ -25,3 +25,4 @@ "main": "./dist/index.js", | ||
"dependencies": { | ||
"decimal.js": "^10.3.1" | ||
"decimal.js": "^10.3.1", | ||
"deep-clone": "^3.0.3" | ||
}, | ||
@@ -28,0 +29,0 @@ "devDependencies": { |
@@ -0,0 +0,0 @@ <img src="https://capsule-render.vercel.app/api?type=waving&color=343a40&height=210§ion=header&text=Typescript Prototype Helper&fontSize=50&fontAlignY=35&fontColor=adb5bd" /> |
@@ -0,0 +0,0 @@ { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
50875
625
2
+ Addeddeep-clone@^3.0.3
+ Addeddeep-clone@3.0.3(transitive)