yet-another-js-utils 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/js-utils.js +16 -16
- package/package.json +1 -1
package/js-utils.js
CHANGED
@@ -13,7 +13,7 @@ const yaju = {
|
|
13
13
|
* @param { boolean } exp
|
14
14
|
* @returns { boolean }
|
15
15
|
*/
|
16
|
-
nil(exp) { // values implicitly considered functions
|
16
|
+
nil: function (exp) { // values implicitly considered functions
|
17
17
|
if (
|
18
18
|
exp === null
|
19
19
|
|| typeof exp === 'undefined'
|
@@ -35,7 +35,7 @@ const yaju = {
|
|
35
35
|
* @param { number } end
|
36
36
|
* @returns
|
37
37
|
*/
|
38
|
-
hack(array, start, end) {
|
38
|
+
hack: function (array, start, end) {
|
39
39
|
return array.slice(start, end + 1);
|
40
40
|
},
|
41
41
|
|
@@ -51,7 +51,7 @@ const yaju = {
|
|
51
51
|
* @param {*} pruningFunction
|
52
52
|
* @returns
|
53
53
|
*/
|
54
|
-
pick(array, pruningFunction) {
|
54
|
+
pick: function (array, pruningFunction) {
|
55
55
|
return array.filter(pruningFunction);
|
56
56
|
},
|
57
57
|
|
@@ -62,7 +62,7 @@ const yaju = {
|
|
62
62
|
* @param {*} filteringFunction
|
63
63
|
* @returns
|
64
64
|
*/
|
65
|
-
prune(array, filteringFunction) {
|
65
|
+
prune: function (array, filteringFunction) {
|
66
66
|
return array.filter(function (x) {
|
67
67
|
return !filteringFunction(x);
|
68
68
|
});
|
@@ -77,7 +77,7 @@ const yaju = {
|
|
77
77
|
* @param {*} checkingFunction
|
78
78
|
* @returns
|
79
79
|
*/
|
80
|
-
check(array, checkingFunction) {
|
80
|
+
check: function (array, checkingFunction) {
|
81
81
|
return array.every(checkingFunction);
|
82
82
|
},
|
83
83
|
|
@@ -86,7 +86,7 @@ const yaju = {
|
|
86
86
|
* @param { string } string
|
87
87
|
* @returns
|
88
88
|
*/
|
89
|
-
escape(string) {
|
89
|
+
escape: function (string) {
|
90
90
|
return string
|
91
91
|
.replace(/&/g, '&')
|
92
92
|
.replace(/</g, '<')
|
@@ -100,7 +100,7 @@ const yaju = {
|
|
100
100
|
* @param {Array} strings
|
101
101
|
* @returns {object} a DocumentFragment
|
102
102
|
*/
|
103
|
-
html(strings) {
|
103
|
+
html: function (strings) {
|
104
104
|
let output = strings[0], // assumes empty string start?
|
105
105
|
max = Math.max(strings.length, arguments.length - 1);
|
106
106
|
for (let i = 1; i < max; i++) {
|
@@ -120,7 +120,7 @@ const yaju = {
|
|
120
120
|
* @param {*} firstNode
|
121
121
|
* @param {*} secondNode
|
122
122
|
*/
|
123
|
-
replaceChildren(firstNode, secondNode) {
|
123
|
+
replaceChildren: function (firstNode, secondNode) {
|
124
124
|
let firstNodeChildren = firstNode.childNodes,
|
125
125
|
secondNodeChildren = secondNode.childNodes;
|
126
126
|
for (let i = 0, c = firstNodeChildren.length; i < c; i++) {
|
@@ -158,7 +158,7 @@ const yaju = {
|
|
158
158
|
* @param { object } element
|
159
159
|
* @param { string } state
|
160
160
|
*/
|
161
|
-
addDataState(element, state) {
|
161
|
+
addDataState: function (element, state) {
|
162
162
|
let stateArray = [];
|
163
163
|
if (
|
164
164
|
element.dataset.state
|
@@ -179,7 +179,7 @@ const yaju = {
|
|
179
179
|
* @param { object } element
|
180
180
|
* @param { string } state
|
181
181
|
*/
|
182
|
-
removeDataState(element, state) {
|
182
|
+
removeDataState: function (element, state) {
|
183
183
|
let stateArray = [];
|
184
184
|
if (
|
185
185
|
element.dataset.state
|
@@ -201,7 +201,7 @@ const yaju = {
|
|
201
201
|
* @param { string } stateToRemove
|
202
202
|
* @param { string } stateToAdd
|
203
203
|
*/
|
204
|
-
replaceDataState(element, stateToRemove, stateToAdd) {
|
204
|
+
replaceDataState: function (element, stateToRemove, stateToAdd) {
|
205
205
|
this.removeDataState(element, stateToRemove);
|
206
206
|
this.addDataState(element, stateToAdd);
|
207
207
|
},
|
@@ -211,7 +211,7 @@ const yaju = {
|
|
211
211
|
* @param { object } element
|
212
212
|
* @param { string } state
|
213
213
|
*/
|
214
|
-
toggleDataState(element, state) {
|
214
|
+
toggleDataState: function (element, state) {
|
215
215
|
let stateArray = element.dataset.state.split(' ');
|
216
216
|
if (stateArray.indexOf(state) == -1) {
|
217
217
|
this.addDataState(element, state);
|
@@ -229,7 +229,7 @@ const yaju = {
|
|
229
229
|
* @param {boolean} isJson Response contains json
|
230
230
|
* @param {object} callbackContext
|
231
231
|
*/
|
232
|
-
ajaxGet(url, callback, isJson, callbackContext) {
|
232
|
+
ajaxGet: function (url, callback, isJson, callbackContext) {
|
233
233
|
var req = new XMLHttpRequest();
|
234
234
|
req.open("GET", url);
|
235
235
|
req.addEventListener("load", function () {
|
@@ -265,7 +265,7 @@ const yaju = {
|
|
265
265
|
* @param {object} successCallbackContext
|
266
266
|
* @param {object} failureCallbackContext
|
267
267
|
*/
|
268
|
-
ajaxPost(url, data, successCallback, failureCallback, isJson, successCallbackContext, failureCallbackContext) {
|
268
|
+
ajaxPost: function (url, data, successCallback, failureCallback, isJson, successCallbackContext, failureCallbackContext) {
|
269
269
|
var req = new XMLHttpRequest();
|
270
270
|
req.open("POST", url);
|
271
271
|
req.addEventListener("load", function () {
|
@@ -293,9 +293,9 @@ const yaju = {
|
|
293
293
|
* @param {*} input
|
294
294
|
* @returns {*}
|
295
295
|
*/
|
296
|
-
pipe(input, ...functions) {
|
296
|
+
pipe: function (input, ...functions) {
|
297
297
|
return functions.reduce((res, fun) => fun(res), input);
|
298
298
|
}
|
299
299
|
}
|
300
300
|
|
301
|
-
module.exports = yaju;
|
301
|
+
module.exports = {...yaju};
|
package/package.json
CHANGED