yet-another-js-utils 0.0.2 → 0.0.4

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.
Files changed (2) hide show
  1. package/js-utils.js +18 -18
  2. package/package.json +1 -1
package/js-utils.js CHANGED
@@ -1,5 +1,4 @@
1
- module.exports =
2
- (function () { return {
1
+ const yaju = {
3
2
  // # Nil
4
3
 
5
4
  // I like the NOT operator
@@ -14,7 +13,7 @@ module.exports =
14
13
  * @param { boolean } exp
15
14
  * @returns { boolean }
16
15
  */
17
- nil(exp) { // values implicitly considered functions
16
+ nil: function (exp) { // values implicitly considered functions
18
17
  if (
19
18
  exp === null
20
19
  || typeof exp === 'undefined'
@@ -36,7 +35,7 @@ module.exports =
36
35
  * @param { number } end
37
36
  * @returns
38
37
  */
39
- hack(array, start, end) {
38
+ hack: function (array, start, end) {
40
39
  return array.slice(start, end + 1);
41
40
  },
42
41
 
@@ -52,7 +51,7 @@ module.exports =
52
51
  * @param {*} pruningFunction
53
52
  * @returns
54
53
  */
55
- pick(array, pruningFunction) {
54
+ pick: function (array, pruningFunction) {
56
55
  return array.filter(pruningFunction);
57
56
  },
58
57
 
@@ -63,7 +62,7 @@ module.exports =
63
62
  * @param {*} filteringFunction
64
63
  * @returns
65
64
  */
66
- prune(array, filteringFunction) {
65
+ prune: function (array, filteringFunction) {
67
66
  return array.filter(function (x) {
68
67
  return !filteringFunction(x);
69
68
  });
@@ -78,7 +77,7 @@ module.exports =
78
77
  * @param {*} checkingFunction
79
78
  * @returns
80
79
  */
81
- check(array, checkingFunction) {
80
+ check: function (array, checkingFunction) {
82
81
  return array.every(checkingFunction);
83
82
  },
84
83
 
@@ -87,7 +86,7 @@ module.exports =
87
86
  * @param { string } string
88
87
  * @returns
89
88
  */
90
- escape(string) {
89
+ escape: function (string) {
91
90
  return string
92
91
  .replace(/&/g, '&')
93
92
  .replace(/</g, '&lt;')
@@ -101,7 +100,7 @@ module.exports =
101
100
  * @param {Array} strings
102
101
  * @returns {object} a DocumentFragment
103
102
  */
104
- html(strings) {
103
+ html: function (strings) {
105
104
  let output = strings[0], // assumes empty string start?
106
105
  max = Math.max(strings.length, arguments.length - 1);
107
106
  for (let i = 1; i < max; i++) {
@@ -121,7 +120,7 @@ module.exports =
121
120
  * @param {*} firstNode
122
121
  * @param {*} secondNode
123
122
  */
124
- replaceChildren(firstNode, secondNode) {
123
+ replaceChildren: function (firstNode, secondNode) {
125
124
  let firstNodeChildren = firstNode.childNodes,
126
125
  secondNodeChildren = secondNode.childNodes;
127
126
  for (let i = 0, c = firstNodeChildren.length; i < c; i++) {
@@ -159,7 +158,7 @@ module.exports =
159
158
  * @param { object } element
160
159
  * @param { string } state
161
160
  */
162
- addDataState(element, state) {
161
+ addDataState: function (element, state) {
163
162
  let stateArray = [];
164
163
  if (
165
164
  element.dataset.state
@@ -180,7 +179,7 @@ module.exports =
180
179
  * @param { object } element
181
180
  * @param { string } state
182
181
  */
183
- removeDataState(element, state) {
182
+ removeDataState: function (element, state) {
184
183
  let stateArray = [];
185
184
  if (
186
185
  element.dataset.state
@@ -202,7 +201,7 @@ module.exports =
202
201
  * @param { string } stateToRemove
203
202
  * @param { string } stateToAdd
204
203
  */
205
- replaceDataState(element, stateToRemove, stateToAdd) {
204
+ replaceDataState: function (element, stateToRemove, stateToAdd) {
206
205
  this.removeDataState(element, stateToRemove);
207
206
  this.addDataState(element, stateToAdd);
208
207
  },
@@ -212,7 +211,7 @@ module.exports =
212
211
  * @param { object } element
213
212
  * @param { string } state
214
213
  */
215
- toggleDataState(element, state) {
214
+ toggleDataState: function (element, state) {
216
215
  let stateArray = element.dataset.state.split(' ');
217
216
  if (stateArray.indexOf(state) == -1) {
218
217
  this.addDataState(element, state);
@@ -230,7 +229,7 @@ module.exports =
230
229
  * @param {boolean} isJson Response contains json
231
230
  * @param {object} callbackContext
232
231
  */
233
- ajaxGet(url, callback, isJson, callbackContext) {
232
+ ajaxGet: function (url, callback, isJson, callbackContext) {
234
233
  var req = new XMLHttpRequest();
235
234
  req.open("GET", url);
236
235
  req.addEventListener("load", function () {
@@ -266,7 +265,7 @@ module.exports =
266
265
  * @param {object} successCallbackContext
267
266
  * @param {object} failureCallbackContext
268
267
  */
269
- ajaxPost(url, data, successCallback, failureCallback, isJson, successCallbackContext, failureCallbackContext) {
268
+ ajaxPost: function (url, data, successCallback, failureCallback, isJson, successCallbackContext, failureCallbackContext) {
270
269
  var req = new XMLHttpRequest();
271
270
  req.open("POST", url);
272
271
  req.addEventListener("load", function () {
@@ -294,8 +293,9 @@ module.exports =
294
293
  * @param {*} input
295
294
  * @returns {*}
296
295
  */
297
- pipe(input, ...functions) {
296
+ pipe: function (input, ...functions) {
298
297
  return functions.reduce((res, fun) => fun(res), input);
299
298
  }
300
299
  }
301
- });
300
+
301
+ module.exports = yaju;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "yet-another-js-utils",
3
3
  "description": "Basic javascript utils",
4
4
  "authors": "Adrian Turcev",
5
- "version": "0.0.2",
5
+ "version": "0.0.4",
6
6
  "license": "MPL-2.0",
7
7
  "homepage": "https://github.com/adrianturcev/js-utils",
8
8
  "repository": {