-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpolyfills.ts
81 lines (71 loc) · 2.49 KB
/
polyfills.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* @nevware21/ts-utils
* /~https://github.com/nevware21/ts-utils
*
* Copyright (c) 2022 NevWare21 Solutions LLC
* Licensed under the MIT license.
*/
import { arrForEach } from "./array/forEach";
import { ArrCls, ArrProto, ObjClass, StrProto } from "./internal/constants";
import { polyIsArray, polyArrIncludes, polyArrFind, polyArrFindIndex, polyArrFindLastIndex, polyArrFindLast, polyArrFrom } from "./polyfills/array";
import { polyObjKeys } from "./polyfills/object";
import { polyStrStartsWith } from "./string/starts_with";
import { polyStrEndsWith } from "./string/ends_with";
import { polyStrTrim, polyStrTrimEnd, polyStrTrimStart } from "./polyfills/trim";
import { polyStrPadEnd, polyStrPadStart } from "./string/pad";
import { makePolyFn } from "./internal/poly_helpers";
import { polyObjHasOwn } from "./object/has_own";
import { polyStrSubstr } from "./string/substring";
import { polyStrIncludes } from "./string/includes";
(function () {
const objectPolyfills = {
"keys": polyObjKeys,
"hasOwn": polyObjHasOwn
};
const stringPolyfills = {
"startsWith" : polyStrStartsWith,
"endsWith": polyStrEndsWith,
"padStart": polyStrPadStart,
"padEnd": polyStrPadEnd,
"trim": polyStrTrim,
"trimStart": polyStrTrimStart,
"trimLeft": polyStrTrimStart,
"trimEnd": polyStrTrimEnd,
"trimRight": polyStrTrimEnd,
"substr": polyStrSubstr,
"includes": polyStrIncludes
};
const arrayClsPolyfills = {
"isArray": polyIsArray,
"from": polyArrFrom
};
const arrayPolyfills = {
"includes": polyArrIncludes,
"find": polyArrFind,
"findIndex": polyArrFindIndex,
"findLast": polyArrFindLast,
"findLastIndex": polyArrFindLastIndex
};
// Add Object polyfills
arrForEach(polyObjKeys(objectPolyfills), (key) => {
if (!ObjClass[key]) {
ObjClass[key] = makePolyFn(objectPolyfills[key]);
}
});
arrForEach(polyObjKeys(arrayClsPolyfills), (key) => {
if (!ArrCls[key]) {
ArrCls[key] = makePolyFn(arrayClsPolyfills[key]);
}
});
// Add Array polyfills
arrForEach(polyObjKeys(arrayPolyfills), (key) => {
if (!ArrProto[key]) {
ArrProto[key] = makePolyFn(arrayPolyfills[key]);
}
});
arrForEach(polyObjKeys(stringPolyfills), (key) => {
if (!StrProto[key]) {
StrProto[key] = makePolyFn(stringPolyfills[key]);
}
});
})();