1 | ;
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | class NativeString {
|
4 | constructor(value) {
|
5 | this._value = "";
|
6 | this._value = value;
|
7 | }
|
8 | /**
|
9 | * Returns the character at the specified index.
|
10 | *
|
11 | * @param {number} pos The zero-based index of the desired character.
|
12 | */
|
13 | charAt(pos) {
|
14 | this._value = this._value.charAt(pos);
|
15 | return this;
|
16 | }
|
17 | /**
|
18 | * Returns the Unicode value of the character at the specified location.
|
19 | *
|
20 | * @param {number} index The zero-based index of the desired character. If there
|
21 | * is no character at the specified index, NaN is returned.
|
22 | */
|
23 | charCodeAt(index) {
|
24 | return this._value.charCodeAt(index);
|
25 | }
|
26 | /**
|
27 | * Returns a nonnegative integer Number less than 1114112 (0x110000) that is the
|
28 | * code point value of the UTF-16 encoded code point starting at the string
|
29 | * element at position pos in the String resulting from converting this object to
|
30 | * a String. If there is no element at that position, the result is undefined. If
|
31 | * a valid UTF-16 surrogate pair does not begin at pos, the result is the code
|
32 | * unit at pos.
|
33 | *
|
34 | * @param {number} pos
|
35 | */
|
36 | codePointAt(pos) {
|
37 | return this._value.codePointAt(pos);
|
38 | }
|
39 | /**
|
40 | * Returns a string that contains the concatenation of two or more strings.
|
41 | *
|
42 | * @param {string[]} strings The strings to append to the end of the string.
|
43 | */
|
44 | concat(...strings) {
|
45 | this._value = this._value.concat(...strings);
|
46 | return this;
|
47 | }
|
48 | /**
|
49 | * Returns true if the sequence of elements of searchString converted to a String
|
50 | * is the same as the corresponding elements of this object (converted to a
|
51 | * String) starting at endPosition – length(this). Otherwise returns false.
|
52 | *
|
53 | * @param {string} searchString
|
54 | * @param {number} [endPosition]
|
55 | */
|
56 | endsWith(searchString, endPosition) {
|
57 | return this._value.endsWith(searchString, endPosition);
|
58 | }
|
59 | /**
|
60 | * Returns true if searchString appears as a substring of the result of converting
|
61 | * this object to a String, at one or more positions that are greater than or
|
62 | * equal to position; otherwise, returns false.
|
63 | *
|
64 | * @param {string} searchString Search string
|
65 | * @param {number} [position] If position is undefined, 0 is assumed, so as to
|
66 | * search all of the String.
|
67 | */
|
68 | includes(searchString, position) {
|
69 | return this._value.includes(searchString, position);
|
70 | }
|
71 | /**
|
72 | * Returns the position of the first occurrence of a substring.
|
73 | *
|
74 | * @param {string} searchString The substring to search for in the string
|
75 | * @param {number} [position] The index at which to begin searching the String
|
76 | * object. If omitted, search starts at the beginning of the string.
|
77 | */
|
78 | indexOf(searchString, position) {
|
79 | return this._value.indexOf(searchString, position);
|
80 | }
|
81 | /**
|
82 | * Returns the last occurrence of a substring in the string.
|
83 | *
|
84 | * @param {string} searchString The substring to search for.
|
85 | * @param {number} [position] The index at which to begin searching. If omitted,
|
86 | * the search begins at the end of the string.
|
87 | */
|
88 | lastIndexOf(searchString, position) {
|
89 | return this._value.lastIndexOf(searchString, position);
|
90 | }
|
91 | /** Returns the length of a String object. */
|
92 | get length() {
|
93 | return this._value.length;
|
94 | }
|
95 | /**
|
96 | * Determines whether two strings are equivalent in the current locale.
|
97 | *
|
98 | * @param {string} value String to compare to target string
|
99 | * @returns {number}
|
100 | */
|
101 | localeCompare(value) {
|
102 | return this._value.localeCompare(value);
|
103 | }
|
104 | /**
|
105 | * Matches a string an object that supports being matched against, and returns an
|
106 | * array containing the results of that search.
|
107 | *
|
108 | * @param {{ [Symbol.match](string: string): RegExpMatchArray | null }} matcher An
|
109 | * object that supports being matched against.
|
110 | * @returns {RegExpMatchArray | null}
|
111 | */
|
112 | match(matcher) {
|
113 | return this._value.match(matcher);
|
114 | }
|
115 | /**
|
116 | * Returns the String value result of normalizing the string into the
|
117 | * normalization form named by form as specified in Unicode Standard Annex #15,
|
118 | * Unicode Normalization Forms.
|
119 | *
|
120 | * @param {"NFC" | "NFD" | "NFKC" | "NFKD"} form Applicable values: "NFC", "NFD",
|
121 | * "NFKC", or "NFKD", If not specified default is "NFC"
|
122 | */
|
123 | normalize(form) {
|
124 | this._value = this._value.normalize(form);
|
125 | return this;
|
126 | }
|
127 | /**
|
128 | * Pads the current string with a given string (possibly repeated) so that the
|
129 | * resulting string reaches a given length. The padding is applied from the end
|
130 | * (right) of the current string.
|
131 | *
|
132 | * @param {number} maxLength The length of the resulting string once the current
|
133 | * string has been padded. If this parameter is smaller than the current
|
134 | * string's length, the current string will be returned as it is.
|
135 | * @param {string} [fillString] The string to pad the current string with. If this
|
136 | * string is too long, it will be truncated and the left-most part will be
|
137 | * applied. The default value for this parameter is " " (U+0020).
|
138 | */
|
139 | padEnd(maxLength, fillString) {
|
140 | this._value = this._value.padEnd(maxLength, fillString);
|
141 | return this;
|
142 | }
|
143 | /**
|
144 | * Pads the current string with a given string (possibly repeated) so that the
|
145 | * resulting string reaches a given length. The padding is applied from the start
|
146 | * (left) of the current string.
|
147 | *
|
148 | * @param {number} maxLength The length of the resulting string once the current
|
149 | * string has been padded. If this parameter is smaller than the current
|
150 | * string's length, the current string will be returned as it is.
|
151 | * @param {string} [fillString] The string to pad the current string with. If this
|
152 | * string is too long, it will be truncated and the left-most part will be
|
153 | * applied. The default value for this parameter is " " (U+0020).
|
154 | */
|
155 | padStart(maxLength, fillString) {
|
156 | this._value = this._value.padStart(maxLength, fillString);
|
157 | return this;
|
158 | }
|
159 | /**
|
160 | * Returns a String value that is made from count copies appended together. If
|
161 | * count is 0, the empty string is returned.
|
162 | *
|
163 | * @param {number} count Number of copies to append
|
164 | */
|
165 | repeat(count) {
|
166 | this._value = this._value.repeat(count);
|
167 | return this;
|
168 | }
|
169 | /**
|
170 | * Replaces text in a string, using a regular expression or search string.
|
171 | *
|
172 | * @param {string | RegExp} searchValue A string to search for.
|
173 | * @param {string} replaceValue A string containing the text to replace for every
|
174 | * successful match of searchValue in this string.
|
175 | */
|
176 | replace(searchValue, replaceValue) {
|
177 | this._value = this._value.replace(searchValue, replaceValue);
|
178 | return this;
|
179 | }
|
180 | /**
|
181 | * Finds the first substring match in a regular expression search.
|
182 | *
|
183 | * @param {string | RegExp} regexp The regular expression pattern and applicable
|
184 | * flags.
|
185 | * @returns {number}
|
186 | */
|
187 | search(regexp) {
|
188 | return this._value.search(regexp);
|
189 | }
|
190 | /**
|
191 | * Returns a section of a string.
|
192 | *
|
193 | * @param {number} [start] The index to the beginning of the specified portion of
|
194 | * stringObj.
|
195 | * @param {number} [end] The index to the end of the specified portion of
|
196 | * stringObj. The substring includes the characters up to, but not including,
|
197 | * the character indicated by end. If this value is not specified, the
|
198 | * substring continues to the end of stringObj.
|
199 | */
|
200 | slice(start, end) {
|
201 | this._value = this._value.slice(start, end);
|
202 | return this;
|
203 | }
|
204 | /**
|
205 | * Split a string into substrings using the specified separator and return them as
|
206 | * an array.
|
207 | *
|
208 | * @param {string | RegExp} separator A string that identifies character or
|
209 | * characters to use in separating the string. If omitted, a single-element
|
210 | * array containing the entire string is returned.
|
211 | * @param {number} [limit] A value used to limit the number of elements returned
|
212 | * in the array.
|
213 | * @returns {string[]}
|
214 | */
|
215 | split(separator, limit) {
|
216 | return this._value.split(separator, limit);
|
217 | }
|
218 | // IE extensions
|
219 | /**
|
220 | * Gets a substring beginning at the specified location and having the specified
|
221 | * length.
|
222 | *
|
223 | * @param {number} from The starting position of the desired substring. The index
|
224 | * of the first character in the string is zero.
|
225 | * @param {number} [length] The number of characters to include in the returned
|
226 | * substring.
|
227 | */
|
228 | substr(from, length) {
|
229 | this._value = this._value.substr(from, length);
|
230 | return this;
|
231 | }
|
232 | /**
|
233 | * Returns the substring at the specified location within a String object.
|
234 | *
|
235 | * @param {number} start The zero-based index number indicating the beginning of
|
236 | * the substring.
|
237 | * @param {number} [end] Zero-based index number indicating the end of the
|
238 | * substring. The substring includes the characters up to, but not including,
|
239 | * the character indicated by end. If end is omitted, the characters from
|
240 | * start through the end of the original string are returned.
|
241 | */
|
242 | substring(start, end) {
|
243 | this._value = this._value.substring(start, end);
|
244 | return this;
|
245 | }
|
246 | /**
|
247 | * Returns true if the sequence of elements of searchString converted to a String
|
248 | * is the same as the corresponding elements of this object (converted to a
|
249 | * String) starting at position. Otherwise returns false.
|
250 | *
|
251 | * @param {string} searchString
|
252 | * @param {number} [position]
|
253 | * @returns {boolean}
|
254 | */
|
255 | startsWith(searchString, position) {
|
256 | return this._value.startsWith(searchString, position);
|
257 | }
|
258 | /** Converts all the alphabetic characters in a string to lowercase. */
|
259 | toLowerCase() {
|
260 | this._value = this._value.toLowerCase();
|
261 | return this;
|
262 | }
|
263 | /**
|
264 | * Converts all alphabetic characters to lowercase, taking into account the host
|
265 | * environment's current locale.
|
266 | */
|
267 | toLocaleLowerCase() {
|
268 | this._value = this._value.toLocaleLowerCase();
|
269 | return this;
|
270 | }
|
271 | /** Converts all the alphabetic characters in a string to uppercase. */
|
272 | toUpperCase() {
|
273 | this._value = this._value.toUpperCase();
|
274 | return this;
|
275 | }
|
276 | /**
|
277 | * Returns a string where all alphabetic characters have been converted to
|
278 | * uppercase, taking into account the host environment's current locale.
|
279 | */
|
280 | toLocaleUpperCase() {
|
281 | this._value = this._value.toLocaleUpperCase();
|
282 | return this;
|
283 | }
|
284 | /**
|
285 | * Returns a string representation of a StarkStringType & NativeString Object
|
286 | *
|
287 | * @returns {string}
|
288 | */
|
289 | toString() {
|
290 | return this._value.toString();
|
291 | }
|
292 | /**
|
293 | * Removes the leading and trailing white space and line terminator characters
|
294 | * from a string.
|
295 | */
|
296 | trim() {
|
297 | this._value = this._value.trim();
|
298 | return this;
|
299 | }
|
300 | /** Removes whitespace from the left end of a string. */
|
301 | trimLeft() {
|
302 | this._value = this._value.trimLeft();
|
303 | return this;
|
304 | }
|
305 | /** Removes whitespace from the right end of a string. */
|
306 | trimRight() {
|
307 | this._value = this._value.trimRight();
|
308 | return this;
|
309 | }
|
310 | /** Returns the primitive value of the specified object. */
|
311 | valueOf() {
|
312 | return this._value.valueOf();
|
313 | }
|
314 | }
|
315 | exports.default = NativeString;
|
316 | //# sourceMappingURL=NativeString.js.map |
\ | No newline at end of file |