@barchart/portfolio-api-common 1.3.24 → 1.4.3

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.
@@ -253,7 +253,7 @@ module.exports = (() => {
253
253
  }
254
254
 
255
255
  toString() {
256
- return '[InstrumentType]';
256
+ return `[InstrumentType (code=${this.code})]`;
257
257
  }
258
258
  }
259
259
 
@@ -393,6 +393,10 @@ module.exports = (() => {
393
393
  return even;
394
394
  }
395
395
  }
396
+
397
+ toString() {
398
+ return `[PositionDirection (code=${this.code})]`;
399
+ }
396
400
  }
397
401
 
398
402
  const long = new PositionDirection('LONG', 'Long', 'positive');
@@ -580,7 +584,7 @@ module.exports = (() => {
580
584
  }
581
585
 
582
586
  toString() {
583
- return '[PositionSummaryFrame]';
587
+ return `[PositionSummaryFrame (code=${this.code})]`;
584
588
  }
585
589
  }
586
590
 
@@ -1247,7 +1251,7 @@ module.exports = (() => {
1247
1251
  }
1248
1252
 
1249
1253
  toString() {
1250
- return '[TransactionType]';
1254
+ return `[TransactionType (code=${this.code})]`;
1251
1255
  }
1252
1256
  }
1253
1257
 
@@ -1755,7 +1759,7 @@ module.exports = (() => {
1755
1759
  const tree = new Tree();
1756
1760
 
1757
1761
  createGroups.call(this, tree, this._items, treeDefinition, treeDefinition.definitions);
1758
-
1762
+
1759
1763
  map[treeDefinition.name] = tree;
1760
1764
 
1761
1765
  return map;
@@ -2087,6 +2091,41 @@ module.exports = (() => {
2087
2091
  return is.object(item) && item.data.locked;
2088
2092
  }
2089
2093
 
2094
+ /**
2095
+ * Causes a position to be flagged as calculating.
2096
+ *
2097
+ * @public
2098
+ * @param {Object} position
2099
+ */
2100
+ setPositionCalculating(position) {
2101
+ if (position) {
2102
+ assert.argumentIsRequired(position, 'position', Object);
2103
+ assert.argumentIsRequired(position.position, 'position.position', String);
2104
+
2105
+ const item = this._items.find(i => i.position.position === position.position);
2106
+
2107
+ if (item) {
2108
+ item.setPositionCalculating(position);
2109
+ }
2110
+ }
2111
+ }
2112
+
2113
+ /**
2114
+ * Returns a position's calculating status.
2115
+ *
2116
+ * @public
2117
+ * @param {Object} position
2118
+ * @return {Boolean}
2119
+ */
2120
+ getPositionCalculating(position) {
2121
+ assert.argumentIsRequired(position, 'position', Object);
2122
+ assert.argumentIsRequired(position.position, 'position.position', String);
2123
+
2124
+ const item = this._items.find(i => i.position.position === position.position);
2125
+
2126
+ return is.object(item) && item.data.calculating;
2127
+ }
2128
+
2090
2129
  /**
2091
2130
  * Performs a batch update of both position quotes and forex quotes,
2092
2131
  * triggering updates to position(s) and data aggregation(s).
@@ -2139,6 +2178,26 @@ module.exports = (() => {
2139
2178
  }
2140
2179
  }
2141
2180
 
2181
+ /**
2182
+ * Returns current price for symbol provided.
2183
+ *
2184
+ * @param {String} symbol
2185
+ * @return {null|Number}
2186
+ */
2187
+ getCurrentPrice(symbol) {
2188
+ assert.argumentIsRequired(symbol, 'symbol', String);
2189
+
2190
+ let price;
2191
+
2192
+ if (this._symbols.hasOwnProperty(symbol) && this._symbols[symbol].length > 0) {
2193
+ price = this._symbols[symbol][0].currentPrice;
2194
+ } else {
2195
+ price = null;
2196
+ }
2197
+
2198
+ return price;
2199
+ }
2200
+
2142
2201
  /**
2143
2202
  * Sets a historical forex quote.
2144
2203
  *
@@ -2749,6 +2808,7 @@ module.exports = (() => {
2749
2808
  this._dataFormat.hide = false;
2750
2809
  this._dataFormat.invalid = false;
2751
2810
  this._dataFormat.locked = false;
2811
+ this._dataFormat.calculating = false;
2752
2812
  this._dataFormat.newsExists = false;
2753
2813
  this._dataFormat.quantity = null;
2754
2814
  this._dataFormat.quantityPrevious = null;
@@ -3256,6 +3316,7 @@ module.exports = (() => {
3256
3316
 
3257
3317
  let newsBinding = Disposable.getEmpty();
3258
3318
  let lockedBinding = Disposable.getEmpty();
3319
+ let calculatingBinding = Disposable.getEmpty();
3259
3320
 
3260
3321
  if (this._single) {
3261
3322
  newsBinding = item.registerNewsExistsChangeHandler((exists) => {
@@ -3266,6 +3327,10 @@ module.exports = (() => {
3266
3327
  lockedBinding = item.registerLockChangeHandler((locked) => {
3267
3328
  this._dataFormat.locked = locked;
3268
3329
  });
3330
+
3331
+ calculatingBinding = item.registerCalculatingChangeHandler((calculating) => {
3332
+ this._dataFormat.calculating = calculating;
3333
+ });
3269
3334
  }
3270
3335
 
3271
3336
  this._disposeStack.push(item.registerPortfolioChangeHandler((portfolio) => {
@@ -3280,6 +3345,7 @@ module.exports = (() => {
3280
3345
  this._disposeStack.push(fundamentalBinding);
3281
3346
  this._disposeStack.push(quoteBinding);
3282
3347
  this._disposeStack.push(lockedBinding);
3348
+ this._disposeStack.push(calculatingBinding);
3283
3349
  this._disposeStack.push(newsBinding);
3284
3350
 
3285
3351
  this._disposeStack.push(item.registerPositionItemDisposeHandler(() => {
@@ -3287,6 +3353,7 @@ module.exports = (() => {
3287
3353
  quoteBinding.dispose();
3288
3354
  newsBinding.dispose();
3289
3355
  lockedBinding.dispose();
3356
+ calculatingBinding.dispose();
3290
3357
 
3291
3358
  array.remove(this._items, i => i === item);
3292
3359
  array.remove(this._excludedItems, i => i === item);
@@ -3339,7 +3406,7 @@ module.exports = (() => {
3339
3406
  const format = group._dataFormat;
3340
3407
 
3341
3408
  const currency = group.currency;
3342
-
3409
+
3343
3410
  const items = group._consideredItems;
3344
3411
 
3345
3412
  group._bypassCurrencyTranslation = items.every(item => item.currency === currency);
@@ -3470,6 +3537,7 @@ module.exports = (() => {
3470
3537
 
3471
3538
  format.invalid = definition.type === PositionLevelType.POSITION && item.invalid;
3472
3539
  format.locked = definition.type === PositionLevelType.POSITION && item.data.locked;
3540
+ format.calculating = definition.type === PositionLevelType.POSITION && item.data.calculating;
3473
3541
  }
3474
3542
 
3475
3543
  let portfolioType = null;
@@ -3575,7 +3643,7 @@ module.exports = (() => {
3575
3643
  actual.marketChangePercent = marketChangePercent;
3576
3644
 
3577
3645
  format.market = formatCurrency(actual.market, currency);
3578
-
3646
+
3579
3647
  if (updates.marketDirection.up || updates.marketDirection.down) {
3580
3648
  format.marketDirection = unchanged;
3581
3649
  setTimeout(() => format.marketDirection = updates.marketDirection, 0);
@@ -3764,7 +3832,7 @@ module.exports = (() => {
3764
3832
 
3765
3833
  this._data.quantity = null;
3766
3834
  this._data.quantityPrevious = null;
3767
-
3835
+
3768
3836
  this._data.realized = null;
3769
3837
  this._data.income = null;
3770
3838
  this._data.basisPrice = null;
@@ -3796,12 +3864,14 @@ module.exports = (() => {
3796
3864
 
3797
3865
  this._data.newsExists = false;
3798
3866
  this._data.fundamental = { };
3867
+ this._data.calculating = getIsCalculating(position);
3799
3868
  this._data.locked = getIsLocked(position);
3800
3869
 
3801
3870
  this._quoteChangedEvent = new Event(this);
3802
3871
  this._newsExistsChangedEvent = new Event(this);
3803
3872
  this._fundamentalDataChangedEvent = new Event(this);
3804
3873
  this._lockChangedEvent = new Event(this);
3874
+ this._calculatingChangedEvent = new Event(this);
3805
3875
  this._portfolioChangedEvent = new Event(this);
3806
3876
  this._positionItemDisposeEvent = new Event(this);
3807
3877
 
@@ -3899,6 +3969,15 @@ module.exports = (() => {
3899
3969
  return this._previousQuote;
3900
3970
  }
3901
3971
 
3972
+ /**
3973
+ * The current price.
3974
+ *
3975
+ * @return {null|Number}
3976
+ */
3977
+ get currentPrice() {
3978
+ return this._currentPrice;
3979
+ }
3980
+
3902
3981
  updatePortfolio(portfolio) {
3903
3982
  assert.argumentIsRequired(portfolio, 'portfolio', Object);
3904
3983
  assert.argumentIsRequired(portfolio.portfolio, 'portfolio.portfolio', String);
@@ -3998,6 +4077,26 @@ module.exports = (() => {
3998
4077
  }
3999
4078
  }
4000
4079
 
4080
+ /**
4081
+ * Sets a position's calculating status.
4082
+ *
4083
+ * @public
4084
+ * @param {Object} position
4085
+ */
4086
+ setPositionCalculating(position) {
4087
+ assert.argumentIsRequired(position, 'position', Object);
4088
+
4089
+ if (this.getIsDisposed()) {
4090
+ return;
4091
+ }
4092
+
4093
+ const value = getIsCalculating(position);
4094
+
4095
+ if (this._data.calculating !== value) {
4096
+ this._calculatingChangedEvent.fire(this._data.calculating = value);
4097
+ }
4098
+ }
4099
+
4001
4100
  /**
4002
4101
  * Registers an observer for quote changes, which is fired after internal recalculations
4003
4102
  * of position data are complete.
@@ -4043,6 +4142,17 @@ module.exports = (() => {
4043
4142
  return this._lockChangedEvent.register(handler);
4044
4143
  }
4045
4144
 
4145
+ /**
4146
+ * Registers an observer for position calculating changes.
4147
+ *
4148
+ * @public
4149
+ * @param {Function} handler
4150
+ * @return {Disposable}
4151
+ */
4152
+ registerCalculatingChangeHandler(handler) {
4153
+ return this._calculatingChangedEvent.register(handler);
4154
+ }
4155
+
4046
4156
  /**
4047
4157
  * Registers an observer changes to portfolio metadata.
4048
4158
  *
@@ -4405,6 +4515,12 @@ module.exports = (() => {
4405
4515
  return is.object(position.system) && is.boolean(position.system.locked) && position.system.locked;
4406
4516
  }
4407
4517
 
4518
+ function getIsCalculating(position) {
4519
+ assert.argumentIsRequired(position, 'position', Object);
4520
+
4521
+ return is.object(position.system) && is.object(position.system.calculate) && is.number(position.system.calculate.processors) && position.system.calculate.processors > 0;
4522
+ }
4523
+
4408
4524
  function getSnapshot(position, currentSummary, reporting) {
4409
4525
  let snapshot;
4410
4526
 
@@ -8826,7 +8942,7 @@ module.exports = (() => {
8826
8942
 
8827
8943
  return {
8828
8944
  /**
8829
- * Returns true, if the argument is a number. NaN will return false.
8945
+ * Returns true if the argument is a number. NaN will return false.
8830
8946
  *
8831
8947
  * @static
8832
8948
  * @public
@@ -8838,7 +8954,7 @@ module.exports = (() => {
8838
8954
  },
8839
8955
 
8840
8956
  /**
8841
- * Returns true, if the argument is NaN.
8957
+ * Returns true if the argument is NaN.
8842
8958
  *
8843
8959
  * @static
8844
8960
  * @public
@@ -8850,7 +8966,7 @@ module.exports = (() => {
8850
8966
  },
8851
8967
 
8852
8968
  /**
8853
- * Returns true, if the argument is a valid 32-bit integer.
8969
+ * Returns true if the argument is a valid 32-bit integer.
8854
8970
  *
8855
8971
  * @static
8856
8972
  * @public
@@ -8862,7 +8978,7 @@ module.exports = (() => {
8862
8978
  },
8863
8979
 
8864
8980
  /**
8865
- * Returns true, if the argument is a valid integer (which can exceed 32 bits); however,
8981
+ * Returns true if the argument is a valid integer (which can exceed 32 bits); however,
8866
8982
  * the check can fail above the value of Number.MAX_SAFE_INTEGER.
8867
8983
  *
8868
8984
  * @static
@@ -8875,7 +8991,7 @@ module.exports = (() => {
8875
8991
  },
8876
8992
 
8877
8993
  /**
8878
- * Returns true, if the argument is a number that is positive.
8994
+ * Returns true if the argument is a number that is positive.
8879
8995
  *
8880
8996
  * @static
8881
8997
  * @public
@@ -8887,7 +9003,7 @@ module.exports = (() => {
8887
9003
  },
8888
9004
 
8889
9005
  /**
8890
- * Returns true, if the argument is a number that is negative.
9006
+ * Returns true if the argument is a number that is negative.
8891
9007
  *
8892
9008
  * @static
8893
9009
  * @public
@@ -8899,7 +9015,19 @@ module.exports = (() => {
8899
9015
  },
8900
9016
 
8901
9017
  /**
8902
- * Returns true, if the argument is a string.
9018
+ * Returns true if the argument is iterable.
9019
+ *
9020
+ * @static
9021
+ * @public
9022
+ * @param {*} candidate
9023
+ * @returns {boolean}
9024
+ */
9025
+ iterable(candidate) {
9026
+ return !this.null(candidate) && !this.undefined(candidate) && this.fn(candidate[Symbol.iterator]);
9027
+ },
9028
+
9029
+ /**
9030
+ * Returns true if the argument is a string.
8903
9031
  *
8904
9032
  * @static
8905
9033
  * @public
@@ -8911,7 +9039,7 @@ module.exports = (() => {
8911
9039
  },
8912
9040
 
8913
9041
  /**
8914
- * Returns true, if the argument is a JavaScript Date instance.
9042
+ * Returns true if the argument is a JavaScript Date instance.
8915
9043
  *
8916
9044
  * @static
8917
9045
  * @public
@@ -8923,7 +9051,7 @@ module.exports = (() => {
8923
9051
  },
8924
9052
 
8925
9053
  /**
8926
- * Returns true, if the argument is a function.
9054
+ * Returns true if the argument is a function.
8927
9055
  *
8928
9056
  * @static
8929
9057
  * @public
@@ -8935,7 +9063,7 @@ module.exports = (() => {
8935
9063
  },
8936
9064
 
8937
9065
  /**
8938
- * Returns true, if the argument is an array.
9066
+ * Returns true if the argument is an array.
8939
9067
  *
8940
9068
  * @static
8941
9069
  * @public
@@ -8947,7 +9075,7 @@ module.exports = (() => {
8947
9075
  },
8948
9076
 
8949
9077
  /**
8950
- * Returns true, if the argument is a Boolean value.
9078
+ * Returns true if the argument is a Boolean value.
8951
9079
  *
8952
9080
  * @static
8953
9081
  * @public
@@ -8959,7 +9087,7 @@ module.exports = (() => {
8959
9087
  },
8960
9088
 
8961
9089
  /**
8962
- * Returns true, if the argument is an object.
9090
+ * Returns true if the argument is an object.
8963
9091
  *
8964
9092
  * @static
8965
9093
  * @public
@@ -8971,7 +9099,7 @@ module.exports = (() => {
8971
9099
  },
8972
9100
 
8973
9101
  /**
8974
- * Returns true, if the argument is a null value.
9102
+ * Returns true if the argument is a null value.
8975
9103
  *
8976
9104
  * @static
8977
9105
  * @public
@@ -8983,7 +9111,7 @@ module.exports = (() => {
8983
9111
  },
8984
9112
 
8985
9113
  /**
8986
- * Returns true, if the argument is an undefined value.
9114
+ * Returns true if the argument is an undefined value.
8987
9115
  *
8988
9116
  * @static
8989
9117
  * @public
@@ -8994,6 +9122,18 @@ module.exports = (() => {
8994
9122
  return candidate === undefined;
8995
9123
  },
8996
9124
 
9125
+ /**
9126
+ * Returns true if the argument is a zero-length string.
9127
+ *
9128
+ * @static
9129
+ * @public
9130
+ * @param {*} candidate
9131
+ * @returns {boolean}
9132
+ */
9133
+ zeroLengthString(candidate) {
9134
+ return this.string(candidate) && candidate.length === 0;
9135
+ },
9136
+
8997
9137
  /**
8998
9138
  * Given two classes, determines if the "child" class extends
8999
9139
  * the "parent" class (without instantiation).
@@ -9033,11 +9173,11 @@ module.exports = (() => {
9033
9173
  simple(fn) {
9034
9174
  const cache = {};
9035
9175
  return x => {
9036
- if (cache.hasOwnProperty(x)) {
9037
- return cache[x];
9038
- } else {
9039
- return cache[x] = fn(x);
9176
+ if (!cache.hasOwnProperty(x)) {
9177
+ cache[x] = fn(x);
9040
9178
  }
9179
+
9180
+ return cache[x];
9041
9181
  };
9042
9182
  },
9043
9183
 
@@ -10172,9 +10312,9 @@ module.exports = (() => {
10172
10312
 
10173
10313
  },{"./../../../lang/assert":29,"./../../../lang/is":33,"./../Component":36,"./../DataType":37,"./../Field":38,"./../Schema":39,"./ComponentBuilder":40}],42:[function(require,module,exports){
10174
10314
  /*
10175
- * big.js v5.0.3
10315
+ * big.js v5.2.2
10176
10316
  * A small, fast, easy-to-use library for arbitrary-precision decimal arithmetic.
10177
- * Copyright (c) 2017 Michael Mclaughlin <M8ch88l@gmail.com>
10317
+ * Copyright (c) 2018 Michael Mclaughlin <M8ch88l@gmail.com>
10178
10318
  * https://github.com/MikeMcl/big.js/LICENCE
10179
10319
  */
10180
10320
  ;(function (GLOBAL) {
@@ -10280,7 +10420,7 @@ module.exports = (() => {
10280
10420
  Big.RM = RM;
10281
10421
  Big.NE = NE;
10282
10422
  Big.PE = PE;
10283
- Big.version = '5.0.2';
10423
+ Big.version = '5.2.2';
10284
10424
 
10285
10425
  return Big;
10286
10426
  }
@@ -10364,7 +10504,7 @@ module.exports = (() => {
10364
10504
  more = xc[i] > 5 || xc[i] == 5 &&
10365
10505
  (more || i < 0 || xc[i + 1] !== UNDEFINED || xc[i - 1] & 1);
10366
10506
  } else if (rm === 3) {
10367
- more = more || xc[i] !== UNDEFINED || i < 0;
10507
+ more = more || !!xc[0];
10368
10508
  } else {
10369
10509
  more = false;
10370
10510
  if (rm !== 0) throw Error(INVALID_RM);
@@ -10831,7 +10971,7 @@ module.exports = (() => {
10831
10971
  xc = xc.slice();
10832
10972
 
10833
10973
  // Prepend zeros to equalise exponents.
10834
- // Note: Faster to use reverse then do unshifts.
10974
+ // Note: reverse faster than unshifts.
10835
10975
  if (a = xe - ye) {
10836
10976
  if (a > 0) {
10837
10977
  ye = xe;
@@ -10903,18 +11043,19 @@ module.exports = (() => {
10903
11043
 
10904
11044
 
10905
11045
  /*
10906
- * Return a new Big whose value is the value of this Big rounded to a maximum of dp decimal
10907
- * places using rounding mode rm.
11046
+ * Return a new Big whose value is the value of this Big rounded using rounding mode rm
11047
+ * to a maximum of dp decimal places, or, if dp is negative, to an integer which is a
11048
+ * multiple of 10**-dp.
10908
11049
  * If dp is not specified, round to 0 decimal places.
10909
11050
  * If rm is not specified, use Big.RM.
10910
11051
  *
10911
- * dp? {number} Integer, 0 to MAX_DP inclusive.
11052
+ * dp? {number} Integer, -MAX_DP to MAX_DP inclusive.
10912
11053
  * rm? 0, 1, 2 or 3 (ROUND_DOWN, ROUND_HALF_UP, ROUND_HALF_EVEN, ROUND_UP)
10913
11054
  */
10914
11055
  P.round = function (dp, rm) {
10915
11056
  var Big = this.constructor;
10916
11057
  if (dp === UNDEFINED) dp = 0;
10917
- else if (dp !== ~~dp || dp < 0 || dp > MAX_DP) throw Error(INVALID_DP);
11058
+ else if (dp !== ~~dp || dp < -MAX_DP || dp > MAX_DP) throw Error(INVALID_DP);
10918
11059
  return round(new Big(this), dp, rm === UNDEFINED ? Big.RM : rm);
10919
11060
  };
10920
11061
 
@@ -10938,17 +11079,18 @@ module.exports = (() => {
10938
11079
  if (s < 0) throw Error(NAME + 'No square root');
10939
11080
 
10940
11081
  // Estimate.
10941
- s = Math.sqrt(x.toString());
11082
+ s = Math.sqrt(x + '');
10942
11083
 
10943
11084
  // Math.sqrt underflow/overflow?
10944
- // Re-estimate: pass x to Math.sqrt as integer, then adjust the result exponent.
11085
+ // Re-estimate: pass x coefficient to Math.sqrt as integer, then adjust the result exponent.
10945
11086
  if (s === 0 || s === 1 / 0) {
10946
11087
  c = x.c.join('');
10947
11088
  if (!(c.length + e & 1)) c += '0';
10948
- r = new Big(Math.sqrt(c).toString());
10949
- r.e = ((e + 1) / 2 | 0) - (e < 0 || e & 1);
11089
+ s = Math.sqrt(c);
11090
+ e = ((e + 1) / 2 | 0) - (e < 0 || e & 1);
11091
+ r = new Big((s == 1 / 0 ? '1e' : (s = s.toExponential()).slice(0, s.indexOf('e') + 1)) + e);
10950
11092
  } else {
10951
- r = new Big(s.toString());
11093
+ r = new Big(s);
10952
11094
  }
10953
11095
 
10954
11096
  e = r.e + (Big.DP += 4);
@@ -16972,43 +17114,48 @@ for (var i = 0; i < 256; ++i) {
16972
17114
  function bytesToUuid(buf, offset) {
16973
17115
  var i = offset || 0;
16974
17116
  var bth = byteToHex;
16975
- return bth[buf[i++]] + bth[buf[i++]] +
16976
- bth[buf[i++]] + bth[buf[i++]] + '-' +
16977
- bth[buf[i++]] + bth[buf[i++]] + '-' +
16978
- bth[buf[i++]] + bth[buf[i++]] + '-' +
16979
- bth[buf[i++]] + bth[buf[i++]] + '-' +
16980
- bth[buf[i++]] + bth[buf[i++]] +
16981
- bth[buf[i++]] + bth[buf[i++]] +
16982
- bth[buf[i++]] + bth[buf[i++]];
17117
+ // join used to fix memory issue caused by concatenation: https://bugs.chromium.org/p/v8/issues/detail?id=3175#c4
17118
+ return ([
17119
+ bth[buf[i++]], bth[buf[i++]],
17120
+ bth[buf[i++]], bth[buf[i++]], '-',
17121
+ bth[buf[i++]], bth[buf[i++]], '-',
17122
+ bth[buf[i++]], bth[buf[i++]], '-',
17123
+ bth[buf[i++]], bth[buf[i++]], '-',
17124
+ bth[buf[i++]], bth[buf[i++]],
17125
+ bth[buf[i++]], bth[buf[i++]],
17126
+ bth[buf[i++]], bth[buf[i++]]
17127
+ ]).join('');
16983
17128
  }
16984
17129
 
16985
17130
  module.exports = bytesToUuid;
16986
17131
 
16987
17132
  },{}],49:[function(require,module,exports){
16988
- (function (global){
16989
17133
  // Unique ID creation requires a high quality random # generator. In the
16990
17134
  // browser this is a little complicated due to unknown quality of Math.random()
16991
17135
  // and inconsistent support for the `crypto` API. We do the best we can via
16992
17136
  // feature-detection
16993
- var rng;
16994
17137
 
16995
- var crypto = global.crypto || global.msCrypto; // for IE 11
16996
- if (crypto && crypto.getRandomValues) {
17138
+ // getRandomValues needs to be invoked in a context where "this" is a Crypto
17139
+ // implementation. Also, find the complete implementation of crypto on IE11.
17140
+ var getRandomValues = (typeof(crypto) != 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto)) ||
17141
+ (typeof(msCrypto) != 'undefined' && typeof window.msCrypto.getRandomValues == 'function' && msCrypto.getRandomValues.bind(msCrypto));
17142
+
17143
+ if (getRandomValues) {
16997
17144
  // WHATWG crypto RNG - http://wiki.whatwg.org/wiki/Crypto
16998
17145
  var rnds8 = new Uint8Array(16); // eslint-disable-line no-undef
16999
- rng = function whatwgRNG() {
17000
- crypto.getRandomValues(rnds8);
17146
+
17147
+ module.exports = function whatwgRNG() {
17148
+ getRandomValues(rnds8);
17001
17149
  return rnds8;
17002
17150
  };
17003
- }
17004
-
17005
- if (!rng) {
17151
+ } else {
17006
17152
  // Math.random()-based (RNG)
17007
17153
  //
17008
17154
  // If all else fails, use Math.random(). It's fast, but is of unspecified
17009
17155
  // quality.
17010
17156
  var rnds = new Array(16);
17011
- rng = function() {
17157
+
17158
+ module.exports = function mathRNG() {
17012
17159
  for (var i = 0, r; i < 16; i++) {
17013
17160
  if ((i & 0x03) === 0) r = Math.random() * 0x100000000;
17014
17161
  rnds[i] = r >>> ((i & 0x03) << 3) & 0xff;
@@ -17018,9 +17165,6 @@ if (!rng) {
17018
17165
  };
17019
17166
  }
17020
17167
 
17021
- module.exports = rng;
17022
-
17023
- }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
17024
17168
  },{}],50:[function(require,module,exports){
17025
17169
  var rng = require('./lib/rng');
17026
17170
  var bytesToUuid = require('./lib/bytesToUuid');
@@ -17030,30 +17174,40 @@ var bytesToUuid = require('./lib/bytesToUuid');
17030
17174
  // Inspired by https://github.com/LiosK/UUID.js
17031
17175
  // and http://docs.python.org/library/uuid.html
17032
17176
 
17033
- // random #'s we need to init node and clockseq
17034
- var _seedBytes = rng();
17035
-
17036
- // Per 4.5, create and 48-bit node id, (47 random bits + multicast bit = 1)
17037
- var _nodeId = [
17038
- _seedBytes[0] | 0x01,
17039
- _seedBytes[1], _seedBytes[2], _seedBytes[3], _seedBytes[4], _seedBytes[5]
17040
- ];
17041
-
17042
- // Per 4.2.2, randomize (14 bit) clockseq
17043
- var _clockseq = (_seedBytes[6] << 8 | _seedBytes[7]) & 0x3fff;
17177
+ var _nodeId;
17178
+ var _clockseq;
17044
17179
 
17045
17180
  // Previous uuid creation time
17046
- var _lastMSecs = 0, _lastNSecs = 0;
17181
+ var _lastMSecs = 0;
17182
+ var _lastNSecs = 0;
17047
17183
 
17048
- // See https://github.com/broofa/node-uuid for API details
17184
+ // See https://github.com/uuidjs/uuid for API details
17049
17185
  function v1(options, buf, offset) {
17050
17186
  var i = buf && offset || 0;
17051
17187
  var b = buf || [];
17052
17188
 
17053
17189
  options = options || {};
17054
-
17190
+ var node = options.node || _nodeId;
17055
17191
  var clockseq = options.clockseq !== undefined ? options.clockseq : _clockseq;
17056
17192
 
17193
+ // node and clockseq need to be initialized to random values if they're not
17194
+ // specified. We do this lazily to minimize issues related to insufficient
17195
+ // system entropy. See #189
17196
+ if (node == null || clockseq == null) {
17197
+ var seedBytes = rng();
17198
+ if (node == null) {
17199
+ // Per 4.5, create and 48-bit node id, (47 random bits + multicast bit = 1)
17200
+ node = _nodeId = [
17201
+ seedBytes[0] | 0x01,
17202
+ seedBytes[1], seedBytes[2], seedBytes[3], seedBytes[4], seedBytes[5]
17203
+ ];
17204
+ }
17205
+ if (clockseq == null) {
17206
+ // Per 4.2.2, randomize (14 bit) clockseq
17207
+ clockseq = _clockseq = (seedBytes[6] << 8 | seedBytes[7]) & 0x3fff;
17208
+ }
17209
+ }
17210
+
17057
17211
  // UUID timestamps are 100 nano-second units since the Gregorian epoch,
17058
17212
  // (1582-10-15 00:00). JSNumbers aren't precise enough for this, so
17059
17213
  // time is handled internally as 'msecs' (integer milliseconds) and 'nsecs'
@@ -17113,7 +17267,6 @@ function v1(options, buf, offset) {
17113
17267
  b[i++] = clockseq & 0xff;
17114
17268
 
17115
17269
  // `node`
17116
- var node = options.node || _nodeId;
17117
17270
  for (var n = 0; n < 6; ++n) {
17118
17271
  b[i + n] = node[n];
17119
17272
  }
@@ -17131,7 +17284,7 @@ function v4(options, buf, offset) {
17131
17284
  var i = buf && offset || 0;
17132
17285
 
17133
17286
  if (typeof(options) == 'string') {
17134
- buf = options == 'binary' ? new Array(16) : null;
17287
+ buf = options === 'binary' ? new Array(16) : null;
17135
17288
  options = null;
17136
17289
  }
17137
17290
  options = options || {};
package/jsdoc.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "source": {
3
- "include": [ "." ],
4
- "exclude": [ "./node_modules", "./test" ],
5
- "includePattern": ".+\\.js(doc|x)?$",
6
- "excludePattern": "(^|\\/|\\\\)_"
7
- }
8
- }