ig-types 6.15.6 → 6.16.0

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/Array.js CHANGED
@@ -12,6 +12,7 @@
12
12
  /*********************************************************************/
13
13
 
14
14
  var object = require('ig-object')
15
+ var stoppable = require('ig-stoppable')
15
16
 
16
17
  var generator = require('./generator')
17
18
 
@@ -22,11 +23,7 @@ var generator = require('./generator')
22
23
  // NOTE: this is used in a similar fashion to Python's StopIteration...
23
24
  var STOP =
24
25
  module.STOP =
25
- object.STOP
26
-
27
- var stoppable =
28
- module.stoppable =
29
- generator.stoppable
26
+ stoppable.STOP
30
27
 
31
28
 
32
29
  //---------------------------------------------------------------------
@@ -215,9 +212,12 @@ object.Mixin('ArrayMixin', 'soft', {
215
212
  // done...
216
213
  : [] },
217
214
 
218
- // XXX add handler function support -- a-la generator.js'
219
- iter: function*(lst=[]){
220
- yield* lst.iter() },
215
+ // XXX not sure about the handler API here yet...
216
+ iter: function*(lst=[], handler=undefined){
217
+ yield* lst.iter(
218
+ ...(handler ?
219
+ [handler]
220
+ : [])) },
221
221
  })
222
222
 
223
223
 
package/Function.js ADDED
@@ -0,0 +1,18 @@
1
+ /**********************************************************************
2
+ *
3
+ *
4
+ *
5
+ **********************************************/ /* c8 ignore next 2 */
6
+ ((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define)
7
+ (function(require){ var module={} // make module AMD/node compatible...
8
+ /*********************************************************************/
9
+
10
+
11
+ var AsyncFunction =
12
+ module.AsyncFunction =
13
+ (async function(){}).constructor
14
+
15
+
16
+
17
+ /**********************************************************************
18
+ * vim:set ts=4 sw=4 : */ return module })
package/Promise.js CHANGED
@@ -464,6 +464,11 @@ object.Constructor('IterablePromise', Promise, {
464
464
  every: promiseProxy('every'),
465
465
 
466
466
 
467
+ join: async function(){
468
+ return [...(await this)]
469
+ .join(...arguments) },
470
+
471
+
467
472
  // this is defined globally as Promise.prototype.iter(..)
468
473
  //
469
474
  // for details see: PromiseMixin(..) below...
package/README.md CHANGED
@@ -13,6 +13,8 @@ Library of JavaScript type extensions, types and utilities.
13
13
  - [`Object.matchPartial(..)`](#objectmatchpartial)
14
14
  - [`<object>.run(..)`](#objectrun)
15
15
  - [`Object.sort(..)`](#objectsort)
16
+ - [`Function`](#function)
17
+ - [`func.AsyncFunction`](#funcasyncfunction)
16
18
  - [`Array`](#array)
17
19
  - [`<array>.first(..)` / `<array>.last(..)`](#arrayfirst--arraylast)
18
20
  - [`<array>.rol(..)`](#arrayrol)
@@ -454,6 +456,30 @@ Object.keys(Object.sort(o, ['x', 'a', '100']))
454
456
  This is similar to [`<map>.sort(..)`](#mapsort) and [`<ser>.sort(..)`](#setsort).
455
457
 
456
458
 
459
+ ## `Function`
460
+
461
+ ```javascript
462
+ var func = require('ig-types/Function')
463
+ ```
464
+
465
+ ### `func.AsyncFunction`
466
+
467
+ The async function constructor.
468
+
469
+ This enables us to test if an object is an instance of an async function.
470
+
471
+ ```javascript
472
+ var a = async function(){
473
+ // ...
474
+ }
475
+
476
+ a instanceof func.AsyncFunction // -> true
477
+ ```
478
+
479
+ This is hidden by JavaScript by default.
480
+
481
+
482
+
457
483
  ## `Array`
458
484
 
459
485
  ```javascript
package/event.js CHANGED
@@ -343,14 +343,14 @@ module.EventDocMixin = object.Mixin('EventDocMixin', {
343
343
  return object.deepKeys(this)
344
344
  .filter(function(n){
345
345
  // avoid triggering props...
346
- return !object.values(this, n, function(){ return object.STOP }, true)[0].get
346
+ return !object.values(this, n, true).next().value.get
347
347
  // XXX this is too strict...
348
348
  && (this[n] || {}).constructor === Eventful}.bind(this)) },
349
349
  get events(){
350
350
  return object.deepKeys(this)
351
351
  .filter(function(n){
352
352
  // avoid triggering props...
353
- return !object.values(this, n, function(){ return object.STOP }, true)[0].get
353
+ return !object.values(this, n, true).next().value.get
354
354
  // XXX this is too strict...
355
355
  && (this[n] || {}).constructor === Event }.bind(this)) },
356
356
  })
package/generator.js CHANGED
@@ -8,6 +8,7 @@
8
8
  /*********************************************************************/
9
9
 
10
10
  var object = require('ig-object')
11
+ var stoppable = require('ig-stoppable')
11
12
 
12
13
 
13
14
 
@@ -16,7 +17,7 @@ var object = require('ig-object')
16
17
  // NOTE: this is used in a similar fashion to Python's StopIteration...
17
18
  var STOP =
18
19
  module.STOP =
19
- object.STOP
20
+ stoppable.STOP
20
21
 
21
22
 
22
23
  //---------------------------------------------------------------------
@@ -38,11 +39,11 @@ module.STOP =
38
39
  // of each of them.
39
40
  // So, below we will define:
40
41
  //
41
- // GeneratorPrototype
42
+ // Generator.prototype
42
43
  // prototype of the generator constructors (i.e. Iter(..) from the
43
44
  // above example)
44
45
  //
45
- // GeneratorPrototype.prototype
46
+ // Generator.prototype.prototype
46
47
  // generator instance prototype (i.e. iter for the above code)
47
48
  //
48
49
  //
@@ -58,17 +59,10 @@ module.STOP =
58
59
  //
59
60
  //---------------------------------------------------------------------
60
61
 
61
- var GeneratorPrototype =
62
- (function*(){}).constructor.prototype
63
-
64
62
  var Generator =
65
63
  module.Generator =
66
64
  (function*(){}).constructor
67
65
 
68
-
69
- var AsyncGeneratorPrototype =
70
- (async function*(){}).constructor.prototype
71
-
72
66
  var AsyncGenerator =
73
67
  module.AsyncGenerator =
74
68
  (async function*(){}).constructor
@@ -84,54 +78,6 @@ var ITERATOR_PROTOTYPES = [
84
78
 
85
79
 
86
80
 
87
- //---------------------------------------------------------------------
88
-
89
- // XXX should this be part of object???
90
- var stoppable =
91
- module.stoppable =
92
- function(func){
93
- return Object.assign(
94
- func instanceof Generator ?
95
- // NOTE: the only difference between Generator/AsyncGenerator
96
- // versions of this is the async keyword -- keep them
97
- // in sync...
98
- function*(){
99
- try{
100
- yield* func.call(this, ...arguments)
101
- } catch(err){
102
- if(err === STOP){
103
- return
104
- } else if(err instanceof STOP){
105
- yield err.value
106
- return }
107
- throw err } }
108
- : func instanceof AsyncGenerator ?
109
- // NOTE: the only difference between Generator/AsyncGenerator
110
- // versions of this is the async keyword -- keep them
111
- // in sync...
112
- async function*(){
113
- try{
114
- yield* func.call(this, ...arguments)
115
- } catch(err){
116
- if(err === STOP){
117
- return
118
- } else if(err instanceof STOP){
119
- yield err.value
120
- return }
121
- throw err } }
122
- : function(){
123
- try{
124
- return func.call(this, ...arguments)
125
- } catch(err){
126
- if(err === STOP){
127
- return
128
- } else if(err instanceof STOP){
129
- return err.value }
130
- throw err } },
131
- { toString: function(){
132
- return func.toString() }, }) }
133
-
134
-
135
81
  //---------------------------------------------------------------------
136
82
  // generic generator wrapper...
137
83
 
@@ -165,12 +111,12 @@ Generator.iter =
165
111
 
166
112
  // NOTE: we need .iter(..) to both return generators if passed an iterable
167
113
  // and genereator constructos if passed a function...
168
- iter.__proto__ = GeneratorPrototype
114
+ iter.__proto__ = Generator.prototype
169
115
 
170
116
 
171
117
 
172
118
  //---------------------------------------------------------------------
173
- // GeneratorPrototype "class" methods...
119
+ // Generator.prototype "class" methods...
174
120
  //
175
121
  // the following are effectively the same:
176
122
  // 1) Wrapper
@@ -286,7 +232,7 @@ object.Mixin('GeneratorMixin', 'soft', {
286
232
  return that(...arguments).toArray() },
287
233
  { toString: function(){
288
234
  return that.toString()
289
- + '\n .toString()'}, }) },
235
+ + '\n .toArray()'}, }) },
290
236
  gpop: makeGenerator('gpop'),
291
237
  pop: function(){
292
238
  var that = this
@@ -296,7 +242,7 @@ object.Mixin('GeneratorMixin', 'soft', {
296
242
  return that(...arguments).pop() },
297
243
  { toString: function(){
298
244
  return that.toString()
299
- + '\n .gpop()'}, }) },
245
+ + '\n .pop()'}, }) },
300
246
  push: makeGenerator('push'),
301
247
  gshift: makeGenerator('gshift'),
302
248
  shift: function(){
@@ -307,7 +253,7 @@ object.Mixin('GeneratorMixin', 'soft', {
307
253
  return that(...arguments).shift() },
308
254
  { toString: function(){
309
255
  return that.toString()
310
- + '\n .gshift()'}, }) },
256
+ + '\n .shift()'}, }) },
311
257
  unshift: makeGenerator('unshift'),
312
258
 
313
259
  // promises...
@@ -331,6 +277,18 @@ object.Mixin('GeneratorMixin', 'soft', {
331
277
  //zip: makeGenerator('zip'),
332
278
 
333
279
  enumerate: makeGenerator('enumerate'),
280
+
281
+ // XXX should this have a .gjoin(..) companion...
282
+ join: function(){
283
+ var args = [...arguments]
284
+ var that = this
285
+ return Object.assign(
286
+ function(){
287
+ //return that(...arguments).toArray().shift() },
288
+ return that(...arguments).join(...args) },
289
+ { toString: function(){
290
+ return that.toString()
291
+ + '\n .join()'}, }) },
334
292
  })
335
293
 
336
294
 
@@ -503,11 +461,15 @@ object.Mixin('GeneratorProtoMixin', 'soft', {
503
461
  var i = 0
504
462
  for(var e of this){
505
463
  yield [i++, e] } },
464
+
465
+ join: function(){
466
+ return [...this]
467
+ .join(...arguments) },
506
468
  })
507
469
 
508
470
 
509
- GeneratorMixin(GeneratorPrototype)
510
- GeneratorProtoMixin(GeneratorPrototype.prototype)
471
+ GeneratorMixin(Generator.prototype)
472
+ GeneratorProtoMixin(Generator.prototype.prototype)
511
473
 
512
474
 
513
475
  // Extend base iterators...
@@ -608,13 +570,17 @@ object.Mixin('AsyncGeneratorProtoMixin', 'soft', {
608
570
  yield elem
609
571
  yield* this },
610
572
 
573
+ join: async function(){
574
+ return [...(await this)]
575
+ .join(...arguments) },
576
+
611
577
  // XXX
612
578
  // slice -- not sure if we need this...
613
579
  // ...
614
580
  })
615
581
 
616
- AsyncGeneratorMixin(AsyncGeneratorPrototype)
617
- AsyncGeneratorProtoMixin(AsyncGeneratorPrototype.prototype)
582
+ AsyncGeneratorMixin(AsyncGenerator.prototype)
583
+ AsyncGeneratorProtoMixin(AsyncGenerator.prototype.prototype)
618
584
 
619
585
 
620
586
 
package/main.js CHANGED
@@ -22,6 +22,7 @@ module.patchDate = require('./Date').patchDate
22
22
 
23
23
  // Additional types...
24
24
  module.containers = require('./containers')
25
+ module.func = require('./Function')
25
26
  module.generator = require('./generator')
26
27
  module.event = require('./event')
27
28
  module.runner = require('./runner')
@@ -31,7 +32,9 @@ module.runner = require('./runner')
31
32
  module.STOP = object.STOP
32
33
 
33
34
  // frequently used stuff...
35
+ module.AsyncFunction = module.func.AsyncFunction
34
36
  module.Generator = module.generator.Generator
37
+ module.AsyncGenerator = module.generator.AsyncGenerator
35
38
  // XXX doc...
36
39
  module.iter = module.generator.iter
37
40
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ig-types",
3
- "version": "6.15.6",
3
+ "version": "6.16.0",
4
4
  "description": "Generic JavaScript types and type extensions...",
5
5
  "main": "main.js",
6
6
  "scripts": {
@@ -23,7 +23,8 @@
23
23
  },
24
24
  "homepage": "https://github.com/flynx/types.js#readme",
25
25
  "dependencies": {
26
- "ig-object": "^5.4.16",
26
+ "ig-object": "^6.0.0",
27
+ "ig-stoppable": "^2.0.0",
27
28
  "object-run": "^1.0.1"
28
29
  },
29
30
  "devDependencies": {