ig-types 6.15.6 → 6.16.2

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)
@@ -78,6 +80,7 @@ Library of JavaScript type extensions, types and utilities.
78
80
  - [`<promise-iter>.concat(..)`](#promise-iterconcat)
79
81
  - [`<promise-iter>.push(..)` / `<promise-iter>.unshift(..)`](#promise-iterpush--promise-iterunshift)
80
82
  - [`<promise-iter>.at(..)` / `<promise-iter>.first()` / `<promise-iter>.last()`](#promise-iterat--promise-iterfirst--promise-iterlast)
83
+ - [`<promise-iter>.join(..)`](#promise-iterjoin)
81
84
  - [`<promise-iter>.some(..)` / `<promise-iter>.find(..)`](#promise-itersome--promise-iterfind)
82
85
  - [Array proxy methods returning `<promise-iter>`](#array-proxy-methods-returning-promise-iter)
83
86
  - [Array proxy methods returning a `<promise>`](#array-proxy-methods-returning-a-promise)
@@ -102,6 +105,7 @@ Library of JavaScript type extensions, types and utilities.
102
105
  - [`<generator>.flat(..)`](#generatorflat)
103
106
  - [`<generator>.shift()` / `<generator>.pop()` / `<generator>.gshift()` / `<generator>.gpop()`](#generatorshift--generatorpop--generatorgshift--generatorgpop)
104
107
  - [`<generator>.unshift(..)` / `<generator>.push(..)`](#generatorunshift--generatorpush)
108
+ - [`<generator>.join(..)`](#generatorjoin)
105
109
  - [`<generator>.then(..)` / `<generator>.catch(..)` / `<generator>.finally(..)`](#generatorthen--generatorcatch--generatorfinally)
106
110
  - [`<generator>.toArray()`](#generatortoarray)
107
111
  - [Treating iterators the same as generators](#treating-iterators-the-same-as-generators)
@@ -113,6 +117,7 @@ Library of JavaScript type extensions, types and utilities.
113
117
  - [`<Generator>.slice(..)`](#generatorslice-1)
114
118
  - [`<Generator>.map(..)` / `<Generator>.filter(..)` / `<Generator>.reduce(..)` / `<Generator>.flat()`](#generatormap--generatorfilter--generatorreduce--generatorflat)
115
119
  - [`<Generator>.toArray()`](#generatortoarray-1)
120
+ - [`<Generator>.join(..)`](#generatorjoin-1)
116
121
  - [`<Generator>.then(..)` / `<Generator>.catch(..)` / `<Generator>.finally(..)`](#generatorthen--generatorcatch--generatorfinally-1)
117
122
  - [Generator combinators](#generator-combinators)
118
123
  - [`<Generator>.chain(..)` / `<generator>.chain(..)`](#generatorchain--generatorchain)
@@ -454,6 +459,30 @@ Object.keys(Object.sort(o, ['x', 'a', '100']))
454
459
  This is similar to [`<map>.sort(..)`](#mapsort) and [`<ser>.sort(..)`](#setsort).
455
460
 
456
461
 
462
+ ## `Function`
463
+
464
+ ```javascript
465
+ var func = require('ig-types/Function')
466
+ ```
467
+
468
+ ### `func.AsyncFunction`
469
+
470
+ The async function constructor.
471
+
472
+ This enables us to test if an object is an instance of an async function.
473
+
474
+ ```javascript
475
+ var a = async function(){
476
+ // ...
477
+ }
478
+
479
+ a instanceof func.AsyncFunction // -> true
480
+ ```
481
+
482
+ This is hidden by JavaScript by default.
483
+
484
+
485
+
457
486
  ## `Array`
458
487
 
459
488
  ```javascript
@@ -1685,6 +1714,12 @@ parent `<promise-iter>`.
1685
1714
 
1686
1715
  XXX
1687
1716
 
1717
+
1718
+ #### `<promise-iter>.join(..)`
1719
+
1720
+ XXX
1721
+
1722
+
1688
1723
  #### `<promise-iter>.some(..)` / `<promise-iter>.find(..)`
1689
1724
 
1690
1725
  ```bnf
@@ -2181,6 +2216,11 @@ Value added by `.unshift(..)` will be yielded by `<generator>` "first", i.e. on
2181
2216
  _next_ call to `.next()`, regardless of the current generator state.
2182
2217
 
2183
2218
 
2219
+ #### `<generator>.join(..)`
2220
+
2221
+ XXX
2222
+
2223
+
2184
2224
  #### `<generator>.then(..)` / `<generator>.catch(..)` / `<generator>.finally(..)`
2185
2225
 
2186
2226
  Return a promise and resolve it with the generator value.
@@ -2384,6 +2424,10 @@ Return a function that will return a `<generator>` output as an `Array`.
2384
2424
  -> <function>
2385
2425
  ```
2386
2426
 
2427
+ #### `<Generator>.join(..)`
2428
+
2429
+ XXX
2430
+
2387
2431
 
2388
2432
  #### `<Generator>.then(..)` / `<Generator>.catch(..)` / `<Generator>.finally(..)`
2389
2433
 
package/event.js CHANGED
@@ -116,14 +116,17 @@ object.Constructor('Eventful', {
116
116
  this.handlerLocation == 'method' ?
117
117
  (this.__event_handlers__ = this.__event_handlers__ || [])
118
118
  // context (default)...
119
- : (context.__event_handlers__ == null ?
119
+ //: (context.__event_handlers__ == null ?
120
+ : !context.hasOwnProperty('__event_handlers__') ?
120
121
  Object.defineProperty(context, '__event_handlers__', {
121
122
  value: {[this.name]: (handlers = [])},
122
123
  enumerable: false,
124
+ configurable: true,
125
+ writable: true,
123
126
  })
124
127
  && handlers
125
- : (context.__event_handlers__[this.name] =
126
- context.__event_handlers__[this.name] || []))
128
+ : (context.__event_handlers__[this.name] =
129
+ context.__event_handlers__[this.name] || [])
127
130
  // add handler...
128
131
  handlers.push(handler)
129
132
  return this },
@@ -289,10 +292,13 @@ module.EventHandlerMixin = object.Mixin('EventHandlerMixin', {
289
292
  this[evt].bind(this, func)
290
293
  // non-event...
291
294
  } else {
292
- this.__event_handlers__ == null
295
+ //this.__event_handlers__ == null
296
+ !this.hasOwnProperty('__event_handlers__')
293
297
  && Object.defineProperty(this, '__event_handlers__', {
294
298
  value: {},
295
299
  enumerable: false,
300
+ configurable: true,
301
+ writable: true,
296
302
  })
297
303
  ;(this.__event_handlers__[evt] =
298
304
  this.__event_handlers__[evt] || [])
@@ -343,14 +349,14 @@ module.EventDocMixin = object.Mixin('EventDocMixin', {
343
349
  return object.deepKeys(this)
344
350
  .filter(function(n){
345
351
  // avoid triggering props...
346
- return !object.values(this, n, function(){ return object.STOP }, true)[0].get
352
+ return !object.values(this, n, true).next().value.get
347
353
  // XXX this is too strict...
348
354
  && (this[n] || {}).constructor === Eventful}.bind(this)) },
349
355
  get events(){
350
356
  return object.deepKeys(this)
351
357
  .filter(function(n){
352
358
  // avoid triggering props...
353
- return !object.values(this, n, function(){ return object.STOP }, true)[0].get
359
+ return !object.values(this, n, true).next().value.get
354
360
  // XXX this is too strict...
355
361
  && (this[n] || {}).constructor === Event }.bind(this)) },
356
362
  })
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.2",
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": {