Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@waves/assets-pairs-order

Package Overview
Dependencies
Maintainers
7
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@waves/assets-pairs-order - npm Package Compare versions

Comparing version 2.3.5 to 3.0.1

src/index.d.ts

91

index.umd.js

@@ -7,47 +7,13 @@ (function (global, factory) {

var slicedToArray = function () {
function sliceIterator(arr, i) {
var _arr = [];
var _n = true;
var _d = false;
var _e = undefined;
var Base58 = require('bs58');
try {
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);
var _require = require('ramda'),
curry = _require.curry;
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally {
try {
if (!_n && _i["return"]) _i["return"]();
} finally {
if (_d) throw _e;
}
}
return _arr;
}
return function (arr, i) {
if (Array.isArray(arr)) {
return arr;
} else if (Symbol.iterator in Object(arr)) {
return sliceIterator(arr, i);
} else {
throw new TypeError("Invalid attempt to destructure non-iterable instance");
}
};
}();
var Base58 = require('bs58');
var MAINNET_RAW_DATA = require('./mainnet.json');
var _require = require('./utils'),
compareUint8Arrays = _require.compareUint8Arrays,
isPair = _require.isPair,
isEmptyArray = _require.isEmptyArray;
var _require2 = require('./utils'),
compareUint8Arrays = _require2.compareUint8Arrays,
isPair = _require2.isPair,
isEmptyArray = _require2.isEmptyArray;

@@ -58,39 +24,5 @@ var MAINNET_DATA = MAINNET_RAW_DATA.map(function (d) {

// Entry point of package
// Check arguments and do the magic
var main = function main() {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
if (!main.predefinedList || !Array.isArray(main.predefinedList)) throw new Error('Incorrect predefined assets list');
if (main.predefinedList.length === 0) console.warn("You have empty predefined assets list. This is probably not, what you desired. Check 'predefinedList' property.");
switch (true) {
case args.length === 0 || isEmptyArray(args[0]):
return [];
case args.length === 2 && isPair(args):
return orderPairs([[args[0], args[1]]]);
case Array.isArray(args[0]) && isPair(args[0][0]):
return orderPairs.apply(undefined, args);
case args.every(function (a) {
return isPair(a);
}):
return orderPairs([].concat(args));
default:
throw new Error('Incorrect arguments: ' + JSON.stringify(args));
}
};
// By default predefinedList is mainNet data
main.predefinedList = MAINNET_DATA;
var orderPairs = function orderPairs(pairs) {
return pairs.map(orderPair);
};
var orderPair = function orderPair(_ref) {
var _ref2 = slicedToArray(_ref, 2),
first = _ref2[0],
second = _ref2[1];
var firstListIndex = main.predefinedList.indexOf(first);
var secondListIndex = main.predefinedList.indexOf(second);
var orderPair = function orderPair(predefinedList, first, second) {
var firstListIndex = predefinedList.indexOf(first);
var secondListIndex = predefinedList.indexOf(second);
var isFirstInList = Boolean(~firstListIndex);

@@ -109,4 +41,5 @@ var isSecondInList = Boolean(~secondListIndex);

};
module.exports = main;
module.exports.createOrderPair = curry(orderPair);
module.exports.MAINNET_DATA = MAINNET_DATA;
})));
{
"name": "@waves/assets-pairs-order",
"version": "2.3.5",
"version": "3.0.1",
"main": "src/index.js",
"types": "src/index.d.ts",
"license": "MIT",

@@ -32,4 +33,5 @@ "repository": {

"dependencies": {
"bs58": "^4.0.1"
"bs58": "^4.0.1",
"ramda": "^0.25.0"
}
}
# Utility for ordering pair of assets in (amount_asset, price_asset)
![Build Status](https://api.travis-ci.org/wavesplatform/assets-pairs-order.svg?branch=master)
## Accepts:
```javascript
orderPairs(string, string)
orderPairs([string, string])
orderPairs([string, string], [string, string], ...)
orderPairs([[string, string], [string, string], ...])
```
## Returns:
```javascript
[
[amount_asset1, price_asset1],
[amount_asset2, price_asset2],
...
]
```
## Example:

@@ -25,4 +9,5 @@ ```

```javascript
import orderPairs from '@waves/assets-pairs-order'
import { createOrderPairs, MAINNET_DATA } from '@waves/assets-pairs-order'
const orderPair = createOrderPairs(MAINNET_DATA);
orderPairs(

@@ -34,42 +19,5 @@ 'DNhP2zAH5HM1kdUSmxcBqs8RP4vvUgRFc1YgAKkfPmPD',

/* [
[
'DNhP2zAH5HM1kdUSmxcBqs8RP4vvUgRFc1YgAKkfPmPD',
'FxSm86qcEw8wGfpX3T7X5fsnuK5XxYA6ZfVYJja29vMA',
]
'DNhP2zAH5HM1kdUSmxcBqs8RP4vvUgRFc1YgAKkfPmPD',
'FxSm86qcEw8wGfpX3T7X5fsnuK5XxYA6ZfVYJja29vMA',
]
*/
// Or you can pass in array of pairs
orderPairs([
['DNhP2zAH5HM1kdUSmxcBqs8RP4vvUgRFc1YgAKkfPmPD', 'FxSm86qcEw8wGfpX3T7X5fsnuK5XxYA6ZfVYJja29vMA'],
['FxSm86qcEw8wGfpX3T7X5fsnuK5XxYA6ZfVYJja29vMA','DNhP2zAH5HM1kdUSmxcBqs8RP4vvUgRFc1YgAKkfPmPD']
])
/* [
[
'DNhP2zAH5HM1kdUSmxcBqs8RP4vvUgRFc1YgAKkfPmPD',
'FxSm86qcEw8wGfpX3T7X5fsnuK5XxYA6ZfVYJja29vMA',
],
[
'DNhP2zAH5HM1kdUSmxcBqs8RP4vvUgRFc1YgAKkfPmPD',
'FxSm86qcEw8wGfpX3T7X5fsnuK5XxYA6ZfVYJja29vMA',
]
]
*/
```
You can redefine `predefinedList` property:
(By default it's MAINNET_DATA)
```javascript
import orderPairs from '@waves/assets-pairs-order';
orderPairs.predefinedList = ['2', '1'];
orderPairs([['1','2']])
/* [
[
'1',
'2',
]
]
*/
```

@@ -1,6 +0,8 @@

import orderPairs from '../';
import { createOrderPair, MAINNET_DATA } from '../';
import { compareUint8Arrays } from '../utils';
import { equal } from 'assert';
describe('OrderPairs utility', () => {
const orderPair = createOrderPair(MAINNET_DATA);
describe('orderPair utility', () => {
/**

@@ -10,9 +12,10 @@ * Simple tests for proof-of-existence

it('is function', () => {
expect(typeof orderPairs).toBe('function');
expect(typeof orderPair).toBe('function');
});
it('is callable without arguments', () => {
expect(() => orderPairs()).not.toThrow();
expect(() => orderPair()).not.toThrow();
});
it('has both default and named exports', () => {
expect(orderPairs).toBeDefined();
expect(createOrderPair).toBeDefined();
expect(MAINNET_DATA).toBeDefined();
expect(compareUint8Arrays).toBeDefined();

@@ -24,37 +27,6 @@ });

*/
it('accepts ([[string, string]])', () => {
expect(() =>
orderPairs([
[
'CrztSP3dRxLaXq4odFyDQ3w1nuRmqPZhFW6ib7JMo6Vt',
'CrztSP3dRxLaXq4odFyDQ3w1nuRmqPZhFW6ib7JMo6Vt',
],
])
).not.toThrow();
});
it('accepts ([string, string])', () => {
expect(() =>
orderPairs([
'FxSm86qcEw8wGfpX3T7X5fsnuK5XxYA6ZfVYJja29vMA',
'DNhP2zAH5HM1kdUSmxcBqs8RP4vvUgRFc1YgAKkfPmPD',
])
).not.toThrow();
});
it('accepts ([string, string], [string, string])', () => {
expect(() =>
orderPairs(
[
'FxSm86qcEw8wGfpX3T7X5fsnuK5XxYA6ZfVYJja29vMA',
'DNhP2zAH5HM1kdUSmxcBqs8RP4vvUgRFc1YgAKkfPmPD',
],
[
'FxSm86qcEw8wGfpX3T7X5fsnuK5XxYA6ZfVYJja29vMA',
'DNhP2zAH5HM1kdUSmxcBqs8RP4vvUgRFc1YgAKkfPmPD',
]
)
).not.toThrow();
});
it('accepts (string, string)', () => {
expect(() =>
orderPairs(
orderPair(
'FxSm86qcEw8wGfpX3T7X5fsnuK5XxYA6ZfVYJja29vMA',

@@ -65,18 +37,8 @@ 'DNhP2zAH5HM1kdUSmxcBqs8RP4vvUgRFc1YgAKkfPmPD'

expect(
orderPairs(
orderPair(
'FxSm86qcEw8wGfpX3T7X5fsnuK5XxYA6ZfVYJja29vMA',
'DNhP2zAH5HM1kdUSmxcBqs8RP4vvUgRFc1YgAKkfPmPD'
)[0]
)
).toHaveLength(2);
});
it('accepts ([])', () => {
expect(() => orderPairs([])).not.toThrow();
expect(orderPairs([])).toEqual([]);
});
it("doesn't accept other types", () => {
expect(() => orderPairs(NaN, null)).toThrow();
expect(() => orderPairs(1, 2)).toThrow();
expect(() => orderPairs([1, 2])).toThrow();
expect(() => orderPairs([[1, 2]])).toThrow();
});

@@ -88,3 +50,3 @@ /**

expect(
orderPairs(
orderPair(
'Ft8X1v1LTa1ABafufpaCWyVj8KkaxUWE6xBhW6sNFJck',

@@ -94,6 +56,4 @@ 'Gtb1WRznfchDnTh37ezoDTJ4wcoKaRsKqKjJjy7nm2zU'

).toEqual([
[
'Gtb1WRznfchDnTh37ezoDTJ4wcoKaRsKqKjJjy7nm2zU',
'Ft8X1v1LTa1ABafufpaCWyVj8KkaxUWE6xBhW6sNFJck',
],
'Gtb1WRznfchDnTh37ezoDTJ4wcoKaRsKqKjJjy7nm2zU',
'Ft8X1v1LTa1ABafufpaCWyVj8KkaxUWE6xBhW6sNFJck',
]);

@@ -103,3 +63,3 @@ });

expect(
orderPairs(
orderPair(
'Gtb1WRznfchDnTh37ezoDTJ4wcoKaRsKqKjJjy7nm2zU',

@@ -109,6 +69,4 @@ 'Ft8X1v1LTa1ABafufpaCWyVj8KkaxUWE6xBhW6sNFJck'

).toEqual([
[
'Gtb1WRznfchDnTh37ezoDTJ4wcoKaRsKqKjJjy7nm2zU',
'Ft8X1v1LTa1ABafufpaCWyVj8KkaxUWE6xBhW6sNFJck',
],
'Gtb1WRznfchDnTh37ezoDTJ4wcoKaRsKqKjJjy7nm2zU',
'Ft8X1v1LTa1ABafufpaCWyVj8KkaxUWE6xBhW6sNFJck',
]);

@@ -118,3 +76,3 @@ });

expect(
orderPairs(
orderPair(
'Gtb1WRznfchDnTh37ezoDTJ4wcoKaRsKqKjJjy7nm2zU',

@@ -124,6 +82,4 @@ 'FxSm86qcEw8wGfpX3T7X5fsnuK5XxYA6ZfVYJja29vMA'

).toEqual([
[
'FxSm86qcEw8wGfpX3T7X5fsnuK5XxYA6ZfVYJja29vMA',
'Gtb1WRznfchDnTh37ezoDTJ4wcoKaRsKqKjJjy7nm2zU',
],
'FxSm86qcEw8wGfpX3T7X5fsnuK5XxYA6ZfVYJja29vMA',
'Gtb1WRznfchDnTh37ezoDTJ4wcoKaRsKqKjJjy7nm2zU',
]);

@@ -133,3 +89,3 @@ });

expect(
orderPairs(
orderPair(
'FxSm86qcEw8wGfpX3T7X5fsnuK5XxYA6ZfVYJja29vMA',

@@ -139,6 +95,4 @@ 'Gtb1WRznfchDnTh37ezoDTJ4wcoKaRsKqKjJjy7nm2zU'

).toEqual([
[
'FxSm86qcEw8wGfpX3T7X5fsnuK5XxYA6ZfVYJja29vMA',
'Gtb1WRznfchDnTh37ezoDTJ4wcoKaRsKqKjJjy7nm2zU',
],
'FxSm86qcEw8wGfpX3T7X5fsnuK5XxYA6ZfVYJja29vMA',
'Gtb1WRznfchDnTh37ezoDTJ4wcoKaRsKqKjJjy7nm2zU',
]);

@@ -148,3 +102,3 @@ });

expect(
orderPairs(
orderPair(
'FxSm86qcEw8wGfpX3T7X5fsnuK5XxYA6ZfVYJja29vMA',

@@ -154,6 +108,4 @@ 'DNhP2zAH5HM1kdUSmxcBqs8RP4vvUgRFc1YgAKkfPmPD'

).toEqual([
[
'DNhP2zAH5HM1kdUSmxcBqs8RP4vvUgRFc1YgAKkfPmPD',
'FxSm86qcEw8wGfpX3T7X5fsnuK5XxYA6ZfVYJja29vMA',
],
'DNhP2zAH5HM1kdUSmxcBqs8RP4vvUgRFc1YgAKkfPmPD',
'FxSm86qcEw8wGfpX3T7X5fsnuK5XxYA6ZfVYJja29vMA',
]);

@@ -163,3 +115,3 @@ });

expect(
orderPairs(
orderPair(
'DNhP2zAH5HM1kdUSmxcBqs8RP4vvUgRFc1YgAKkfPmPD',

@@ -169,6 +121,4 @@ 'FxSm86qcEw8wGfpX3T7X5fsnuK5XxYA6ZfVYJja29vMA'

).toEqual([
[
'DNhP2zAH5HM1kdUSmxcBqs8RP4vvUgRFc1YgAKkfPmPD',
'FxSm86qcEw8wGfpX3T7X5fsnuK5XxYA6ZfVYJja29vMA',
],
'DNhP2zAH5HM1kdUSmxcBqs8RP4vvUgRFc1YgAKkfPmPD',
'FxSm86qcEw8wGfpX3T7X5fsnuK5XxYA6ZfVYJja29vMA',
]);

@@ -178,15 +128,13 @@ });

expect(
orderPairs(['Ft8X1v1LTa1ABafufpaCWyVj8KkaxUWE6xBhW6sNFJck', 'WAVES'])
).toEqual([['WAVES', 'Ft8X1v1LTa1ABafufpaCWyVj8KkaxUWE6xBhW6sNFJck']]);
orderPair('Ft8X1v1LTa1ABafufpaCWyVj8KkaxUWE6xBhW6sNFJck', 'WAVES')
).toEqual(['WAVES', 'Ft8X1v1LTa1ABafufpaCWyVj8KkaxUWE6xBhW6sNFJck']);
});
it('orders [WAVES, USD] in [WAVES, USD]', () => {
expect(
orderPairs(['WAVES', 'Ft8X1v1LTa1ABafufpaCWyVj8KkaxUWE6xBhW6sNFJck'])
).toEqual([['WAVES', 'Ft8X1v1LTa1ABafufpaCWyVj8KkaxUWE6xBhW6sNFJck']]);
orderPair('WAVES', 'Ft8X1v1LTa1ABafufpaCWyVj8KkaxUWE6xBhW6sNFJck')
).toEqual(['WAVES', 'Ft8X1v1LTa1ABafufpaCWyVj8KkaxUWE6xBhW6sNFJck']);
});
it('works with custom predefinedList', () => {
let prevList = orderPairs.predefinedList;
orderPairs.predefinedList = ['1', '2'];
expect(orderPairs(['2', '1'])).toEqual([['2', '1']]);
orderPairs.predefinedList = prevList;
const customOrderPair = createOrderPair(['1', '2']);
expect(customOrderPair('2', '1')).toEqual(['2', '1']);
});

@@ -193,0 +141,0 @@ });

const Base58 = require('bs58');
const { curry } = require('ramda');
const MAINNET_RAW_DATA = require('./mainnet.json');

@@ -6,31 +7,5 @@ const { compareUint8Arrays, isPair, isEmptyArray } = require('./utils');

// Entry point of package
// Check arguments and do the magic
const main = (...args) => {
if (!main.predefinedList || !Array.isArray(main.predefinedList))
throw new Error('Incorrect predefined assets list');
if (main.predefinedList.length === 0)
console.warn(
"You have empty predefined assets list. This is probably not, what you desired. Check 'predefinedList' property."
);
switch (true) {
case args.length === 0 || isEmptyArray(args[0]):
return [];
case args.length === 2 && isPair(args):
return orderPairs([[args[0], args[1]]]);
case Array.isArray(args[0]) && isPair(args[0][0]):
return orderPairs(...args);
case args.every(a => isPair(a)):
return orderPairs([...args]);
default:
throw new Error(`Incorrect arguments: ${JSON.stringify(args)}`);
}
};
// By default predefinedList is mainNet data
main.predefinedList = MAINNET_DATA;
const orderPairs = pairs => pairs.map(orderPair);
const orderPair = ([first, second]) => {
const firstListIndex = main.predefinedList.indexOf(first);
const secondListIndex = main.predefinedList.indexOf(second);
const orderPair = (predefinedList, first, second) => {
const firstListIndex = predefinedList.indexOf(first);
const secondListIndex = predefinedList.indexOf(second);
const isFirstInList = Boolean(~firstListIndex);

@@ -53,2 +28,3 @@ const isSecondInList = Boolean(~secondListIndex);

};
module.exports = main;
module.exports.createOrderPair = curry(orderPair);
module.exports.MAINNET_DATA = MAINNET_DATA;

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc