ccxt-look 1.81.50
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/.cache/eslintcache +1 -0
- package/.dockerignore +6 -0
- package/.eslintignore +1 -0
- package/.gitattributes +5 -0
- package/.readthedocs.yaml +16 -0
- package/CONTRIBUTING.md +1049 -0
- package/LICENSE.txt +21 -0
- package/README.md +537 -0
- package/SECURITY.md +5 -0
- package/build/cleanup-old-tags.js +94 -0
- package/build/countries.js +256 -0
- package/build/export-exchanges.js +520 -0
- package/build/fs.js +51 -0
- package/build/transpile.js +1772 -0
- package/build/vss.js +78 -0
- package/ccxt.browser.js +7 -0
- package/ccxt.d.ts +692 -0
- package/ccxt.js +171 -0
- package/cleanup.sh +2 -0
- package/composer-install.sh +20 -0
- package/dist/ccxt.browser.js +208383 -0
- package/gource.sh +3 -0
- package/index.html +7 -0
- package/js/.eslintrc +87 -0
- package/js/aax.js +2686 -0
- package/js/ascendex.js +2584 -0
- package/js/base/.eslintrc.js +43 -0
- package/js/base/Exchange.js +2371 -0
- package/js/base/Precise.js +283 -0
- package/js/base/errorHierarchy.js +47 -0
- package/js/base/errors.js +55 -0
- package/js/base/functions/crypto.js +158 -0
- package/js/base/functions/encode.js +118 -0
- package/js/base/functions/generic.js +270 -0
- package/js/base/functions/misc.js +138 -0
- package/js/base/functions/number.js +329 -0
- package/js/base/functions/platform.js +38 -0
- package/js/base/functions/string.js +21 -0
- package/js/base/functions/throttle.js +79 -0
- package/js/base/functions/time.js +210 -0
- package/js/base/functions/type.js +66 -0
- package/js/base/functions.js +28 -0
- package/js/bequant.js +32 -0
- package/js/bibox.js +1407 -0
- package/js/bigone.js +1366 -0
- package/js/binance.js +5652 -0
- package/js/binancecoinm.js +46 -0
- package/js/binanceus.js +46 -0
- package/js/binanceusdm.js +49 -0
- package/js/bit2c.js +535 -0
- package/js/bitbank.js +842 -0
- package/js/bitbay.js +16 -0
- package/js/bitbns.js +1073 -0
- package/js/bitcoincom.js +15 -0
- package/js/bitfinex.js +1433 -0
- package/js/bitfinex2.js +2025 -0
- package/js/bitflyer.js +840 -0
- package/js/bitforex.js +614 -0
- package/js/bitget.js +2397 -0
- package/js/bithumb.js +980 -0
- package/js/bitmart.js +2516 -0
- package/js/bitmex.js +1809 -0
- package/js/bitopro.js +1443 -0
- package/js/bitpanda.js +1782 -0
- package/js/bitrue.js +1747 -0
- package/js/bitso.js +1062 -0
- package/js/bitstamp.js +1757 -0
- package/js/bitstamp1.js +343 -0
- package/js/bittrex.js +1876 -0
- package/js/bitvavo.js +1579 -0
- package/js/bkex.js +1233 -0
- package/js/bl3p.js +346 -0
- package/js/blockchaincom.js +969 -0
- package/js/btcalpha.js +680 -0
- package/js/btcbox.js +477 -0
- package/js/btcmarkets.js +1022 -0
- package/js/btctradeua.js +466 -0
- package/js/btcturk.js +734 -0
- package/js/buda.js +946 -0
- package/js/bw.js +1265 -0
- package/js/bybit.js +3372 -0
- package/js/bytetrade.js +1336 -0
- package/js/cdax.js +1646 -0
- package/js/cex.js +1410 -0
- package/js/coinbase.js +1342 -0
- package/js/coinbaseprime.js +31 -0
- package/js/coinbasepro.js +1466 -0
- package/js/coincheck.js +755 -0
- package/js/coinex.js +3400 -0
- package/js/coinfalcon.js +880 -0
- package/js/coinmate.js +794 -0
- package/js/coinone.js +816 -0
- package/js/coinspot.js +345 -0
- package/js/crex24.js +1636 -0
- package/js/cryptocom.js +1832 -0
- package/js/currencycom.js +1748 -0
- package/js/delta.js +1547 -0
- package/js/deribit.js +2148 -0
- package/js/digifinex.js +1585 -0
- package/js/eqonex.js +1660 -0
- package/js/exmo.js +1670 -0
- package/js/fairdesk.js +1231 -0
- package/js/flowbtc.js +35 -0
- package/js/fmfwio.js +34 -0
- package/js/ftx.js +2751 -0
- package/js/ftxus.js +38 -0
- package/js/gateio.js +4174 -0
- package/js/gemini.js +1397 -0
- package/js/hitbtc.js +1343 -0
- package/js/hitbtc3.js +2329 -0
- package/js/hollaex.js +1486 -0
- package/js/huobi.js +5706 -0
- package/js/huobijp.js +1710 -0
- package/js/huobipro.js +18 -0
- package/js/idex.js +1439 -0
- package/js/independentreserve.js +649 -0
- package/js/indodax.js +742 -0
- package/js/itbit.js +722 -0
- package/js/kraken.js +2179 -0
- package/js/kucoin.js +2571 -0
- package/js/kucoinfutures.js +1771 -0
- package/js/kuna.js +809 -0
- package/js/latoken.js +1445 -0
- package/js/lbank.js +760 -0
- package/js/liquid.js +1432 -0
- package/js/luno.js +873 -0
- package/js/lykke.js +1147 -0
- package/js/mercado.js +771 -0
- package/js/mexc.js +3151 -0
- package/js/ndax.js +2233 -0
- package/js/novadax.js +1318 -0
- package/js/oceanex.js +816 -0
- package/js/okcoin.js +3841 -0
- package/js/okex.js +16 -0
- package/js/okex5.js +16 -0
- package/js/okx.js +4795 -0
- package/js/paymium.js +498 -0
- package/js/phemex.js +2957 -0
- package/js/poloniex.js +1674 -0
- package/js/probit.js +1346 -0
- package/js/qtrade.js +1588 -0
- package/js/ripio.js +1061 -0
- package/js/static_dependencies/BN/bn.js +3526 -0
- package/js/static_dependencies/README.md +1 -0
- package/js/static_dependencies/crypto-js/crypto-js.js +5988 -0
- package/js/static_dependencies/elliptic/lib/elliptic/curve/base.js +375 -0
- package/js/static_dependencies/elliptic/lib/elliptic/curve/edwards.js +433 -0
- package/js/static_dependencies/elliptic/lib/elliptic/curve/index.js +8 -0
- package/js/static_dependencies/elliptic/lib/elliptic/curve/mont.js +180 -0
- package/js/static_dependencies/elliptic/lib/elliptic/curve/short.js +938 -0
- package/js/static_dependencies/elliptic/lib/elliptic/curves.js +204 -0
- package/js/static_dependencies/elliptic/lib/elliptic/ec/index.js +240 -0
- package/js/static_dependencies/elliptic/lib/elliptic/ec/key.js +119 -0
- package/js/static_dependencies/elliptic/lib/elliptic/ec/signature.js +24 -0
- package/js/static_dependencies/elliptic/lib/elliptic/eddsa/index.js +145 -0
- package/js/static_dependencies/elliptic/lib/elliptic/eddsa/key.js +100 -0
- package/js/static_dependencies/elliptic/lib/elliptic/eddsa/signature.js +65 -0
- package/js/static_dependencies/elliptic/lib/elliptic/precomputed/secp256k1.js +780 -0
- package/js/static_dependencies/elliptic/lib/elliptic/utils.js +214 -0
- package/js/static_dependencies/elliptic/lib/elliptic.js +22 -0
- package/js/static_dependencies/elliptic/lib/hmac-drbg/hmac-drbg.js +114 -0
- package/js/static_dependencies/fetch-ponyfill/fetch-node.js +39 -0
- package/js/static_dependencies/node-fetch/index.js +1564 -0
- package/js/static_dependencies/node-rsa/NodeRSA.js +223 -0
- package/js/static_dependencies/node-rsa/asn1/ber/errors.js +13 -0
- package/js/static_dependencies/node-rsa/asn1/ber/index.js +21 -0
- package/js/static_dependencies/node-rsa/asn1/ber/reader.js +262 -0
- package/js/static_dependencies/node-rsa/asn1/ber/types.js +36 -0
- package/js/static_dependencies/node-rsa/asn1/index.js +17 -0
- package/js/static_dependencies/node-rsa/encryptEngines/js.js +34 -0
- package/js/static_dependencies/node-rsa/formats/components.js +71 -0
- package/js/static_dependencies/node-rsa/formats/formats.js +31 -0
- package/js/static_dependencies/node-rsa/formats/pkcs1.js +148 -0
- package/js/static_dependencies/node-rsa/formats/pkcs8.js +187 -0
- package/js/static_dependencies/node-rsa/libs/jsbn.js +1252 -0
- package/js/static_dependencies/node-rsa/libs/rsa.js +147 -0
- package/js/static_dependencies/node-rsa/schemes/pkcs1.js +176 -0
- package/js/static_dependencies/node-rsa/schemes/schemes.js +21 -0
- package/js/static_dependencies/node-rsa/utils.js +98 -0
- package/js/static_dependencies/qs/formats.js +18 -0
- package/js/static_dependencies/qs/index.js +11 -0
- package/js/static_dependencies/qs/parse.js +242 -0
- package/js/static_dependencies/qs/stringify.js +269 -0
- package/js/static_dependencies/qs/utils.js +230 -0
- package/js/stex.js +1925 -0
- package/js/test/.eslintrc.js +42 -0
- package/js/test/Exchange/test.balance.js +61 -0
- package/js/test/Exchange/test.borrowRate.js +32 -0
- package/js/test/Exchange/test.currency.js +52 -0
- package/js/test/Exchange/test.fetchBalance.js +23 -0
- package/js/test/Exchange/test.fetchBorrowInterest.js +59 -0
- package/js/test/Exchange/test.fetchBorrowRate.js +32 -0
- package/js/test/Exchange/test.fetchBorrowRates.js +28 -0
- package/js/test/Exchange/test.fetchClosedOrders.js +32 -0
- package/js/test/Exchange/test.fetchCurrencies.js +35 -0
- package/js/test/Exchange/test.fetchDeposits.js +31 -0
- package/js/test/Exchange/test.fetchFundingFees.js +19 -0
- package/js/test/Exchange/test.fetchFundingRateHistory.js +40 -0
- package/js/test/Exchange/test.fetchL2OrderBook.js +23 -0
- package/js/test/Exchange/test.fetchLedger.js +42 -0
- package/js/test/Exchange/test.fetchLeverageTiers.js +33 -0
- package/js/test/Exchange/test.fetchMarketLeverageTiers.js +22 -0
- package/js/test/Exchange/test.fetchMarkets.js +33 -0
- package/js/test/Exchange/test.fetchMyTrades.js +42 -0
- package/js/test/Exchange/test.fetchOHLCV.js +46 -0
- package/js/test/Exchange/test.fetchOpenOrders.js +36 -0
- package/js/test/Exchange/test.fetchOrderBook.js +25 -0
- package/js/test/Exchange/test.fetchOrderBooks.js +35 -0
- package/js/test/Exchange/test.fetchOrders.js +41 -0
- package/js/test/Exchange/test.fetchPositions.js +47 -0
- package/js/test/Exchange/test.fetchStatus.js +35 -0
- package/js/test/Exchange/test.fetchTicker.js +38 -0
- package/js/test/Exchange/test.fetchTickers.js +49 -0
- package/js/test/Exchange/test.fetchTrades.js +39 -0
- package/js/test/Exchange/test.fetchTradingFee.js +18 -0
- package/js/test/Exchange/test.fetchTradingFees.js +22 -0
- package/js/test/Exchange/test.fetchTransactions.js +31 -0
- package/js/test/Exchange/test.fetchWithdrawals.js +31 -0
- package/js/test/Exchange/test.ledgerItem.js +46 -0
- package/js/test/Exchange/test.leverageTier.js +33 -0
- package/js/test/Exchange/test.loadMarkets.js +35 -0
- package/js/test/Exchange/test.market.js +129 -0
- package/js/test/Exchange/test.ohlcv.js +33 -0
- package/js/test/Exchange/test.order.js +62 -0
- package/js/test/Exchange/test.orderbook.js +61 -0
- package/js/test/Exchange/test.position.js +21 -0
- package/js/test/Exchange/test.throttle.js +94 -0
- package/js/test/Exchange/test.ticker.js +95 -0
- package/js/test/Exchange/test.trade.js +68 -0
- package/js/test/Exchange/test.tradingFee.js +34 -0
- package/js/test/Exchange/test.transaction.js +35 -0
- package/js/test/base/.eslintrc +38 -0
- package/js/test/base/functions/test.crypto.js +110 -0
- package/js/test/base/functions/test.datetime.js +62 -0
- package/js/test/base/functions/test.generic.js +152 -0
- package/js/test/base/functions/test.number.js +362 -0
- package/js/test/base/functions/test.time.js +56 -0
- package/js/test/base/functions/test.type.js +53 -0
- package/js/test/base/test.base.js +193 -0
- package/js/test/errors/test.InsufficientFunds.js +86 -0
- package/js/test/errors/test.InvalidNonce.js +64 -0
- package/js/test/errors/test.InvalidOrder.js +35 -0
- package/js/test/errors/test.OrderNotFound.js +39 -0
- package/js/test/test.js +426 -0
- package/js/test/test.timeout_hang.js +12 -0
- package/js/therock.js +1431 -0
- package/js/tidebit.js +632 -0
- package/js/tidex.js +939 -0
- package/js/timex.js +1283 -0
- package/js/upbit.js +1622 -0
- package/js/vcc.js +1353 -0
- package/js/wavesexchange.js +2185 -0
- package/js/wazirx.js +732 -0
- package/js/whitebit.js +1352 -0
- package/js/woo.js +1577 -0
- package/js/xena.js +1948 -0
- package/js/yobit.js +1129 -0
- package/js/zaif.js +647 -0
- package/js/zb.js +4088 -0
- package/js/zipmex.js +40 -0
- package/js/zonda.js +1497 -0
- package/multilang.sh +159 -0
- package/package.json +591 -0
- package/postinstall.js +103 -0
@@ -0,0 +1,242 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var utils = require('./utils');
|
4
|
+
|
5
|
+
var has = Object.prototype.hasOwnProperty;
|
6
|
+
|
7
|
+
var defaults = {
|
8
|
+
allowDots: false,
|
9
|
+
allowPrototypes: false,
|
10
|
+
arrayLimit: 20,
|
11
|
+
charset: 'utf-8',
|
12
|
+
charsetSentinel: false,
|
13
|
+
comma: false,
|
14
|
+
decoder: utils.decode,
|
15
|
+
delimiter: '&',
|
16
|
+
depth: 5,
|
17
|
+
ignoreQueryPrefix: false,
|
18
|
+
interpretNumericEntities: false,
|
19
|
+
parameterLimit: 1000,
|
20
|
+
parseArrays: true,
|
21
|
+
plainObjects: false,
|
22
|
+
strictNullHandling: false
|
23
|
+
};
|
24
|
+
|
25
|
+
var interpretNumericEntities = function (str) {
|
26
|
+
return str.replace(/&#(\d+);/g, function ($0, numberStr) {
|
27
|
+
return String.fromCharCode(parseInt(numberStr, 10));
|
28
|
+
});
|
29
|
+
};
|
30
|
+
|
31
|
+
// This is what browsers will submit when the ✓ character occurs in an
|
32
|
+
// application/x-www-form-urlencoded body and the encoding of the page containing
|
33
|
+
// the form is iso-8859-1, or when the submitted form has an accept-charset
|
34
|
+
// attribute of iso-8859-1. Presumably also with other charsets that do not contain
|
35
|
+
// the ✓ character, such as us-ascii.
|
36
|
+
var isoSentinel = 'utf8=%26%2310003%3B'; // encodeURIComponent('✓')
|
37
|
+
|
38
|
+
// These are the percent-encoded utf-8 octets representing a checkmark, indicating that the request actually is utf-8 encoded.
|
39
|
+
var charsetSentinel = 'utf8=%E2%9C%93'; // encodeURIComponent('✓')
|
40
|
+
|
41
|
+
var parseValues = function parseQueryStringValues(str, options) {
|
42
|
+
var obj = {};
|
43
|
+
var cleanStr = options.ignoreQueryPrefix ? str.replace(/^\?/, '') : str;
|
44
|
+
var limit = options.parameterLimit === Infinity ? undefined : options.parameterLimit;
|
45
|
+
var parts = cleanStr.split(options.delimiter, limit);
|
46
|
+
var skipIndex = -1; // Keep track of where the utf8 sentinel was found
|
47
|
+
var i;
|
48
|
+
|
49
|
+
var charset = options.charset;
|
50
|
+
if (options.charsetSentinel) {
|
51
|
+
for (i = 0; i < parts.length; ++i) {
|
52
|
+
if (parts[i].indexOf('utf8=') === 0) {
|
53
|
+
if (parts[i] === charsetSentinel) {
|
54
|
+
charset = 'utf-8';
|
55
|
+
} else if (parts[i] === isoSentinel) {
|
56
|
+
charset = 'iso-8859-1';
|
57
|
+
}
|
58
|
+
skipIndex = i;
|
59
|
+
i = parts.length; // The eslint settings do not allow break;
|
60
|
+
}
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
for (i = 0; i < parts.length; ++i) {
|
65
|
+
if (i === skipIndex) {
|
66
|
+
continue;
|
67
|
+
}
|
68
|
+
var part = parts[i];
|
69
|
+
|
70
|
+
var bracketEqualsPos = part.indexOf(']=');
|
71
|
+
var pos = bracketEqualsPos === -1 ? part.indexOf('=') : bracketEqualsPos + 1;
|
72
|
+
|
73
|
+
var key, val;
|
74
|
+
if (pos === -1) {
|
75
|
+
key = options.decoder(part, defaults.decoder, charset);
|
76
|
+
val = options.strictNullHandling ? null : '';
|
77
|
+
} else {
|
78
|
+
key = options.decoder(part.slice(0, pos), defaults.decoder, charset);
|
79
|
+
val = options.decoder(part.slice(pos + 1), defaults.decoder, charset);
|
80
|
+
}
|
81
|
+
|
82
|
+
if (val && options.interpretNumericEntities && charset === 'iso-8859-1') {
|
83
|
+
val = interpretNumericEntities(val);
|
84
|
+
}
|
85
|
+
|
86
|
+
if (val && options.comma && val.indexOf(',') > -1) {
|
87
|
+
val = val.split(',');
|
88
|
+
}
|
89
|
+
|
90
|
+
if (has.call(obj, key)) {
|
91
|
+
obj[key] = utils.combine(obj[key], val);
|
92
|
+
} else {
|
93
|
+
obj[key] = val;
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
return obj;
|
98
|
+
};
|
99
|
+
|
100
|
+
var parseObject = function (chain, val, options) {
|
101
|
+
var leaf = val;
|
102
|
+
|
103
|
+
for (var i = chain.length - 1; i >= 0; --i) {
|
104
|
+
var obj;
|
105
|
+
var root = chain[i];
|
106
|
+
|
107
|
+
if (root === '[]' && options.parseArrays) {
|
108
|
+
obj = [].concat(leaf);
|
109
|
+
} else {
|
110
|
+
obj = options.plainObjects ? Object.create(null) : {};
|
111
|
+
var cleanRoot = root.charAt(0) === '[' && root.charAt(root.length - 1) === ']' ? root.slice(1, -1) : root;
|
112
|
+
var index = parseInt(cleanRoot, 10);
|
113
|
+
if (!options.parseArrays && cleanRoot === '') {
|
114
|
+
obj = { 0: leaf };
|
115
|
+
} else if (
|
116
|
+
!isNaN(index)
|
117
|
+
&& root !== cleanRoot
|
118
|
+
&& String(index) === cleanRoot
|
119
|
+
&& index >= 0
|
120
|
+
&& (options.parseArrays && index <= options.arrayLimit)
|
121
|
+
) {
|
122
|
+
obj = [];
|
123
|
+
obj[index] = leaf;
|
124
|
+
} else {
|
125
|
+
obj[cleanRoot] = leaf;
|
126
|
+
}
|
127
|
+
}
|
128
|
+
|
129
|
+
leaf = obj;
|
130
|
+
}
|
131
|
+
|
132
|
+
return leaf;
|
133
|
+
};
|
134
|
+
|
135
|
+
var parseKeys = function parseQueryStringKeys(givenKey, val, options) {
|
136
|
+
if (!givenKey) {
|
137
|
+
return;
|
138
|
+
}
|
139
|
+
|
140
|
+
// Transform dot notation to bracket notation
|
141
|
+
var key = options.allowDots ? givenKey.replace(/\.([^.[]+)/g, '[$1]') : givenKey;
|
142
|
+
|
143
|
+
// The regex chunks
|
144
|
+
|
145
|
+
var brackets = /(\[[^[\]]*])/;
|
146
|
+
var child = /(\[[^[\]]*])/g;
|
147
|
+
|
148
|
+
// Get the parent
|
149
|
+
|
150
|
+
var segment = brackets.exec(key);
|
151
|
+
var parent = segment ? key.slice(0, segment.index) : key;
|
152
|
+
|
153
|
+
// Stash the parent if it exists
|
154
|
+
|
155
|
+
var keys = [];
|
156
|
+
if (parent) {
|
157
|
+
// If we aren't using plain objects, optionally prefix keys that would overwrite object prototype properties
|
158
|
+
if (!options.plainObjects && has.call(Object.prototype, parent)) {
|
159
|
+
if (!options.allowPrototypes) {
|
160
|
+
return;
|
161
|
+
}
|
162
|
+
}
|
163
|
+
|
164
|
+
keys.push(parent);
|
165
|
+
}
|
166
|
+
|
167
|
+
// Loop through children appending to the array until we hit depth
|
168
|
+
|
169
|
+
var i = 0;
|
170
|
+
while ((segment = child.exec(key)) !== null && i < options.depth) {
|
171
|
+
i += 1;
|
172
|
+
if (!options.plainObjects && has.call(Object.prototype, segment[1].slice(1, -1))) {
|
173
|
+
if (!options.allowPrototypes) {
|
174
|
+
return;
|
175
|
+
}
|
176
|
+
}
|
177
|
+
keys.push(segment[1]);
|
178
|
+
}
|
179
|
+
|
180
|
+
// If there's a remainder, just add whatever is left
|
181
|
+
|
182
|
+
if (segment) {
|
183
|
+
keys.push('[' + key.slice(segment.index) + ']');
|
184
|
+
}
|
185
|
+
|
186
|
+
return parseObject(keys, val, options);
|
187
|
+
};
|
188
|
+
|
189
|
+
var normalizeParseOptions = function normalizeParseOptions(opts) {
|
190
|
+
if (!opts) {
|
191
|
+
return defaults;
|
192
|
+
}
|
193
|
+
|
194
|
+
if (opts.decoder !== null && opts.decoder !== undefined && typeof opts.decoder !== 'function') {
|
195
|
+
throw new TypeError('Decoder has to be a function.');
|
196
|
+
}
|
197
|
+
|
198
|
+
if (typeof opts.charset !== 'undefined' && opts.charset !== 'utf-8' && opts.charset !== 'iso-8859-1') {
|
199
|
+
throw new Error('The charset option must be either utf-8, iso-8859-1, or undefined');
|
200
|
+
}
|
201
|
+
var charset = typeof opts.charset === 'undefined' ? defaults.charset : opts.charset;
|
202
|
+
|
203
|
+
return {
|
204
|
+
allowDots: typeof opts.allowDots === 'undefined' ? defaults.allowDots : !!opts.allowDots,
|
205
|
+
allowPrototypes: typeof opts.allowPrototypes === 'boolean' ? opts.allowPrototypes : defaults.allowPrototypes,
|
206
|
+
arrayLimit: typeof opts.arrayLimit === 'number' ? opts.arrayLimit : defaults.arrayLimit,
|
207
|
+
charset: charset,
|
208
|
+
charsetSentinel: typeof opts.charsetSentinel === 'boolean' ? opts.charsetSentinel : defaults.charsetSentinel,
|
209
|
+
comma: typeof opts.comma === 'boolean' ? opts.comma : defaults.comma,
|
210
|
+
decoder: typeof opts.decoder === 'function' ? opts.decoder : defaults.decoder,
|
211
|
+
delimiter: typeof opts.delimiter === 'string' || utils.isRegExp(opts.delimiter) ? opts.delimiter : defaults.delimiter,
|
212
|
+
depth: typeof opts.depth === 'number' ? opts.depth : defaults.depth,
|
213
|
+
ignoreQueryPrefix: opts.ignoreQueryPrefix === true,
|
214
|
+
interpretNumericEntities: typeof opts.interpretNumericEntities === 'boolean' ? opts.interpretNumericEntities : defaults.interpretNumericEntities,
|
215
|
+
parameterLimit: typeof opts.parameterLimit === 'number' ? opts.parameterLimit : defaults.parameterLimit,
|
216
|
+
parseArrays: opts.parseArrays !== false,
|
217
|
+
plainObjects: typeof opts.plainObjects === 'boolean' ? opts.plainObjects : defaults.plainObjects,
|
218
|
+
strictNullHandling: typeof opts.strictNullHandling === 'boolean' ? opts.strictNullHandling : defaults.strictNullHandling
|
219
|
+
};
|
220
|
+
};
|
221
|
+
|
222
|
+
module.exports = function (str, opts) {
|
223
|
+
var options = normalizeParseOptions(opts);
|
224
|
+
|
225
|
+
if (str === '' || str === null || typeof str === 'undefined') {
|
226
|
+
return options.plainObjects ? Object.create(null) : {};
|
227
|
+
}
|
228
|
+
|
229
|
+
var tempObj = typeof str === 'string' ? parseValues(str, options) : str;
|
230
|
+
var obj = options.plainObjects ? Object.create(null) : {};
|
231
|
+
|
232
|
+
// Iterate over the keys and setup the new object
|
233
|
+
|
234
|
+
var keys = Object.keys(tempObj);
|
235
|
+
for (var i = 0; i < keys.length; ++i) {
|
236
|
+
var key = keys[i];
|
237
|
+
var newObj = parseKeys(key, tempObj[key], options);
|
238
|
+
obj = utils.merge(obj, newObj, options);
|
239
|
+
}
|
240
|
+
|
241
|
+
return utils.compact(obj);
|
242
|
+
};
|
@@ -0,0 +1,269 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var utils = require('./utils');
|
4
|
+
var formats = require('./formats');
|
5
|
+
var has = Object.prototype.hasOwnProperty;
|
6
|
+
|
7
|
+
var arrayPrefixGenerators = {
|
8
|
+
brackets: function brackets(prefix) { // eslint-disable-line func-name-matching
|
9
|
+
return prefix + '[]';
|
10
|
+
},
|
11
|
+
comma: 'comma',
|
12
|
+
indices: function indices(prefix, key) { // eslint-disable-line func-name-matching
|
13
|
+
return prefix + '[' + key + ']';
|
14
|
+
},
|
15
|
+
repeat: function repeat(prefix) { // eslint-disable-line func-name-matching
|
16
|
+
return prefix;
|
17
|
+
}
|
18
|
+
};
|
19
|
+
|
20
|
+
var isArray = Array.isArray;
|
21
|
+
var push = Array.prototype.push;
|
22
|
+
var pushToArray = function (arr, valueOrArray) {
|
23
|
+
push.apply(arr, isArray(valueOrArray) ? valueOrArray : [valueOrArray]);
|
24
|
+
};
|
25
|
+
|
26
|
+
var toISO = Date.prototype.toISOString;
|
27
|
+
|
28
|
+
var defaults = {
|
29
|
+
addQueryPrefix: false,
|
30
|
+
allowDots: false,
|
31
|
+
charset: 'utf-8',
|
32
|
+
charsetSentinel: false,
|
33
|
+
delimiter: '&',
|
34
|
+
encode: true,
|
35
|
+
encoder: utils.encode,
|
36
|
+
encodeValuesOnly: false,
|
37
|
+
formatter: formats.formatters[formats['default']],
|
38
|
+
// deprecated
|
39
|
+
indices: false,
|
40
|
+
serializeDate: function serializeDate(date) { // eslint-disable-line func-name-matching
|
41
|
+
return toISO.call(date);
|
42
|
+
},
|
43
|
+
skipNulls: false,
|
44
|
+
strictNullHandling: false
|
45
|
+
};
|
46
|
+
|
47
|
+
var stringify = function stringify( // eslint-disable-line func-name-matching
|
48
|
+
object,
|
49
|
+
prefix,
|
50
|
+
generateArrayPrefix,
|
51
|
+
strictNullHandling,
|
52
|
+
skipNulls,
|
53
|
+
encoder,
|
54
|
+
filter,
|
55
|
+
sort,
|
56
|
+
allowDots,
|
57
|
+
serializeDate,
|
58
|
+
formatter,
|
59
|
+
encodeValuesOnly,
|
60
|
+
charset
|
61
|
+
) {
|
62
|
+
var obj = object;
|
63
|
+
if (typeof filter === 'function') {
|
64
|
+
obj = filter(prefix, obj);
|
65
|
+
} else if (obj instanceof Date) {
|
66
|
+
obj = serializeDate(obj);
|
67
|
+
} else if (generateArrayPrefix === 'comma' && isArray(obj)) {
|
68
|
+
obj = obj.join(',');
|
69
|
+
}
|
70
|
+
|
71
|
+
if (obj === null) {
|
72
|
+
if (strictNullHandling) {
|
73
|
+
return encoder && !encodeValuesOnly ? encoder(prefix, defaults.encoder, charset) : prefix;
|
74
|
+
}
|
75
|
+
|
76
|
+
obj = '';
|
77
|
+
}
|
78
|
+
|
79
|
+
if (typeof obj === 'string' || typeof obj === 'number' || typeof obj === 'boolean' || utils.isBuffer(obj)) {
|
80
|
+
if (encoder) {
|
81
|
+
var keyValue = encodeValuesOnly ? prefix : encoder(prefix, defaults.encoder, charset);
|
82
|
+
return [formatter(keyValue) + '=' + formatter(encoder(obj, defaults.encoder, charset))];
|
83
|
+
}
|
84
|
+
return [formatter(prefix) + '=' + formatter(String(obj))];
|
85
|
+
}
|
86
|
+
|
87
|
+
var values = [];
|
88
|
+
|
89
|
+
if (typeof obj === 'undefined') {
|
90
|
+
return values;
|
91
|
+
}
|
92
|
+
|
93
|
+
var objKeys;
|
94
|
+
if (isArray(filter)) {
|
95
|
+
objKeys = filter;
|
96
|
+
} else {
|
97
|
+
var keys = Object.keys(obj);
|
98
|
+
objKeys = sort ? keys.sort(sort) : keys;
|
99
|
+
}
|
100
|
+
|
101
|
+
for (var i = 0; i < objKeys.length; ++i) {
|
102
|
+
var key = objKeys[i];
|
103
|
+
|
104
|
+
if (skipNulls && obj[key] === null) {
|
105
|
+
continue;
|
106
|
+
}
|
107
|
+
|
108
|
+
if (isArray(obj)) {
|
109
|
+
pushToArray(values, stringify(
|
110
|
+
obj[key],
|
111
|
+
typeof generateArrayPrefix === 'function' ? generateArrayPrefix(prefix, key) : prefix,
|
112
|
+
generateArrayPrefix,
|
113
|
+
strictNullHandling,
|
114
|
+
skipNulls,
|
115
|
+
encoder,
|
116
|
+
filter,
|
117
|
+
sort,
|
118
|
+
allowDots,
|
119
|
+
serializeDate,
|
120
|
+
formatter,
|
121
|
+
encodeValuesOnly,
|
122
|
+
charset
|
123
|
+
));
|
124
|
+
} else {
|
125
|
+
pushToArray(values, stringify(
|
126
|
+
obj[key],
|
127
|
+
prefix + (allowDots ? '.' + key : '[' + key + ']'),
|
128
|
+
generateArrayPrefix,
|
129
|
+
strictNullHandling,
|
130
|
+
skipNulls,
|
131
|
+
encoder,
|
132
|
+
filter,
|
133
|
+
sort,
|
134
|
+
allowDots,
|
135
|
+
serializeDate,
|
136
|
+
formatter,
|
137
|
+
encodeValuesOnly,
|
138
|
+
charset
|
139
|
+
));
|
140
|
+
}
|
141
|
+
}
|
142
|
+
|
143
|
+
return values;
|
144
|
+
};
|
145
|
+
|
146
|
+
var normalizeStringifyOptions = function normalizeStringifyOptions(opts) {
|
147
|
+
if (!opts) {
|
148
|
+
return defaults;
|
149
|
+
}
|
150
|
+
|
151
|
+
if (opts.encoder !== null && opts.encoder !== undefined && typeof opts.encoder !== 'function') {
|
152
|
+
throw new TypeError('Encoder has to be a function.');
|
153
|
+
}
|
154
|
+
|
155
|
+
var charset = opts.charset || defaults.charset;
|
156
|
+
if (typeof opts.charset !== 'undefined' && opts.charset !== 'utf-8' && opts.charset !== 'iso-8859-1') {
|
157
|
+
throw new TypeError('The charset option must be either utf-8, iso-8859-1, or undefined');
|
158
|
+
}
|
159
|
+
|
160
|
+
var format = formats['default'];
|
161
|
+
if (typeof opts.format !== 'undefined') {
|
162
|
+
if (!has.call(formats.formatters, opts.format)) {
|
163
|
+
throw new TypeError('Unknown format option provided.');
|
164
|
+
}
|
165
|
+
format = opts.format;
|
166
|
+
}
|
167
|
+
var formatter = formats.formatters[format];
|
168
|
+
|
169
|
+
var filter = defaults.filter;
|
170
|
+
if (typeof opts.filter === 'function' || isArray(opts.filter)) {
|
171
|
+
filter = opts.filter;
|
172
|
+
}
|
173
|
+
|
174
|
+
return {
|
175
|
+
addQueryPrefix: typeof opts.addQueryPrefix === 'boolean' ? opts.addQueryPrefix : defaults.addQueryPrefix,
|
176
|
+
allowDots: typeof opts.allowDots === 'undefined' ? defaults.allowDots : !!opts.allowDots,
|
177
|
+
charset: charset,
|
178
|
+
charsetSentinel: typeof opts.charsetSentinel === 'boolean' ? opts.charsetSentinel : defaults.charsetSentinel,
|
179
|
+
delimiter: typeof opts.delimiter === 'undefined' ? defaults.delimiter : opts.delimiter,
|
180
|
+
encode: typeof opts.encode === 'boolean' ? opts.encode : defaults.encode,
|
181
|
+
encoder: typeof opts.encoder === 'function' ? opts.encoder : defaults.encoder,
|
182
|
+
encodeValuesOnly: typeof opts.encodeValuesOnly === 'boolean' ? opts.encodeValuesOnly : defaults.encodeValuesOnly,
|
183
|
+
filter: filter,
|
184
|
+
formatter: formatter,
|
185
|
+
serializeDate: typeof opts.serializeDate === 'function' ? opts.serializeDate : defaults.serializeDate,
|
186
|
+
skipNulls: typeof opts.skipNulls === 'boolean' ? opts.skipNulls : defaults.skipNulls,
|
187
|
+
sort: typeof opts.sort === 'function' ? opts.sort : null,
|
188
|
+
strictNullHandling: typeof opts.strictNullHandling === 'boolean' ? opts.strictNullHandling : defaults.strictNullHandling
|
189
|
+
};
|
190
|
+
};
|
191
|
+
|
192
|
+
module.exports = function (object, opts) {
|
193
|
+
var obj = object;
|
194
|
+
var options = normalizeStringifyOptions(opts);
|
195
|
+
|
196
|
+
var objKeys;
|
197
|
+
var filter;
|
198
|
+
|
199
|
+
if (typeof options.filter === 'function') {
|
200
|
+
filter = options.filter;
|
201
|
+
obj = filter('', obj);
|
202
|
+
} else if (isArray(options.filter)) {
|
203
|
+
filter = options.filter;
|
204
|
+
objKeys = filter;
|
205
|
+
}
|
206
|
+
|
207
|
+
var keys = [];
|
208
|
+
|
209
|
+
if (typeof obj !== 'object' || obj === null) {
|
210
|
+
return '';
|
211
|
+
}
|
212
|
+
|
213
|
+
var arrayFormat;
|
214
|
+
if (opts && opts.arrayFormat in arrayPrefixGenerators) {
|
215
|
+
arrayFormat = opts.arrayFormat;
|
216
|
+
} else if (opts && 'indices' in opts) {
|
217
|
+
arrayFormat = opts.indices ? 'indices' : 'repeat';
|
218
|
+
} else {
|
219
|
+
arrayFormat = 'indices';
|
220
|
+
}
|
221
|
+
|
222
|
+
var generateArrayPrefix = arrayPrefixGenerators[arrayFormat];
|
223
|
+
|
224
|
+
if (!objKeys) {
|
225
|
+
objKeys = Object.keys(obj);
|
226
|
+
}
|
227
|
+
|
228
|
+
if (options.sort) {
|
229
|
+
objKeys.sort(options.sort);
|
230
|
+
}
|
231
|
+
|
232
|
+
for (var i = 0; i < objKeys.length; ++i) {
|
233
|
+
var key = objKeys[i];
|
234
|
+
|
235
|
+
if (options.skipNulls && obj[key] === null) {
|
236
|
+
continue;
|
237
|
+
}
|
238
|
+
pushToArray(keys, stringify(
|
239
|
+
obj[key],
|
240
|
+
key,
|
241
|
+
generateArrayPrefix,
|
242
|
+
options.strictNullHandling,
|
243
|
+
options.skipNulls,
|
244
|
+
options.encode ? options.encoder : null,
|
245
|
+
options.filter,
|
246
|
+
options.sort,
|
247
|
+
options.allowDots,
|
248
|
+
options.serializeDate,
|
249
|
+
options.formatter,
|
250
|
+
options.encodeValuesOnly,
|
251
|
+
options.charset
|
252
|
+
));
|
253
|
+
}
|
254
|
+
|
255
|
+
var joined = keys.join(options.delimiter);
|
256
|
+
var prefix = options.addQueryPrefix === true ? '?' : '';
|
257
|
+
|
258
|
+
if (options.charsetSentinel) {
|
259
|
+
if (options.charset === 'iso-8859-1') {
|
260
|
+
// encodeURIComponent('✓'), the "numeric entity" representation of a checkmark
|
261
|
+
prefix += 'utf8=%26%2310003%3B&';
|
262
|
+
} else {
|
263
|
+
// encodeURIComponent('✓')
|
264
|
+
prefix += 'utf8=%E2%9C%93&';
|
265
|
+
}
|
266
|
+
}
|
267
|
+
|
268
|
+
return joined.length > 0 ? prefix + joined : '';
|
269
|
+
};
|