tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"sourceMap": true
},
"exclude": [
"node_modules"
]
}
test:
let str = Md5.Instance.get_md5("123456");
console.log(str)
//len:32
//e10adc3949ba59abbe56e057f20f883e
md5.ts
class Md5 {
private static _inst: Md5;
public static get Instance(): Md5 {
return this._inst || (this._inst = new Md5());
}
public get_md5(str: string): string {
return this.md5(str);
}
split(target: string | any[], step: number, markString: boolean = typeof target === "string") {
if (typeof target === "string") target = target.split("");
let result: any[] = target.map(
(_, index: number) =>
index % step === 0
? Array.from(Array(step).keys()).map((x: number) => target[index + x])
: []
)
.filter((x: any[]) => x.length > 0);
if (markString) result = result.map((x: any[]) => x.join(""))
return result;
}
padding(str: string | any[], length: number, char: string, tail: boolean = true, isArray: boolean = Array.isArray(str)) {
let arr;
if (Array.isArray(str)) {
arr = str;
} else {
arr = str.split("");
}
const paddingStr: any[] = this.range(length - str