@barchart/portfolio-api-common 1.2.57 → 1.2.58
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.
|
@@ -26,10 +26,11 @@ module.exports = (() => {
|
|
|
26
26
|
* @public
|
|
27
27
|
* @static
|
|
28
28
|
* @param {Array.<Object>} transactions
|
|
29
|
+
* @param {Boolean=} strict
|
|
29
30
|
* @returns {Boolean}
|
|
30
31
|
*/
|
|
31
|
-
static validateOrder(transactions) {
|
|
32
|
-
return TransactionValidator.getInvalidIndex(transactions) < 0;
|
|
32
|
+
static validateOrder(transactions, strict) {
|
|
33
|
+
return TransactionValidator.getInvalidIndex(transactions, strict) < 0;
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
/**
|
|
@@ -77,15 +78,14 @@ module.exports = (() => {
|
|
|
77
78
|
* @public
|
|
78
79
|
* @static
|
|
79
80
|
* @param {Array.<Object>} transactions
|
|
81
|
+
* @param {Boolean=} strict
|
|
80
82
|
* @returns {Number}
|
|
81
83
|
*/
|
|
82
|
-
static getInvalidIndex(transactions) {
|
|
84
|
+
static getInvalidIndex(transactions, strict) {
|
|
83
85
|
assert.argumentIsArray(transactions, 'transactions');
|
|
86
|
+
assert.argumentIsOptional(strict, 'strict', Boolean);
|
|
84
87
|
|
|
85
|
-
return transactions.findIndex((t, i) => t.sequence !== (i + 1) || (i !== 0 && t.date.getIsBefore(
|
|
86
|
-
|
|
87
|
-
//return transactions.findIndex((t, i, a) => t.sequence !== (i + 1) || (i !== 0 && t.date.getIsBefore(a[ i - 1 ].date)));
|
|
88
|
-
//return transactions.findIndex((t, i, a) => t.sequence !== (i + 1) || (i !== 0 && t.date.getIsBefore(a[ i - 1 ].date)) || (i !== 0 && t.date.getIsEqual(a[i - 1].date) && t.type.sequence < a[i - 1].type.sequence));
|
|
88
|
+
return transactions.findIndex((t, i, a) => t.sequence !== (i + 1) || (i !== 0 && t.date.getIsBefore(a[ i - 1 ].date)) || (i !== 0 && is.boolean(strict) && strict && t.date.getIsEqual(a[i - 1].date) && t.type.sequence < a[i - 1].type.sequence));
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
/**
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -1083,10 +1083,11 @@ module.exports = (() => {
|
|
|
1083
1083
|
* @public
|
|
1084
1084
|
* @static
|
|
1085
1085
|
* @param {Array.<Object>} transactions
|
|
1086
|
+
* @param {Boolean=} strict
|
|
1086
1087
|
* @returns {Boolean}
|
|
1087
1088
|
*/
|
|
1088
|
-
static validateOrder(transactions) {
|
|
1089
|
-
return TransactionValidator.getInvalidIndex(transactions) < 0;
|
|
1089
|
+
static validateOrder(transactions, strict) {
|
|
1090
|
+
return TransactionValidator.getInvalidIndex(transactions, strict) < 0;
|
|
1090
1091
|
}
|
|
1091
1092
|
|
|
1092
1093
|
/**
|
|
@@ -1134,15 +1135,14 @@ module.exports = (() => {
|
|
|
1134
1135
|
* @public
|
|
1135
1136
|
* @static
|
|
1136
1137
|
* @param {Array.<Object>} transactions
|
|
1138
|
+
* @param {Boolean=} strict
|
|
1137
1139
|
* @returns {Number}
|
|
1138
1140
|
*/
|
|
1139
|
-
static getInvalidIndex(transactions) {
|
|
1141
|
+
static getInvalidIndex(transactions, strict) {
|
|
1140
1142
|
assert.argumentIsArray(transactions, 'transactions');
|
|
1143
|
+
assert.argumentIsOptional(strict, 'strict', Boolean);
|
|
1141
1144
|
|
|
1142
|
-
return transactions.findIndex((t, i) => t.sequence !== (i + 1) || (i !== 0 && t.date.getIsBefore(
|
|
1143
|
-
|
|
1144
|
-
//return transactions.findIndex((t, i, a) => t.sequence !== (i + 1) || (i !== 0 && t.date.getIsBefore(a[ i - 1 ].date)));
|
|
1145
|
-
//return transactions.findIndex((t, i, a) => t.sequence !== (i + 1) || (i !== 0 && t.date.getIsBefore(a[ i - 1 ].date)) || (i !== 0 && t.date.getIsEqual(a[i - 1].date) && t.type.sequence < a[i - 1].type.sequence));
|
|
1145
|
+
return transactions.findIndex((t, i, a) => t.sequence !== (i + 1) || (i !== 0 && t.date.getIsBefore(a[ i - 1 ].date)) || (i !== 0 && is.boolean(strict) && strict && t.date.getIsEqual(a[i - 1].date) && t.type.sequence < a[i - 1].type.sequence));
|
|
1146
1146
|
}
|
|
1147
1147
|
|
|
1148
1148
|
/**
|
|
@@ -5166,8 +5166,8 @@ module.exports = function () {
|
|
|
5166
5166
|
* Compares two strings (in ascending order), using {@link String#localeCompare}.
|
|
5167
5167
|
*
|
|
5168
5168
|
* @static
|
|
5169
|
-
* @param {
|
|
5170
|
-
* @param {
|
|
5169
|
+
* @param {Number} a
|
|
5170
|
+
* @param {Number} b
|
|
5171
5171
|
* @returns {Number}
|
|
5172
5172
|
*/
|
|
5173
5173
|
compareStrings: function compareStrings(a, b) {
|
|
@@ -5857,7 +5857,7 @@ module.exports = function () {
|
|
|
5857
5857
|
* @returns {String}
|
|
5858
5858
|
*/
|
|
5859
5859
|
value: function format() {
|
|
5860
|
-
return
|
|
5860
|
+
return this._year + '-' + leftPad(this._month) + '-' + leftPad(this._day);
|
|
5861
5861
|
}
|
|
5862
5862
|
|
|
5863
5863
|
/**
|
|
@@ -5974,7 +5974,7 @@ module.exports = function () {
|
|
|
5974
5974
|
*
|
|
5975
5975
|
* @static
|
|
5976
5976
|
* @public
|
|
5977
|
-
* @
|
|
5977
|
+
* @return {Day}
|
|
5978
5978
|
*/
|
|
5979
5979
|
|
|
5980
5980
|
}, {
|
|
@@ -6066,11 +6066,8 @@ module.exports = function () {
|
|
|
6066
6066
|
|
|
6067
6067
|
var dayRegex = /^([0-9]{4}).?([0-9]{2}).?([0-9]{2})$/;
|
|
6068
6068
|
|
|
6069
|
-
function leftPad(value
|
|
6070
|
-
|
|
6071
|
-
var padding = digits - string.length;
|
|
6072
|
-
|
|
6073
|
-
return '' + character.repeat(padding) + string;
|
|
6069
|
+
function leftPad(value) {
|
|
6070
|
+
return value < 10 ? '0' + value : '' + value;
|
|
6074
6071
|
}
|
|
6075
6072
|
|
|
6076
6073
|
var comparator = ComparatorBuilder.startWith(function (a, b) {
|
|
@@ -6425,7 +6422,7 @@ module.exports = function () {
|
|
|
6425
6422
|
*
|
|
6426
6423
|
* @public
|
|
6427
6424
|
* @param {Decimal} instance
|
|
6428
|
-
* @
|
|
6425
|
+
* @return {Boolean}
|
|
6429
6426
|
*/
|
|
6430
6427
|
value: function getIsZero(instance) {
|
|
6431
6428
|
assert.argumentIsRequired(instance, 'instance', Decimal, 'Decimal');
|
|
@@ -6438,7 +6435,7 @@ module.exports = function () {
|
|
|
6438
6435
|
*
|
|
6439
6436
|
* @public
|
|
6440
6437
|
* @param {Decimal} instance
|
|
6441
|
-
* @
|
|
6438
|
+
* @return {Boolean}
|
|
6442
6439
|
*/
|
|
6443
6440
|
|
|
6444
6441
|
}, {
|
|
@@ -6454,7 +6451,7 @@ module.exports = function () {
|
|
|
6454
6451
|
*
|
|
6455
6452
|
* @public
|
|
6456
6453
|
* @param {Decimal} instance
|
|
6457
|
-
* @
|
|
6454
|
+
* @return {Boolean}
|
|
6458
6455
|
*/
|
|
6459
6456
|
|
|
6460
6457
|
}, {
|
|
@@ -6470,7 +6467,7 @@ module.exports = function () {
|
|
|
6470
6467
|
*
|
|
6471
6468
|
* @public
|
|
6472
6469
|
* @param {Decimal} instance
|
|
6473
|
-
* @
|
|
6470
|
+
* @return {Boolean}
|
|
6474
6471
|
*/
|
|
6475
6472
|
|
|
6476
6473
|
}, {
|
|
@@ -6486,7 +6483,7 @@ module.exports = function () {
|
|
|
6486
6483
|
*
|
|
6487
6484
|
* @public
|
|
6488
6485
|
* @param {Decimal} instance
|
|
6489
|
-
* @
|
|
6486
|
+
* @return {Boolean}
|
|
6490
6487
|
*/
|
|
6491
6488
|
|
|
6492
6489
|
}, {
|
|
@@ -6502,7 +6499,7 @@ module.exports = function () {
|
|
|
6502
6499
|
*
|
|
6503
6500
|
* @public
|
|
6504
6501
|
* @param {Decimal} instance
|
|
6505
|
-
* @
|
|
6502
|
+
* @return {Boolean}
|
|
6506
6503
|
*/
|
|
6507
6504
|
|
|
6508
6505
|
}, {
|
|
@@ -6892,7 +6889,6 @@ module.exports = function () {
|
|
|
6892
6889
|
/**
|
|
6893
6890
|
* The unique code.
|
|
6894
6891
|
*
|
|
6895
|
-
* @public
|
|
6896
6892
|
* @returns {String}
|
|
6897
6893
|
*/
|
|
6898
6894
|
|
|
@@ -6905,7 +6901,6 @@ module.exports = function () {
|
|
|
6905
6901
|
* Returns true if the provided {@link Enum} argument is equal
|
|
6906
6902
|
* to the instance.
|
|
6907
6903
|
*
|
|
6908
|
-
* @public
|
|
6909
6904
|
* @param {Enum} other
|
|
6910
6905
|
* @returns {boolean}
|
|
6911
6906
|
*/
|
|
@@ -6930,7 +6925,6 @@ module.exports = function () {
|
|
|
6930
6925
|
* Looks up a enumeration item; given the enumeration type and the enumeration
|
|
6931
6926
|
* item's value. If no matching item can be found, a null value is returned.
|
|
6932
6927
|
*
|
|
6933
|
-
* @public
|
|
6934
6928
|
* @param {Function} type - The enumeration type.
|
|
6935
6929
|
* @param {String} code - The enumeration item's code.
|
|
6936
6930
|
* @returns {*|null}
|
|
@@ -6950,7 +6944,6 @@ module.exports = function () {
|
|
|
6950
6944
|
/**
|
|
6951
6945
|
* The description.
|
|
6952
6946
|
*
|
|
6953
|
-
* @public
|
|
6954
6947
|
* @returns {String}
|
|
6955
6948
|
*/
|
|
6956
6949
|
|
|
@@ -6970,7 +6963,6 @@ module.exports = function () {
|
|
|
6970
6963
|
/**
|
|
6971
6964
|
* Returns all of the enumeration's items (given an enumeration type).
|
|
6972
6965
|
*
|
|
6973
|
-
* @public
|
|
6974
6966
|
* @param {Function} type - The enumeration to list.
|
|
6975
6967
|
* @returns {Array}
|
|
6976
6968
|
*/
|
|
@@ -7428,7 +7420,7 @@ module.exports = function () {
|
|
|
7428
7420
|
* Parses the value emitted by {@link Timestamp#toJSON}.
|
|
7429
7421
|
*
|
|
7430
7422
|
* @public
|
|
7431
|
-
* @param {
|
|
7423
|
+
* @param {String} value
|
|
7432
7424
|
* @returns {Timestamp}
|
|
7433
7425
|
*/
|
|
7434
7426
|
|
|
@@ -8064,7 +8056,7 @@ module.exports = function () {
|
|
|
8064
8056
|
|
|
8065
8057
|
if (typeof itemConstraint === 'function' && itemConstraint !== Function) {
|
|
8066
8058
|
itemValidator = function itemValidator(value, index) {
|
|
8067
|
-
return
|
|
8059
|
+
return value instanceof itemConstraint || itemConstraint(value, variableName + '[' + index + ']');
|
|
8068
8060
|
};
|
|
8069
8061
|
} else {
|
|
8070
8062
|
itemValidator = function itemValidator(value, index) {
|
|
@@ -8174,7 +8166,7 @@ module.exports = function () {
|
|
|
8174
8166
|
*
|
|
8175
8167
|
* @static
|
|
8176
8168
|
* @param {Object} target - The object to check for existence of the property.
|
|
8177
|
-
* @param {String|Array
|
|
8169
|
+
* @param {String|Array<String>} propertyNames - The property to check -- either a string with separators, or an array of strings (already split by separator).
|
|
8178
8170
|
* @param {String=} separator - The separator (defaults to a period character).
|
|
8179
8171
|
* @returns {boolean}
|
|
8180
8172
|
*/
|
|
@@ -8200,7 +8192,7 @@ module.exports = function () {
|
|
|
8200
8192
|
*
|
|
8201
8193
|
* @static
|
|
8202
8194
|
* @param {Object} target - The object to read from.
|
|
8203
|
-
* @param {String|Array
|
|
8195
|
+
* @param {String|Array<String>} propertyNames - The property to read -- either a string with separators, or an array of strings (already split by separator).
|
|
8204
8196
|
* @param {String=} separator - The separator (defaults to a period character).
|
|
8205
8197
|
* @returns {*}
|
|
8206
8198
|
*/
|
|
@@ -8235,8 +8227,7 @@ module.exports = function () {
|
|
|
8235
8227
|
*
|
|
8236
8228
|
* @static
|
|
8237
8229
|
* @param {Object} target - The object to write to.
|
|
8238
|
-
* @param {String|Array
|
|
8239
|
-
* @param {*} value - The value to assign.
|
|
8230
|
+
* @param {String|Array<String>} propertyNames - The property to write -- either a string with separators, or an array of strings (already split by separator).
|
|
8240
8231
|
* @param {String=} separator - The separator (defaults to a period character).
|
|
8241
8232
|
*/
|
|
8242
8233
|
write: function write(target, propertyNames, value, separator) {
|
|
@@ -8262,7 +8253,7 @@ module.exports = function () {
|
|
|
8262
8253
|
*
|
|
8263
8254
|
* @static
|
|
8264
8255
|
* @param {Object} target - The object to erase a property from.
|
|
8265
|
-
* @param {String|Array
|
|
8256
|
+
* @param {String|Array<String>} propertyNames - The property to write -- either a string with separators, or an array of strings (already split by separator).
|
|
8266
8257
|
* @param {String=} separator - The separator (defaults to a period character).
|
|
8267
8258
|
*/
|
|
8268
8259
|
erase: function erase(target, propertyNames, separator) {
|
|
@@ -9515,7 +9506,7 @@ module.exports = function () {
|
|
|
9515
9506
|
}
|
|
9516
9507
|
|
|
9517
9508
|
/**
|
|
9518
|
-
* Generates a function suitable for use by
|
|
9509
|
+
* Generates a function suitable for use by JSON.parse.
|
|
9519
9510
|
*
|
|
9520
9511
|
* @public
|
|
9521
9512
|
* @returns {Function}
|
|
@@ -13640,9 +13631,9 @@ moment.tz.load(require('./data/packed/latest.json'));
|
|
|
13640
13631
|
|
|
13641
13632
|
mom = createUTC([2000, 1]).day(i);
|
|
13642
13633
|
if (strict && !this._fullWeekdaysParse[i]) {
|
|
13643
|
-
this._fullWeekdaysParse[i] = new RegExp('^' + this.weekdays(mom, '').replace('.', '
|
|
13644
|
-
this._shortWeekdaysParse[i] = new RegExp('^' + this.weekdaysShort(mom, '').replace('.', '
|
|
13645
|
-
this._minWeekdaysParse[i] = new RegExp('^' + this.weekdaysMin(mom, '').replace('.', '
|
|
13634
|
+
this._fullWeekdaysParse[i] = new RegExp('^' + this.weekdays(mom, '').replace('.', '\.?') + '$', 'i');
|
|
13635
|
+
this._shortWeekdaysParse[i] = new RegExp('^' + this.weekdaysShort(mom, '').replace('.', '\.?') + '$', 'i');
|
|
13636
|
+
this._minWeekdaysParse[i] = new RegExp('^' + this.weekdaysMin(mom, '').replace('.', '\.?') + '$', 'i');
|
|
13646
13637
|
}
|
|
13647
13638
|
if (!this._weekdaysParse[i]) {
|
|
13648
13639
|
regex = '^' + this.weekdays(mom, '') + '|^' + this.weekdaysShort(mom, '') + '|^' + this.weekdaysMin(mom, '');
|
|
@@ -14445,7 +14436,7 @@ moment.tz.load(require('./data/packed/latest.json'));
|
|
|
14445
14436
|
|
|
14446
14437
|
function preprocessRFC2822(s) {
|
|
14447
14438
|
// Remove comments and folding whitespace and replace multiple-spaces with a single space
|
|
14448
|
-
return s.replace(/\([^)]*\)|[\n\t]/g, ' ').replace(/(\s\s+)/g, ' ').
|
|
14439
|
+
return s.replace(/\([^)]*\)|[\n\t]/g, ' ').replace(/(\s\s+)/g, ' ').trim();
|
|
14449
14440
|
}
|
|
14450
14441
|
|
|
14451
14442
|
function checkWeekday(weekdayStr, parsedInput, config) {
|
|
@@ -16624,7 +16615,7 @@ moment.tz.load(require('./data/packed/latest.json'));
|
|
|
16624
16615
|
// Side effect imports
|
|
16625
16616
|
|
|
16626
16617
|
|
|
16627
|
-
hooks.version = '2.22.
|
|
16618
|
+
hooks.version = '2.22.1';
|
|
16628
16619
|
|
|
16629
16620
|
setHookCallback(createLocal);
|
|
16630
16621
|
|
|
@@ -17256,15 +17247,17 @@ describe('When validating transaction order', () => {
|
|
|
17256
17247
|
expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-04-30'), build(3, '2018-04-30') ])).toEqual(true);
|
|
17257
17248
|
});
|
|
17258
17249
|
|
|
17259
|
-
/*
|
|
17260
17250
|
it('An array of transactions with ordered sequences, on the same day should be valid, where a dividend occurs last, should be valid', () => {
|
|
17261
17251
|
expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-04-30', TransactionType.DIVIDEND) ])).toEqual(true);
|
|
17262
17252
|
});
|
|
17263
17253
|
|
|
17264
|
-
it('An array of transactions with ordered sequences, on the same day should be valid, where a dividend occurs first, should not be valid', () => {
|
|
17265
|
-
expect(TransactionValidator.validateOrder([ build(1, '2018-04-30', TransactionType.DIVIDEND), build(2, '2018-04-30') ])).toEqual(false);
|
|
17254
|
+
it('An array of transactions with ordered sequences, on the same day should be valid, where a dividend occurs first, in strict mode, should not be valid', () => {
|
|
17255
|
+
expect(TransactionValidator.validateOrder([ build(1, '2018-04-30', TransactionType.DIVIDEND), build(2, '2018-04-30') ], true)).toEqual(false);
|
|
17256
|
+
});
|
|
17257
|
+
|
|
17258
|
+
it('An array of transactions with ordered sequences, on the same day should be valid, where a dividend occurs first, in non-strict mode, should be valid', () => {
|
|
17259
|
+
expect(TransactionValidator.validateOrder([ build(1, '2018-04-30', TransactionType.DIVIDEND), build(2, '2018-04-30') ], false)).toEqual(true);
|
|
17266
17260
|
});
|
|
17267
|
-
*/
|
|
17268
17261
|
|
|
17269
17262
|
it('An array of transactions with ordered sequences, on the sequential days should be valid', () => {
|
|
17270
17263
|
expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-05-01'), build(3, '2018-05-02', TransactionType.DIVIDEND) ])).toEqual(true);
|
|
@@ -18,15 +18,17 @@ describe('When validating transaction order', () => {
|
|
|
18
18
|
expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-04-30'), build(3, '2018-04-30') ])).toEqual(true);
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
-
/*
|
|
22
21
|
it('An array of transactions with ordered sequences, on the same day should be valid, where a dividend occurs last, should be valid', () => {
|
|
23
22
|
expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-04-30', TransactionType.DIVIDEND) ])).toEqual(true);
|
|
24
23
|
});
|
|
25
24
|
|
|
26
|
-
it('An array of transactions with ordered sequences, on the same day should be valid, where a dividend occurs first, should not be valid', () => {
|
|
27
|
-
expect(TransactionValidator.validateOrder([ build(1, '2018-04-30', TransactionType.DIVIDEND), build(2, '2018-04-30') ])).toEqual(false);
|
|
25
|
+
it('An array of transactions with ordered sequences, on the same day should be valid, where a dividend occurs first, in strict mode, should not be valid', () => {
|
|
26
|
+
expect(TransactionValidator.validateOrder([ build(1, '2018-04-30', TransactionType.DIVIDEND), build(2, '2018-04-30') ], true)).toEqual(false);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('An array of transactions with ordered sequences, on the same day should be valid, where a dividend occurs first, in non-strict mode, should be valid', () => {
|
|
30
|
+
expect(TransactionValidator.validateOrder([ build(1, '2018-04-30', TransactionType.DIVIDEND), build(2, '2018-04-30') ], false)).toEqual(true);
|
|
28
31
|
});
|
|
29
|
-
*/
|
|
30
32
|
|
|
31
33
|
it('An array of transactions with ordered sequences, on the sequential days should be valid', () => {
|
|
32
34
|
expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-05-01'), build(3, '2018-05-02', TransactionType.DIVIDEND) ])).toEqual(true);
|