prototype-helper
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -8,3 +8,5 @@ interface Number { | ||
safeSubtract(value: number): number; | ||
padPoint(length: number): string; | ||
padZero(length: number): string; | ||
} | ||
declare function hexfloatNotation(number: number, numberPoint?: number): number; |
@@ -27,16 +27,19 @@ "use strict"; | ||
Number.prototype.safeDivision = function (value) { | ||
return (Number(this) / value).toFixed(16).toNumber(); | ||
return Math.round10(Math.floor10(Number(this) / value, 16), 15); | ||
}; | ||
Number.prototype.safeMultiply = function (value) { | ||
return (Number(this) * value).toFixed(16).toNumber(); | ||
return Math.round10(Math.floor10(Number(this) * value, 16), 15); | ||
}; | ||
Number.prototype.safeAdd = function (value) { | ||
return (Number(this) + value).toFixed(16).toNumber(); | ||
return Math.round10(Math.floor10(Number(this) + value, 16), 15); | ||
}; | ||
Number.prototype.safeAdd = function (value) { | ||
return (Number(this) + value).toFixed(16).toNumber(); | ||
}; | ||
Number.prototype.safeSubtract = function (value) { | ||
return (Number(this) - value).toFixed(16).toNumber(); | ||
return Math.round10(Math.floor10(Number(this) - value, 16), 15); | ||
}; | ||
Number.prototype.padPoint = function (length) { | ||
return `${this}`.padPoint(length); | ||
}; | ||
Number.prototype.padZero = function (length) { | ||
return `${this}`.padZero(length); | ||
}; | ||
//# sourceMappingURL=number.js.map |
@@ -0,2 +1,3 @@ | ||
import "../override/math"; | ||
import "./string"; | ||
import "./number"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
require("../override/math"); | ||
require("./string"); | ||
@@ -12,3 +13,6 @@ require("./number"); | ||
expect((0.1).safeAdd(0.2)).toBe(0.3); | ||
expect((0.3).safeAdd(-0.2)).toBe(0.1); | ||
expect((0.1).safeSubtract(0.2)).toBe(-0.1); | ||
expect((0.1).safeSubtract(0.3)).toBe(-0.2); | ||
expect((0.1).safeSubtract(-0.3)).toBe(0.4); | ||
expect((0.1).safeMultiply(0.2)).toBe(0.02); | ||
@@ -15,0 +19,0 @@ expect((0.1).safeDivision(0.2)).toBe(0.5); |
interface Object { | ||
deepCopy(): Object; | ||
deepClone(): Object; | ||
} | ||
declare function deepClone(obj: any): any; |
@@ -12,3 +12,3 @@ "use strict"; | ||
} | ||
Object.prototype.deepCopy = deepClone(this); | ||
Object.prototype.deepClone = deepClone(this); | ||
//# sourceMappingURL=object.js.map |
interface StringConstructor { | ||
padZero(s: string, length: number): string; | ||
padPoint(s: string, length: number): string; | ||
padZero(length: number): string; | ||
leadingChars(chars: string | number, length: number): string; | ||
toComma(length?: number): string; | ||
toComma(): string; | ||
toNumber(): number; | ||
} | ||
interface String { | ||
padPoint(length: number): string; | ||
padZero(length: number): string; | ||
leadingChars(chars: string | number, length: number): string; | ||
toComma(length?: number): string; | ||
toComma(): string; | ||
toNumber(): number; | ||
} |
@@ -5,13 +5,29 @@ "use strict"; | ||
}; | ||
String.prototype.padPoint = function (length = 0) { | ||
let base = this.split("."); | ||
let point = this.toNumber().toString().split("."); | ||
if (point.length == 1) | ||
point[1] = ""; | ||
else if (point.length >= 3) | ||
throw new Error("Invalid"); | ||
let result = base[0]; | ||
if (point.length == 2 && length != 0) | ||
result += `.${point[1].padEnd(length, "0")}`; | ||
return result; | ||
}; | ||
String.prototype.padZero = function (length) { | ||
let padString = this.toString(); | ||
return padString.padStart(length, "0"); | ||
let point = this.toNumber().toString().split("."); | ||
let result = point[0].padStart(length, "0"); | ||
if (point.length == 2) | ||
result += `.${point[1]}`; | ||
return result; | ||
}; | ||
String.prototype.toComma = function (length = 0) { | ||
String.prototype.toComma = function () { | ||
if (this.length == 0 || this == "NaN") | ||
return "0"; | ||
const tmp = this.split("."); | ||
let num = tmp[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",").padZero(length); | ||
num += tmp.length != 1 && tmp[1].length != 0 ? `.${tmp[1]}` : ""; | ||
return num; | ||
let result = tmp[0].replace(/\B(?=(\d{3})+(?!\d))/g, ","); | ||
if (tmp.length != 1) | ||
result += `.${tmp[1]}`; | ||
return result; | ||
}; | ||
@@ -18,0 +34,0 @@ String.prototype.toNumber = function () { |
import "./string"; | ||
import "./number"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
require("./string"); | ||
require("./number"); | ||
test("string - toComma()", () => { | ||
expect("123".toComma().length).toBe(3); | ||
expect("123456".toComma().length).toBe(7); | ||
expect("123".toComma()).toBe("123"); | ||
expect("123456".toComma()).toBe("123,456"); | ||
expect("24816246784".toComma()).toBe("24,816,246,784"); | ||
@@ -11,4 +12,7 @@ expect("24,816,246,784".toNumber()).toBe(24816246784); | ||
test("string - pad extension", () => { | ||
expect("300".padZero(10)).toBe("0000000300"); | ||
expect("300".padPoint(3)).toBe("300.000"); | ||
expect((30222.12).padPoint(5)).toBe("30222.12000"); | ||
expect("30222.50380000".padPoint(5).toComma()).toBe("30,222.50380"); | ||
expect((30222.12).padPoint(3).toComma()).toBe("30,222.120"); | ||
}); | ||
//# sourceMappingURL=string.test.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const consola = require("consola"); | ||
function getTime() { | ||
const nowDate = new Date(); | ||
return `${nowDate.getHours()}:${nowDate.getMinutes()}:${nowDate.getSeconds()}:${`${nowDate.getMilliseconds()}`.padStart(3, "0")}`; | ||
} | ||
function showMessage(type, ...message) { | ||
consola[type](...message); | ||
consola[type](`[${getTime()}]`, ...message); | ||
} | ||
@@ -7,0 +11,0 @@ console.log = function (...message) { |
@@ -1,1 +0,1 @@ | ||
import "../dist"; | ||
import "./index"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// import "./index"; | ||
require("../dist"); | ||
require("./index"); | ||
// import "../dist"; | ||
// console.log("hello"); | ||
// console.warn("warn log"); | ||
// console.error("error log"); | ||
// console.log("300".padZero(10)); | ||
// console.log("300".pointPad(10)); | ||
// console.log("300".toComma(10)); | ||
@@ -20,10 +20,31 @@ // console.log("24816246784".toComma()); | ||
// console.log(0.2 / 0.2); | ||
// console.log((0.1).safeDivision(0.2)); | ||
console.log(Math); | ||
console.warn(Math.round); | ||
// console.log((0.1).safeAdd(0.2)); // 0.6 | ||
// console.log((0.3).safeAdd(-0.2)); | ||
// console.log((0.1).safeSubtract(0.3)); // 0.6 | ||
// console.log((35).ampersand(0.8)); // 0.6 | ||
// console.log((0.2).safeDivision(0.6)); // 0.8333333333333334 | ||
// console.log((0.1).safeMultiply(0.2)); // 0.02 | ||
////////////////////////////////////////////////////////////////////////// | ||
// console.log(Math.round10(112.5345, 3)); | ||
// console.log(Math.round(112.5)); | ||
// console.log(Math.floor10(112.5345, 3)); | ||
// console.log(Math.ceil10(112.5345, 3)); | ||
// // console.log(Math.round(112.5)); | ||
// console.log(Math.randomRange(112.5, 200, 1)); | ||
// console.log(Math.randomRange(112.5, 200, 0)); | ||
// for (var i = 0; i < 10; i++) { | ||
// console.log(Math.randomRange(4, 5)); | ||
// } | ||
//////////////////////////////////////////////////////////////////////////// | ||
console.log("123".toComma()); | ||
// console.log((1).padZero(5)); | ||
// console.log((3022).padZero(1)); | ||
// console.log((30222.12).padZero(8)); | ||
// console.log((30222.12).padZero(8).toComma()); | ||
console.log("30222.50380000".padPoint(5).toComma()); | ||
// console.log((30222).padPoint(3)); | ||
// console.log((30222.12).padPoint(5).toComma()); | ||
// console.log((30222.12).toComma().pointPad(5)); | ||
// console.log("30222.12".pointPad(5)); | ||
const hello = [1, 2, 3, 4, 5, 6, 7, 8, 9]; | ||
// hello.findIndex; | ||
//# sourceMappingURL=test.js.map |
{ | ||
"name": "prototype-helper", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"private": false, | ||
"main": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/k22pr/prototype-helper.git" | ||
}, | ||
"keywords": [ | ||
"dnf" | ||
], | ||
"author": "서버지기", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/k22pr/prototype-helper/issues" | ||
}, | ||
"homepage": "https://github.com/k22pr/prototype-helper#readme", | ||
"dependencies": { | ||
"consola": "^2.15.3", | ||
"dayjs": "^1.10.5" | ||
"consola": "^2.15.3" | ||
}, | ||
@@ -11,0 +23,0 @@ "devDependencies": { |
@@ -1,4 +0,20 @@ | ||
# Typescript Prototype Helper | ||
<h1 align="center">Typescript Prototype Helper</h1> | ||
<p align="center"> | ||
<a href="https://github.com/prettier/prettier"> | ||
<img alt="code style: prettier" src="https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=for-the-badge"> | ||
</a> | ||
<a href="https://www.npmjs.com/package/prototype-helper"> | ||
<img alt="code style: prettier" src="https://img.shields.io/npm/v/prototype-helper.svg?style=for-the-badge"> | ||
</a> | ||
<a href="https://github.com/k22pr/prototype-helper/blob/master/LICENSE"> | ||
<img alt="code style: prettier" src="https://img.shields.io/github/license/mashape/apistatus.svg?style=for-the-badge"> | ||
</a> | ||
<img alt="npm" src="https://img.shields.io/npm/dm/prototype-helper?style=for-the-badge"> | ||
<!-- <img alt="AppVeyor tests (compact)" src="https://img.shields.io/appveyor/tests/k22pr/prototype-helper?compact_message&style=for-the-badge"> --> | ||
</p> | ||
<p align="center"> | ||
Adds a convenient prototype function package. | ||
</p> | ||
@@ -5,0 +21,0 @@ # Prototype Helper |
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
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
29566
1
352
0
1
166
2
- Removeddayjs@^1.10.5
- Removeddayjs@1.11.13(transitive)