puvox-library 1.0.12 → 1.0.13

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/library_standard.js +144 -0
  2. package/package.json +1 -1
@@ -159,6 +159,150 @@ const puvox_library =
159
159
  return this.stringArrayToNumeric(this.stringToArray(arr));
160
160
  },
161
161
 
162
+
163
+
164
+ // region: ####### from CCXT ##########
165
+ keys: Object.keys,
166
+ values: (x) => ((!isArray (x)) ? Object.values (x) : x),
167
+ extend: (...args) => Object.assign ({}, ...args), // NB: side-effect free
168
+ clone:(x) => (isArray (x) ? Array.from (x) : extend (x)),
169
+ index: (x) => new Set (values (x)),
170
+ ordered: (x) => x, // a stub to keep assoc keys in order (in JS it does nothing, it's mostly for Python)
171
+ unique: (x) => Array.from (index (x)),
172
+ arrayConcat: (a, b) => a.concat (b),
173
+ inArray (needle, haystack) {
174
+ return haystack.includes (needle);
175
+ },
176
+ toArray (object) {
177
+ return Object.values (object);
178
+ },
179
+ isEmpty (object) {
180
+ if (!object) {
181
+ return true;
182
+ }
183
+ return (Array.isArray (object) ? object : Object.keys (object)).length < 1;
184
+ },
185
+ keysort (x, out = {}) {
186
+ for (const k of keys (x).sort ()) {
187
+ out[k] = x[k];
188
+ }
189
+ return out;
190
+ },
191
+ indexBy (x, k, out = {}) {
192
+ // description: https://github.com/ccxt/ccxt/blob/master/js/base/functions/generic.js
193
+ for (const v of values (x)) {
194
+ if (k in v) {
195
+ out[v[k]] = v;
196
+ }
197
+ }
198
+
199
+ return out;
200
+ },
201
+ groupBy (x, k, out = {}) {
202
+ // description: https://github.com/ccxt/ccxt/blob/master/js/base/functions/generic.js
203
+ for (const v of values (x)) {
204
+ if (k in v) {
205
+ const p = v[k];
206
+ out[p] = out[p] || [];
207
+ out[p].push (v);
208
+ }
209
+ }
210
+ return out;
211
+ },
212
+ filterBy (x, k, value = undefined, out = []) {
213
+ // description: https://github.com/ccxt/ccxt/blob/master/js/base/functions/generic.js
214
+ for (const v of values (x)) {
215
+ if (v[k] === value) {
216
+ out.push (v);
217
+ }
218
+ }
219
+ return out;
220
+ },
221
+ sortBy: (array, key, descending = false, direction = descending ? -1 : 1) => array.sort ((a, b) => {
222
+ if (a[key] < b[key]) {
223
+ return -direction;
224
+ } else if (a[key] > b[key]) {
225
+ return direction;
226
+ } else {
227
+ return 0;
228
+ }
229
+ }),
230
+ sortBy2: (array, key1, key2, descending = false, direction = descending ? -1 : 1) => array.sort ((a, b) => {
231
+ if (a[key1] < b[key1]) {
232
+ return -direction;
233
+ } else if (a[key1] > b[key1]) {
234
+ return direction;
235
+ } else {
236
+ if (a[key2] < b[key2]) {
237
+ return -direction;
238
+ } else if (a[key2] > b[key2]) {
239
+ return direction;
240
+ } else {
241
+ return 0;
242
+ }
243
+ }
244
+ }),
245
+ flatten: function flatten (x, out = []) {
246
+
247
+ for (const v of x) {
248
+ if (isArray (v)) {
249
+ flatten (v, out);
250
+ } else {
251
+ out.push (v);
252
+ }
253
+ }
254
+
255
+ return out;
256
+ },
257
+ pluck: (x, k) => values (x).filter ((v) => k in v).map ((v) => v[k]),
258
+ omit (x, ...args) {
259
+ if (!Array.isArray (x)) {
260
+
261
+ const out = clone (x);
262
+
263
+ for (const k of args) {
264
+ if (isArray (k)) { // omit (x, ['a', 'b'])
265
+ for (const kk of k) {
266
+ delete out[kk];
267
+ }
268
+ } else {
269
+ delete out[k]; // omit (x, 'a', 'b')
270
+ }
271
+ }
272
+
273
+ return out;
274
+ }
275
+
276
+ return x;
277
+ },
278
+ sum (...xs) {
279
+ const ns = xs.filter (isNumber); // leave only numbers
280
+ return (ns.length > 0) ? ns.reduce ((a, b) => a + b, 0) : undefined;
281
+ },
282
+ deepExtend: function deepExtend (...xs) {
283
+ let out = undefined;
284
+ for (const x of xs) {
285
+ if (isDictionary (x)) {
286
+ if (!isDictionary (out)) {
287
+ out = {};
288
+ }
289
+ for (const k in x) { // eslint-disable-line guard-for-in
290
+ out[k] = deepExtend (out[k], x[k]);
291
+ }
292
+ } else {
293
+ out = x;
294
+ }
295
+ }
296
+ return out;
297
+ },
298
+ // endregion: ####### from CCXT ##########
299
+
300
+
301
+
302
+
303
+
304
+
305
+
162
306
  objectCopy(obj){
163
307
  return JSON.parse(JSON.stringify(obj));
164
308
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "puvox-library",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "description": "library-class-javascript",
5
5
  "main": "library_standard.js",
6
6
  "scripts": {