UNPKG

4.47 kBJavaScriptView Raw
1((string) => {
2
3 if (!string.lowercaseFirstLetter) {
4 Object.defineProperty(string, 'lowercaseFirstLetter', {
5 enumerable: false,
6 writable: true,
7 configurable: true,
8 value: function () {
9 var string = this;
10 if (string.length > 0) {
11 return string.charAt(0).toLowerCase() + string.slice(1);
12 }
13 return string;
14 }
15 });
16 }
17})(String.prototype);
18
19((array) => {
20
21 if (!array.unique) {
22 Object.defineProperty(array, 'unique', {
23 enumerable: false,
24 writable: true,
25 configurable: true,
26 value: function (func) {
27 var result = [];
28 var finalresult = [];
29 func = func || function (x) { return x; };
30 var collection = this;
31 for (var i = 0; i < collection.length; i++) {
32 //if (func(collection[i])) {
33 if (result.indexOf(func(collection[i])) === -1) {
34 result.push(func(collection[i]));
35 finalresult.push(collection[i]);
36 }
37 //}
38 }
39 return finalresult;
40 //return result;
41 }
42 });
43 }
44 if (!array.interpolate) {
45 Object.defineProperty(array, 'interpolate', {
46 enumerable: false,
47 writable: true,
48 configurable: true,
49 value: function (start, stop, func) {
50 var collection = this;
51 func = func || function (x) { return x; };
52 for (var i = start; i < stop; i++) {
53 if (collection instanceof Float32Array) {
54 collection[i - start] = (func(i));
55 }
56 else
57 collection.push(func(i, i - start));
58 }
59 return collection;
60 }
61 });
62 }
63 if (!array.subset) {
64 Object.defineProperty(array, 'subset', {
65 enumerable: false,
66 writable: true,
67 configurable: true,
68 value: function (start, stop) {
69 var collection = this;
70 stop = Math.min(collection.length, stop === undefined || stop === null ? collection.length : stop);
71 start = Math.min(collection.length, start === undefined || start === null ? collection.length : start);
72 start = start < 0 ? 0 : start;
73 stop = stop < 0 ? 0 : stop;
74 var result = this instanceof Float32Array ? new Float32Array(stop - start) : [];
75 for (var i = start; i < stop; i++) {
76 if (this instanceof Float32Array) {
77 result[i - start] = collection[i];
78 }
79 else {
80 result.push(collection[i]);
81 }
82
83 }
84 return (result);
85 }
86 });
87 }
88 if (!array.last) {
89 Object.defineProperty(array, 'last', {
90 enumerable: false,
91 writable: true,
92 configurable: true,
93 value: function (func) {
94 func = func || function () { return true; };
95 if (typeof (func) !== 'function') {
96 var temp = func;
97 func = function (x) {
98 return temp === x;
99 }
100 }
101 var collection = this;
102 for (var i = collection.length; i--;) {
103 if (func(collection[i])) {
104 var result = (collection[i])
105 return result;
106 }
107 }
108 return null;
109 }
110 });
111 }
112})(Array.prototype);
113
114(function () {
115 if (!String.prototype.pad) {
116 Object.defineProperty(String.prototype, 'pad', {
117 enumerable: false,
118 writable: true,
119 configurable: true,
120 value: function (len, val) {
121 var string = this;
122 if (string.length < len) {
123 for (var i = string.length; i < len; i++) {
124 string = val + string;
125 }
126 }
127 return string;
128 }
129 });
130 }
131})();
132export default {};
\No newline at end of file