|
13 | 13 | * ========================================================================== |
14 | 14 | */ |
15 | 15 | import { ArrayType1D } from "../shared/types"; |
| 16 | +import Utils from "../shared/utils" |
16 | 17 | import Series from "./series"; |
17 | 18 |
|
| 19 | +const utils = new Utils(); |
18 | 20 | /** |
19 | 21 | * Exposes numerous String methods. All methods are applied Element-wise |
20 | 22 | */ |
@@ -45,7 +47,7 @@ export default class Str { |
45 | 47 | const { inplace } = { inplace: false, ...options } |
46 | 48 | const newArr: Array<string | number> = []; |
47 | 49 | this.values.map((val) => { |
48 | | - if (isNaN(val as number) && typeof val != "string") { |
| 50 | + if (utils.isEmpty(val)) { |
49 | 51 | newArr.push(NaN); |
50 | 52 | } else { |
51 | 53 | newArr.push(`${val}`.toLowerCase()); |
@@ -82,7 +84,7 @@ export default class Str { |
82 | 84 | const { inplace } = { inplace: false, ...options } |
83 | 85 | const newArr: Array<string | number> = []; |
84 | 86 | this.values.map((val) => { |
85 | | - if (isNaN(val as number) && typeof val != "string") { |
| 87 | + if (utils.isEmpty(val)) { |
86 | 88 | newArr.push(NaN); |
87 | 89 | } else { |
88 | 90 | newArr.push(`${val}`.toUpperCase()); |
@@ -118,7 +120,7 @@ export default class Str { |
118 | 120 | const { inplace } = { inplace: false, ...options } |
119 | 121 | const newArr: Array<string | number> = []; |
120 | 122 | this.values.map((val) => { |
121 | | - if (isNaN(val as number) && typeof val != "string") { |
| 123 | + if (utils.isEmpty(val)) { |
122 | 124 | newArr.push(NaN); |
123 | 125 | } else { |
124 | 126 | let firstChar = `${val}`.slice(0, 1); |
@@ -159,7 +161,7 @@ export default class Str { |
159 | 161 | const { inplace } = { inplace: false, ...options } |
160 | 162 | const newArr: Array<string | number> = []; |
161 | 163 | this.values.map((val) => { |
162 | | - if (isNaN(val as number) && typeof val != "string") { |
| 164 | + if (utils.isEmpty(val)) { |
163 | 165 | newArr.push(NaN); |
164 | 166 | } else { |
165 | 167 | newArr.push(`${val}`.charAt(index)); |
@@ -209,14 +211,14 @@ export default class Str { |
209 | 211 | } else { |
210 | 212 | this.values.map((val) => { |
211 | 213 | if (position == 1) { |
212 | | - if (isNaN(val as number) && typeof val != "string") { |
| 214 | + if (utils.isEmpty(val)) { |
213 | 215 | newArr.push(NaN); |
214 | 216 | } else { |
215 | 217 | newArr.push(`${val}`.concat(`${other}`)); |
216 | 218 | } |
217 | 219 |
|
218 | 220 | } else { |
219 | | - if (isNaN(val as number) && typeof val != "string") { |
| 221 | + if (utils.isEmpty(val)) { |
220 | 222 | newArr.push(NaN); |
221 | 223 | } else { |
222 | 224 | newArr.push(other.concat(`${val}`)); |
@@ -256,7 +258,7 @@ export default class Str { |
256 | 258 | const { inplace } = { inplace: false, ...options } |
257 | 259 | const newArr: Array<boolean | number> = []; |
258 | 260 | this.values.forEach((val) => { |
259 | | - if (isNaN(val as number) && typeof val != "string") { |
| 261 | + if (utils.isEmpty(val)) { |
260 | 262 | newArr.push(NaN); |
261 | 263 | } else { |
262 | 264 | newArr.push(`${val}`.startsWith(str)); |
@@ -291,7 +293,7 @@ export default class Str { |
291 | 293 | const { inplace } = { inplace: false, ...options } |
292 | 294 | const newArr: Array<boolean | number> = []; |
293 | 295 | this.values.map((val) => { |
294 | | - if (isNaN(val as number) && typeof val != "string") { |
| 296 | + if (utils.isEmpty(val)) { |
295 | 297 | newArr.push(NaN); |
296 | 298 | } else { |
297 | 299 | newArr.push(`${val}`.endsWith(str)); |
@@ -326,7 +328,7 @@ export default class Str { |
326 | 328 | const { inplace } = { inplace: false, ...options } |
327 | 329 | const newArr: Array<boolean | number> = []; |
328 | 330 | this.values.map((val) => { |
329 | | - if (isNaN(val as number) && typeof val != "string") { |
| 331 | + if (utils.isEmpty(val)) { |
330 | 332 | newArr.push(NaN); |
331 | 333 | } else { |
332 | 334 | newArr.push(`${val}`.includes(str)); |
@@ -361,7 +363,7 @@ export default class Str { |
361 | 363 | const { inplace } = { inplace: false, ...options } |
362 | 364 | const newArr: Array<number> = []; |
363 | 365 | this.values.map((val) => { |
364 | | - if (isNaN(val as number) && typeof val != "string") { |
| 366 | + if (utils.isEmpty(val)) { |
365 | 367 | newArr.push(NaN); |
366 | 368 | } else { |
367 | 369 | newArr.push(`${val}`.indexOf(str)); |
@@ -396,7 +398,7 @@ export default class Str { |
396 | 398 | const { inplace } = { inplace: false, ...options } |
397 | 399 | const newArr: Array<string | number> = []; |
398 | 400 | this.values.map((val) => { |
399 | | - if (isNaN(val as number) && typeof val != "string") { |
| 401 | + if (utils.isEmpty(val)) { |
400 | 402 | newArr.push(NaN); |
401 | 403 | } else { |
402 | 404 | newArr.push(`${val}`.lastIndexOf(str)); |
@@ -433,7 +435,7 @@ export default class Str { |
433 | 435 | const { inplace } = { inplace: false, ...options } |
434 | 436 | const newArr: Array<string | number> = []; |
435 | 437 | this.values.map((val) => { |
436 | | - if (isNaN(val as number) && typeof val != "string") { |
| 438 | + if (utils.isEmpty(val)) { |
437 | 439 | newArr.push(NaN); |
438 | 440 | } else { |
439 | 441 | newArr.push(`${val}`.replace(searchValue, replaceValue)); |
@@ -468,7 +470,7 @@ export default class Str { |
468 | 470 | const { inplace } = { inplace: false, ...options } |
469 | 471 | const newArr: Array<string | number> = []; |
470 | 472 | this.values.map((val) => { |
471 | | - if (isNaN(val as number) && typeof val != "string") { |
| 473 | + if (utils.isEmpty(val)) { |
472 | 474 | newArr.push(NaN); |
473 | 475 | } else { |
474 | 476 | newArr.push(`${val}`.repeat(num)); |
@@ -503,7 +505,7 @@ export default class Str { |
503 | 505 | const { inplace } = { inplace: false, ...options } |
504 | 506 | const newArr: Array<string | number> = []; |
505 | 507 | this.values.map((val) => { |
506 | | - if (isNaN(val as number) && typeof val != "string") { |
| 508 | + if (utils.isEmpty(val)) { |
507 | 509 | newArr.push(NaN); |
508 | 510 | } else { |
509 | 511 | newArr.push(`${val}`.search(str)); |
@@ -539,7 +541,7 @@ export default class Str { |
539 | 541 | const { inplace } = { inplace: false, ...options } |
540 | 542 | const newArr: Array<string | number> = []; |
541 | 543 | this.values.map((val) => { |
542 | | - if (isNaN(val as number) && typeof val != "string") { |
| 544 | + if (utils.isEmpty(val)) { |
543 | 545 | newArr.push(NaN); |
544 | 546 | } else { |
545 | 547 | newArr.push(`${val}`.slice(startIndex, endIndex)); |
@@ -573,7 +575,7 @@ export default class Str { |
573 | 575 | const { inplace } = { inplace: false, ...options } |
574 | 576 | const newArr: Array<string | number> = []; |
575 | 577 | this.values.map((val) => { |
576 | | - if (isNaN(val as number) && typeof val != "string") { |
| 578 | + if (utils.isEmpty(val)) { |
577 | 579 | newArr.push(NaN); |
578 | 580 | } else { |
579 | 581 | newArr.push(`${String(val).split(splitVal)}`); |
@@ -607,7 +609,7 @@ export default class Str { |
607 | 609 | const { inplace } = { inplace: false, ...options } |
608 | 610 | const newArr: Array<string | number> = []; |
609 | 611 | this.values.map((val) => { |
610 | | - if (isNaN(val as number) && typeof val != "string") { |
| 612 | + if (utils.isEmpty(val)) { |
611 | 613 | newArr.push(NaN); |
612 | 614 | } else { |
613 | 615 | newArr.push(`${String(val).substr(startIndex, num)}`); |
@@ -641,7 +643,7 @@ export default class Str { |
641 | 643 | const { inplace } = { inplace: false, ...options } |
642 | 644 | const newArr: Array<string | number> = []; |
643 | 645 | this.values.map((val) => { |
644 | | - if (isNaN(val as number) && typeof val != "string") { |
| 646 | + if (utils.isEmpty(val)) { |
645 | 647 | newArr.push(NaN); |
646 | 648 | } else { |
647 | 649 | newArr.push(`${String(val).substring(startIndex, endIndex)}`); |
@@ -674,7 +676,7 @@ export default class Str { |
674 | 676 | const { inplace } = { inplace: false, ...options } |
675 | 677 | const newArr: Array<string | number> = []; |
676 | 678 | this.values.map((val) => { |
677 | | - if (isNaN(val as number) && typeof val != "string") { |
| 679 | + if (utils.isEmpty(val)) { |
678 | 680 | newArr.push(NaN); |
679 | 681 | } else { |
680 | 682 | newArr.push(`${val}`.trim()); |
@@ -709,7 +711,7 @@ export default class Str { |
709 | 711 | const { inplace } = { inplace: false, ...options } |
710 | 712 | const newArr: Array<string | number> = []; |
711 | 713 | this.values.map((val) => { |
712 | | - if (isNaN(val as number) && typeof val != "string") { |
| 714 | + if (utils.isEmpty(val)) { |
713 | 715 | newArr.push(NaN); |
714 | 716 | } else { |
715 | 717 | let leftChar = val; |
@@ -745,7 +747,7 @@ export default class Str { |
745 | 747 | const { inplace } = { inplace: false, ...options } |
746 | 748 | const newArr: Array<string | number> = []; |
747 | 749 | this.values.map((val) => { |
748 | | - if (isNaN(val as number) && typeof val != "string") { |
| 750 | + if (utils.isEmpty(val)) { |
749 | 751 | newArr.push(NaN); |
750 | 752 | } else { |
751 | 753 | newArr.push(`${val}`.length); |
|
0 commit comments