UNPKG

jsshort

Version:

It will make your codes much short and easiar

117 lines (96 loc) 3.1 kB
export function len(this: string): number { return this.length; } export function str(this: string): string { return this.toString(); } export function add(this: string, ...strings: string[]): string { return this.concat(...strings); } export function sb(this: string, start: number, end: number): string { return this.substring(start, end); } export function ind(this: string, substring: string): number { return this.indexOf(substring); } export function lstInd(this: string, substring: string): number { return this.lastIndexOf(substring); } export function inString(this: string, substring: string): boolean { return this.includes(substring); } export function start(this: string, substring: string): boolean { return this.startsWith(substring); } export function end(this: string, substring: string): boolean { return this.endsWith(substring); } export function upr(this: string): string { return this.toUpperCase(); } export function lwr(this: string): string { return this.toLowerCase(); } export function trS(this: string): string { return this.trimStart(); } export function trE(this: string): string { return this.trimEnd(); } export function rpc(this: string, stringOrRegex: string, newSubstring: string): string { return this.replace(stringOrRegex, newSubstring); } export function rpcA(this: string, stringOrRegex: string | RegExp, newSubstring: string): string { return this.replace(stringOrRegex, newSubstring); } export function at(this: string, index: number): string { return this.charAt(index); } export function chCdAt(this: string, index: number): number { return this.charCodeAt(index); } export function locCmp(this: string, compareString: string): number { return this.localeCompare(compareString); } // Add these methods to the String.prototype declare global { interface String { len(): number; str(): string; add(...strings: string[]): string; sb(start: number, end: number): string; ind(substring: string): number; lstInd(substring: string): number; inString(substring: string): boolean; start(substring: string): boolean; end(substring: string): boolean; upr(): string; lwr(): string; trS(): string; trE(): string; rpc(oldSubstring: string, newSubstring: string): string; rpcA(oldSubstring: string, newSubstring: string): string; at(index: number): string; chCdAt(index: number): number; locCmp(compareString: string): number; } } // Add the methods to String.prototype String.prototype.len = len; String.prototype.str = str; String.prototype.add = add; String.prototype.sb = sb; String.prototype.ind = ind; String.prototype.lstInd = lstInd; String.prototype.inString = inString; String.prototype.start = start; String.prototype.end = end; String.prototype.upr = upr; String.prototype.lwr = lwr; String.prototype.trS = trS; String.prototype.trE = trE; String.prototype.rpc = rpc; String.prototype.rpcA = rpcA; String.prototype.at = at; String.prototype.chCdAt = chCdAt; String.prototype.locCmp = locCmp;