UNPKG

3.78 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6const lib_1 = require("./lib");
7const NativeString_1 = __importDefault(require("./NativeString"));
8/** StarkString constructor */
9function starkString(value) {
10 if (typeof value === "number" || typeof value === "string")
11 value = String(value);
12 else if (Array.isArray(value))
13 value = value.join("");
14 else if (value === undefined || value === null)
15 value = "";
16 else
17 throw new Error(`StarkString value must be type of string, number or Array<string|number> instead of ${typeof value}`);
18 return new StarkString(value);
19}
20class StarkString extends NativeString_1.default {
21 constructor(value) {
22 super(value);
23 }
24 /** Returns a copy of a StarkString Object */
25 clone() {
26 return starkString(this._value);
27 }
28 /** Used for set new string */
29 set(value) {
30 this._value = String(value);
31 return this;
32 }
33 /** Used for convert Arabic characters to Persian */
34 persianChar() {
35 this._value = lib_1.persianChar(this.toString());
36 return this;
37 }
38 /** Used for convert any numbers to English */
39 englishNumber() {
40 this._value = lib_1.englishNumber(this._value);
41 return this;
42 }
43 /** Used for convert Arabic numbers to Persian */
44 persianNumber() {
45 this._value = lib_1.persianNumber(this._value);
46 return this;
47 }
48 /** Used for convert English numbers to arabic */
49 arabicNumber() {
50 this._value = lib_1.arabicNumber(this._value);
51 return this;
52 }
53 /**
54 * Used for decode Persian Characters in URL
55 * https://fa.wikipedia.org/wiki/مدیاویکی:Gadget-Extra-Editbuttons-Functions.
56 * s
57 */
58 fixURL() {
59 this._value = lib_1.decodeURL(this._value);
60 return this;
61 }
62 /**
63 * Used for decode Persian Characters in URL
64 * https://fa.wikipedia.org/wiki/مدیاویکی:Gadget-Extra-Editbuttons-Functions.
65 * s
66 */
67 decodeURL() {
68 this._value = lib_1.decodeURL(this._value);
69 return this;
70 }
71 /** Used for Change keyboard layout */
72 switchKey() {
73 this._value = lib_1.switchKey(this._value);
74 return this;
75 }
76 /** Used for get persian words representation of a number */
77 digitsToWords() {
78 this._value = lib_1.digitsToWords(this._value);
79 return this;
80 }
81 /** Used for Zero-width non-joiner correction */
82 halfSpace() {
83 this._value = lib_1.halfSpace(this._value);
84 return this;
85 }
86 /** Return true if value is Integer */
87 isInteger() {
88 return lib_1.isInteger(this._value);
89 }
90 /** Used for validation back card number */
91 isValidBankCard() {
92 return lib_1.isValidBankCard(this._value);
93 }
94 /** Used for convert to price mode */
95 currency() {
96 this._value = lib_1.currency(this._value);
97 return this;
98 }
99 /** Remove anything expect numbers */
100 parseNumber({ max } = {}) {
101 this._value = lib_1.parseNumber(this._value);
102 if (typeof max === "number") {
103 if (Number(this._value) > max) {
104 this._value = String(max);
105 }
106 }
107 return this;
108 }
109 /** Convert any char to star ("*") */
110 security() {
111 this._value = lib_1.security(this._value);
112 return this;
113 }
114 /** Convert to number by native Number function */
115 toNumber() {
116 return Number(this._value);
117 }
118}
119//Expose StarkString
120//CommonJS module is defined
121exports.default = starkString;
122//# sourceMappingURL=index.js.map
\No newline at end of file