redis 3.0.0 → 3.1.1

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.
Files changed (54) hide show
  1. package/.deepsource.toml +9 -0
  2. package/CHANGELOG.md +1 -0
  3. package/LICENSE +1 -1
  4. package/README.md +25 -21
  5. package/heroku/index.js +14 -0
  6. package/heroku/node_modules/.package-lock.json +57 -0
  7. package/heroku/node_modules/denque/CHANGELOG.md +4 -0
  8. package/heroku/node_modules/denque/LICENSE +13 -0
  9. package/heroku/node_modules/denque/README.md +362 -0
  10. package/heroku/node_modules/denque/index.d.ts +31 -0
  11. package/heroku/node_modules/denque/index.js +443 -0
  12. package/heroku/node_modules/denque/package.json +55 -0
  13. package/heroku/node_modules/redis/.deepsource.toml +9 -0
  14. package/heroku/node_modules/redis/CHANGELOG.md +880 -0
  15. package/heroku/node_modules/redis/LICENSE +24 -0
  16. package/heroku/node_modules/redis/README.md +1009 -0
  17. package/heroku/node_modules/redis/a.js +12 -0
  18. package/heroku/node_modules/redis/index.js +1039 -0
  19. package/heroku/node_modules/redis/lib/command.js +16 -0
  20. package/heroku/node_modules/redis/lib/commands.js +105 -0
  21. package/heroku/node_modules/redis/lib/createClient.js +88 -0
  22. package/heroku/node_modules/redis/lib/customErrors.js +58 -0
  23. package/heroku/node_modules/redis/lib/debug.js +13 -0
  24. package/heroku/node_modules/redis/lib/extendedApi.js +113 -0
  25. package/heroku/node_modules/redis/lib/individualCommands.js +629 -0
  26. package/heroku/node_modules/redis/lib/multi.js +187 -0
  27. package/heroku/node_modules/redis/lib/utils.js +134 -0
  28. package/heroku/node_modules/redis/npm +0 -0
  29. package/heroku/node_modules/redis/package.json +77 -0
  30. package/heroku/node_modules/redis-commands/LICENSE +22 -0
  31. package/heroku/node_modules/redis-commands/README.md +51 -0
  32. package/heroku/node_modules/redis-commands/changelog.md +83 -0
  33. package/heroku/node_modules/redis-commands/commands.json +2334 -0
  34. package/heroku/node_modules/redis-commands/index.js +168 -0
  35. package/heroku/node_modules/redis-commands/package.json +41 -0
  36. package/heroku/node_modules/redis-commands/tools/build.js +62 -0
  37. package/heroku/node_modules/redis-errors/LICENSE +22 -0
  38. package/heroku/node_modules/redis-errors/README.md +116 -0
  39. package/heroku/node_modules/redis-errors/index.js +7 -0
  40. package/heroku/node_modules/redis-errors/lib/modern.js +59 -0
  41. package/heroku/node_modules/redis-errors/lib/old.js +119 -0
  42. package/heroku/node_modules/redis-errors/package.json +41 -0
  43. package/heroku/node_modules/redis-parser/LICENSE +22 -0
  44. package/heroku/node_modules/redis-parser/README.md +166 -0
  45. package/heroku/node_modules/redis-parser/changelog.md +156 -0
  46. package/heroku/node_modules/redis-parser/index.js +3 -0
  47. package/heroku/node_modules/redis-parser/lib/parser.js +552 -0
  48. package/heroku/node_modules/redis-parser/package.json +53 -0
  49. package/heroku/package.json +9 -0
  50. package/index.js +8 -19
  51. package/lib/createClient.js +5 -1
  52. package/lib/individualCommands.js +19 -7
  53. package/lib/utils.js +1 -1
  54. package/package.json +15 -13
@@ -0,0 +1,9 @@
1
+ version = 1
2
+ exclude_patterns = ["examples/**"]
3
+
4
+ [[analyzers]]
5
+ name = "javascript"
6
+ enabled = true
7
+
8
+ [analyzers.meta]
9
+ environment = ["nodejs"]
package/CHANGELOG.md CHANGED
@@ -28,6 +28,7 @@ a lot of old deprecated features and old internals in preparation for an upcomin
28
28
  - Replaced `double-ended-queue` with `denque`, which brings performance improvements
29
29
  - Add timestamps to debug traces
30
30
  - Add `socket_initial_delay` option for `socket.setKeepAlive` (#1396)
31
+ - Add support for `rediss` protocol in url (#1282)
31
32
 
32
33
  ## v2.8.0 - 31 Jul, 2017
33
34
 
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) Node Redis contributors.
3
+ Copyright (c) 2016-present Node Redis contributors.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person
6
6
  obtaining a copy of this software and associated documentation
package/README.md CHANGED
@@ -9,12 +9,14 @@
9
9
  ---
10
10
 
11
11
  <p align="center">
12
- <a href="https://www.npmjs.com/package/redis"><img src="https://img.shields.io/npm/dm/redis.svg?style=flat-square" alt="NPM downloads"></a>
13
- <a href="https://www.npmjs.com/package/redis"><img src="https://img.shields.io/npm/v/redis.svg?style=flat-square" alt="NPM version"></a>
14
- <a href="https://travis-ci.org/NodeRedis/node-redis"><img src="https://travis-ci.org/NodeRedis/node-redis.svg?style=flat-square&branch=master" alt="Build Status" /></a>
15
- <a href="https://ci.appveyor.com/project/BridgeAR/node-redis/branch/master"><img src="https://img.shields.io/appveyor/ci/BridgeAR/node-redis/master.svg?style=flat-square&label=Windows%20Tests" alt="Windows Tests" /></a>
16
- <a href="https://coveralls.io/r/NodeRedis/node-redis?branch="><img src="https://coveralls.io/repos/NodeRedis/node-redis/badge.svg?style=flat-square&branch=" alt="Coverage Status" /></a>
17
- <a href="https://twitter.com/NodeRedis"><img src="https://img.shields.io/twitter/follow/NodeRedis.svg?style=flat-square&colorA=1da1f2&colorB=&label=Follow%20on%20Twitter" alt="Follow on Twitter"></a>
12
+ <a href="https://www.npmjs.com/package/redis"><img src="https://img.shields.io/npm/dm/redis.svg" alt="NPM downloads"></a>
13
+ <a href="https://www.npmjs.com/package/redis"><img src="https://img.shields.io/npm/v/redis.svg" alt="NPM version"></a>
14
+ <a href="https://github.com/NodeRedis/node-redis/actions?query=workflow%3ATests"><img src="https://github.com/NodeRedis/node-redis/workflows/Tests/badge.svg" alt="Build Status" /></a>
15
+ <a href="https://github.com/NodeRedis/node-redis/actions?query=workflow%3A%22Tests+Windows%22"><img src="https://github.com/NodeRedis/node-redis/workflows/Tests%20Windows/badge.svg" alt="Windows Build Status" /></a>
16
+ <a href="https://coveralls.io/r/NodeRedis/node-redis?branch="><img src="https://coveralls.io/repos/NodeRedis/node-redis/badge.svg?branch=master" alt="Coverage Status" /></a>
17
+ <a href="https://codeclimate.com/github/NodeRedis/node-redis/maintainability"><img src="https://api.codeclimate.com/v1/badges/f6d7063243c234237e73/maintainability" /></a>
18
+ <a href="https://lgtm.com/projects/g/NodeRedis/node-redis/context:javascript"><img src="https://img.shields.io/lgtm/grade/javascript/g/NodeRedis/node-redis.svg?logo=lgtm&logoWidth=18" alt="Coverage Status" /></a>
19
+ <a href="https://discord.gg/XMMVgxUm"><img src="https://img.shields.io/discord/697882427875393627?style=flat-square" /></a>
18
20
  </p>
19
21
 
20
22
  ---
@@ -171,15 +173,16 @@ using unix sockets if possible to increase throughput.
171
173
  | port | 6379 | Port of the Redis server |
172
174
  | path | null | The UNIX socket string of the Redis server |
173
175
  | url | null | The URL of the Redis server. Format: `[redis[s]:]//[[user][:password@]][host][:port][/db-number][?db=db-number[&password=bar[&option=value]]]` (More info avaliable at [IANA](http://www.iana.org/assignments/uri-schemes/prov/redis)). |
174
- | string_numbers | null | Set to `true`, Node Redis will return Redis number values as Strings instead of javascript Numbers. Useful if you need to handle big numbers (above `Number.MAX_SAFE_INTEGER === 2^53`). Hiredis is incapable of this behavior, so setting this option to `true` will result in the built-in javascript parser being used no matter the value of the `parser` option. |
176
+ | string_numbers | null | Set to `true`, Node Redis will return Redis number values as Strings instead of javascript Numbers. Useful if you need to handle big numbers (above `Number.MAX_SAFE_INTEGER === 2^53`). Hiredis is incapable of this behavior, so setting this option to `true` will result in the built-in javascript parser being used no matter the value of the `parser` option. |
175
177
  | return_buffers | false | If set to `true`, then all replies will be sent to callbacks as Buffers instead of Strings. |
176
178
  | detect_buffers | false | If set to `true`, then replies will be sent to callbacks as Buffers. This option lets you switch between Buffers and Strings on a per-command basis, whereas `return_buffers` applies to every command on a client. **Note**: This doesn't work properly with the pubsub mode. A subscriber has to either always return Strings or Buffers. |
177
179
  | socket_keepalive | true | If set to `true`, the keep-alive functionality is enabled on the underlying socket. |
178
180
  | socket_initial_delay | 0 | Initial Delay in milliseconds, and this will also behave the interval keep alive message sending to Redis. |
179
- | no_ready_check | false | When a connection is established to the Redis server, the server might still be loading the database from disk. While loading, the server will not respond to any commands. To work around this, Node Redis has a "ready check" which sends the `INFO` command to the server. The response from the `INFO` command indicates whether the server is ready for more commands. When ready, `node_redis` emits a `ready` event. Setting `no_ready_check` to `true` will inhibit this check. |
181
+ | no_ready_check | false | When a connection is established to the Redis server, the server might still be loading the database from disk. While loading, the server will not respond to any commands. To work around this, Node Redis has a "ready check" which sends the `INFO` command to the server. The response from the `INFO` command indicates whether the server is ready for more commands. When ready, `node_redis` emits a `ready` event. Setting `no_ready_check` to `true` will inhibit this check. |
180
182
  | enable_offline_queue | true | By default, if there is no active connection to the Redis server, commands are added to a queue and are executed once the connection has been established. Setting `enable_offline_queue` to `false` will disable this feature and the callback will be executed immediately with an error, or an error will be emitted if no callback is specified. |
181
183
  | retry_unfulfilled_commands | false | If set to `true`, all commands that were unfulfilled while the connection is lost will be retried after the connection has been reestablished. Use this with caution if you use state altering commands (e.g. `incr`). This is especially useful if you use blocking commands. |
182
- | password | null | If set, client will run Redis auth command on connect. Alias `auth_pass` **Note** Node Redis < 2.5 must use `auth_pass` |
184
+ | password | null | If set, client will run Redis auth command on connect. Alias `auth_pass` **Note** Node Redis < 2.5 must use `auth_pass` |
185
+ | user | null | The ACL user (only valid when `password` is set) |
183
186
  | db | null | If set, client will run Redis `select` command on connect. |
184
187
  | family | IPv4 | You can force using IPv6 if you set the family to 'IPv6'. See Node.js [net](https://nodejs.org/api/net.html) or [dns](https://nodejs.org/api/dns.html) modules on how to use the family type. |
185
188
  | disable_resubscribing | false | If set to `true`, a client won't resubscribe after disconnecting. |
@@ -187,6 +190,7 @@ using unix sockets if possible to increase throughput.
187
190
  | tls | null | An object containing options to pass to [tls.connect](http://nodejs.org/api/tls.html#tls_tls_connect_port_host_options_callback) to set up a TLS connection to Redis (if, for example, it is set up to be accessible via a tunnel). |
188
191
  | prefix | null | A string used to prefix all used keys (e.g. `namespace:test`). Please be aware that the `keys` command will not be prefixed. The `keys` command has a "pattern" as argument and no key and it would be impossible to determine the existing keys in Redis if this would be prefixed. |
189
192
  | retry_strategy | function | A function that receives an options object as parameter including the retry `attempt`, the `total_retry_time` indicating how much time passed since the last time connected, the `error` why the connection was lost and the number of `times_connected` in total. If you return a number from this function, the retry will happen exactly after that time in milliseconds. If you return a non-number, no further retry will happen and all offline commands are flushed with errors. Return an error to return that specific error to all offline commands. Example below. |
193
+ | connect_timeout | 3600000 | In milliseconds. This should only be the timeout for connecting to redis, but for now it interferes with `retry_strategy` and stops it from reconnecting after this timeout. |
190
194
 
191
195
  **`detect_buffers` example:**
192
196
 
@@ -210,7 +214,7 @@ client.get(new Buffer("foo_rand000000000000"), function(err, reply) {
210
214
  **`retry_strategy` example:**
211
215
 
212
216
  ```js
213
- var client = redis.createClient({
217
+ const client = redis.createClient({
214
218
  retry_strategy: function(options) {
215
219
  if (options.error && options.error.code === "ECONNREFUSED") {
216
220
  // End reconnecting on a specific error and flush all commands with
@@ -394,7 +398,7 @@ responses using JavaScript syntax.
394
398
  ```js
395
399
  client.hmset("key", "foo", "bar", "hello", "world");
396
400
 
397
- client.hgetall("hosts", function(err, value) {
401
+ client.hgetall("key", function(err, value) {
398
402
  console.log(value.foo); // > "bar"
399
403
  console.log(value.hello); // > "world"
400
404
  });
@@ -638,7 +642,7 @@ client.watch("foo", function(watchError) {
638
642
  * If err is null, it means Redis successfully attempted
639
643
  * the operation.
640
644
  */
641
- if (execError) throw err;
645
+ if (execError) throw execError;
642
646
 
643
647
  /**
644
648
  * If results === null, it means that a concurrent client
@@ -675,12 +679,12 @@ clients.watcher.watch("foo", function(watchError) {
675
679
 
676
680
  // if you comment out the next line, the transaction will work
677
681
  clients.modifier.set("foo", Math.random(), setError => {
678
- if (setError) throw err;
682
+ if (setError) throw setError;
679
683
  });
680
684
 
681
- //using a setTimeout here to ensure that the MULTI/EXEC will come after the SET.
682
- //Normally, you would use a callback to ensure order, but I want the above SET command
683
- //to be easily comment-out-able.
685
+ // using a setTimeout here to ensure that the MULTI/EXEC will come after the SET.
686
+ // Normally, you would use a callback to ensure order, but I want the above SET command
687
+ // to be easily comment-out-able.
684
688
  setTimeout(function() {
685
689
  clients.watcher
686
690
  .multi()
@@ -840,26 +844,26 @@ returns it in the callback. If an error occurs in the meanwhile, that is going
840
844
  to return an error instead in the callback.
841
845
 
842
846
  One example of when to use duplicate() would be to accommodate the connection-
843
- blocking redis commands BRPOP, BLPOP, and BRPOPLPUSH. If these commands
847
+ blocking redis commands `BRPOP`, `BLPOP`, and `BRPOPLPUSH`. If these commands
844
848
  are used on the same Redis client instance as non-blocking commands, the
845
849
  non-blocking ones may be queued up until after the blocking ones finish.
846
850
 
847
851
  Another reason to use duplicate() is when multiple DBs on the same server are
848
852
  accessed via the redis SELECT command. Each DB could use its own connection.
849
853
 
850
- ### `client.send_command(command_name[, [args][, callback]])`
854
+ ### `client.sendCommand(command_name[, [args][, callback]])`
851
855
 
852
856
  All Redis commands have been added to the `client` object. However, if new
853
857
  commands are introduced before this library is updated or if you want to add
854
- individual commands you can use `send_command()` to send arbitrary commands to
858
+ individual commands you can use `sendCommand()` to send arbitrary commands to
855
859
  Redis.
856
860
 
857
861
  All commands are sent as multi-bulk commands. `args` can either be an Array of
858
862
  arguments, or omitted / set to undefined.
859
863
 
860
- ### `redis.add_command(command_name)`
864
+ ### `redis.addCommand(command_name)`
861
865
 
862
- Calling add_command will add a new command to the prototype. The exact command
866
+ Calling addCommand will add a new command to the prototype. The exact command
863
867
  name will be used when calling using this new command. Using arbitrary arguments
864
868
  is possible as with any other command.
865
869
 
@@ -0,0 +1,14 @@
1
+ const redis = require("redis");
2
+ const client = redis.createClient(process.env.REDISCLOUD_URL);
3
+
4
+ console.log(process.env.REDISCLOUD_URL);
5
+
6
+ setInterval(() => {
7
+ client.get('a', (err, result) => {
8
+ if (err) {
9
+ return console.error(err);
10
+ }
11
+
12
+ console.log(result);
13
+ })
14
+ }, 3000);
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "heroku",
3
+ "lockfileVersion": 2,
4
+ "requires": true,
5
+ "packages": {
6
+ "node_modules/denque": {
7
+ "version": "1.5.0",
8
+ "resolved": "https://registry.npmjs.org/denque/-/denque-1.5.0.tgz",
9
+ "integrity": "sha512-CYiCSgIF1p6EUByQPlGkKnP1M9g0ZV3qMIrqMqZqdwazygIA/YP2vrbcyl1h/WppKJTdl1F85cXIle+394iDAQ==",
10
+ "engines": {
11
+ "node": ">=0.10"
12
+ }
13
+ },
14
+ "node_modules/redis": {
15
+ "version": "3.1.0",
16
+ "resolved": "https://registry.npmjs.org/redis/-/redis-3.1.0.tgz",
17
+ "integrity": "sha512-//lAOcEtNIKk2ekZibes5oyWKYUVWMvMB71lyD/hS9KRePNkB7AU3nXGkArX6uDKEb2N23EyJBthAv6pagD0uw==",
18
+ "dependencies": {
19
+ "denque": "^1.5.0",
20
+ "redis-commands": "^1.7.0",
21
+ "redis-errors": "^1.2.0",
22
+ "redis-parser": "^3.0.0"
23
+ },
24
+ "engines": {
25
+ "node": ">=10"
26
+ },
27
+ "funding": {
28
+ "type": "opencollective",
29
+ "url": "https://opencollective.com/node-redis"
30
+ }
31
+ },
32
+ "node_modules/redis-commands": {
33
+ "version": "1.7.0",
34
+ "resolved": "https://registry.npmjs.org/redis-commands/-/redis-commands-1.7.0.tgz",
35
+ "integrity": "sha512-nJWqw3bTFy21hX/CPKHth6sfhZbdiHP6bTawSgQBlKOVRG7EZkfHbbHwQJnrE4vsQf0CMNE+3gJ4Fmm16vdVlQ=="
36
+ },
37
+ "node_modules/redis-errors": {
38
+ "version": "1.2.0",
39
+ "resolved": "https://registry.npmjs.org/redis-errors/-/redis-errors-1.2.0.tgz",
40
+ "integrity": "sha1-62LSrbFeTq9GEMBK/hUpOEJQq60=",
41
+ "engines": {
42
+ "node": ">=4"
43
+ }
44
+ },
45
+ "node_modules/redis-parser": {
46
+ "version": "3.0.0",
47
+ "resolved": "https://registry.npmjs.org/redis-parser/-/redis-parser-3.0.0.tgz",
48
+ "integrity": "sha1-tm2CjNyv5rS4pCin3vTGvKwxyLQ=",
49
+ "dependencies": {
50
+ "redis-errors": "^1.0.0"
51
+ },
52
+ "engines": {
53
+ "node": ">=4"
54
+ }
55
+ }
56
+ }
57
+ }
@@ -0,0 +1,4 @@
1
+ ## 1.5.0
2
+
3
+ - feat: adds capacity option for circular buffers (#27)
4
+
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2018 Mike Diarmid (Salakar) <mike.diarmid@gmail.com>
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this library except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
@@ -0,0 +1,362 @@
1
+ <p align="center">
2
+ <a href="https://invertase.io">
3
+ <img src="https://static.invertase.io/assets/invertase-logo-small.png"><br/>
4
+ </a>
5
+ <h2 align="center">Denque</h2>
6
+ </p>
7
+
8
+ <p align="center">
9
+ <a href="https://www.npmjs.com/package/denque"><img src="https://img.shields.io/npm/dm/denque.svg?style=flat-square" alt="NPM downloads"></a>
10
+ <a href="https://www.npmjs.com/package/denque"><img src="https://img.shields.io/npm/v/denque.svg?style=flat-square" alt="NPM version"></a>
11
+ <a href="https://travis-ci.org/Salakar/denque"><img src="https://travis-ci.org/invertase/denque.svg" alt="Build version"></a>
12
+ <a href="https://coveralls.io/github/invertase/denque?branch=master"><img src="https://coveralls.io/repos/github/invertase/denque/badge.svg?branch=master" alt="Build version"></a>
13
+ <a href="/LICENSE"><img src="https://img.shields.io/npm/l/denque.svg?style=flat-square" alt="License"></a>
14
+ <a href="https://discord.gg/C9aK28N"><img src="https://img.shields.io/discord/295953187817521152.svg?logo=discord&style=flat-square&colorA=7289da&label=discord" alt="Chat"></a>
15
+ <a href="https://twitter.com/invertaseio"><img src="https://img.shields.io/twitter/follow/invertaseio.svg?style=social&label=Follow" alt="Follow on Twitter"></a>
16
+ </p>
17
+
18
+ Extremely fast and lightweight [double-ended queue](http://en.wikipedia.org/wiki/Double-ended_queue) implementation with zero dependencies.
19
+
20
+ Double-ended queues can also be used as a:
21
+
22
+ - [Stack](http://en.wikipedia.org/wiki/Stack_\(abstract_data_type\))
23
+ - [Queue](http://en.wikipedia.org/wiki/Queue_\(data_structure\))
24
+
25
+ This implementation is currently the fastest available, even faster than `double-ended-queue`, see the [benchmarks](#benchmarks)
26
+
27
+ Every queue operation is done at a constant `O(1)` - including random access from `.peekAt(index)`.
28
+
29
+ **Works on all node versions >= v0.10**
30
+
31
+ # Quick Start
32
+
33
+ npm install denque
34
+
35
+ ```js
36
+ const Denque = require("denque");
37
+
38
+ const denque = new Denque([1,2,3,4]);
39
+ denque.shift(); // 1
40
+ denque.pop(); // 4
41
+ ```
42
+
43
+
44
+ # API
45
+
46
+ - [`new Denque()`](#new-denque---denque)
47
+ - [`new Denque(Array items)`](#new-denquearray-items---denque)
48
+ - [`push(item)`](#pushitem---int)
49
+ - [`unshift(item)`](#unshiftitem---int)
50
+ - [`pop()`](#pop---dynamic)
51
+ - [`shift()`](#shift---dynamic)
52
+ - [`toArray()`](#toarray---array)
53
+ - [`peekBack()`](#peekback---dynamic)
54
+ - [`peekFront()`](#peekfront---dynamic)
55
+ - [`peekAt(int index)`](#peekAtint-index---dynamic)
56
+ - [`remove(int index, int count)`](#remove)
57
+ - [`removeOne(int index)`](#removeOne)
58
+ - [`splice(int index, int count, item1, item2, ...)`](#splice)
59
+ - [`isEmpty()`](#isempty---boolean)
60
+ - [`clear()`](#clear---void)
61
+
62
+ #### `new Denque()` -> `Denque`
63
+
64
+ Creates an empty double-ended queue with initial capacity of 4.
65
+
66
+ ```js
67
+ var denque = new Denque();
68
+ denque.push(1);
69
+ denque.push(2);
70
+ denque.push(3);
71
+ denque.shift(); //1
72
+ denque.pop(); //3
73
+ ```
74
+
75
+ <hr>
76
+
77
+ #### `new Denque(Array items)` -> `Denque`
78
+
79
+ Creates a double-ended queue from `items`.
80
+
81
+ ```js
82
+ var denque = new Denque([1,2,3,4]);
83
+ denque.shift(); // 1
84
+ denque.pop(); // 4
85
+ ```
86
+
87
+ <hr>
88
+
89
+
90
+ #### `push(item)` -> `int`
91
+
92
+ Push an item to the back of this queue. Returns the amount of items currently in the queue after the operation.
93
+
94
+ ```js
95
+ var denque = new Denque();
96
+ denque.push(1);
97
+ denque.pop(); // 1
98
+ denque.push(2);
99
+ denque.push(3);
100
+ denque.shift(); // 2
101
+ denque.shift(); // 3
102
+ ```
103
+
104
+ <hr>
105
+
106
+ #### `unshift(item)` -> `int`
107
+
108
+ Unshift an item to the front of this queue. Returns the amount of items currently in the queue after the operation.
109
+
110
+ ```js
111
+ var denque = new Denque([2,3]);
112
+ denque.unshift(1);
113
+ denque.toString(); // "1,2,3"
114
+ denque.unshift(-2);
115
+ denque.toString(); // "-2,-1,0,1,2,3"
116
+ ```
117
+
118
+ <hr>
119
+
120
+
121
+ #### `pop()` -> `dynamic`
122
+
123
+ Pop off the item at the back of this queue.
124
+
125
+ Note: The item will be removed from the queue. If you simply want to see what's at the back of the queue use [`peekBack()`](#peekback---dynamic) or [`.peekAt(-1)`](#peekAtint-index---dynamic).
126
+
127
+ If the queue is empty, `undefined` is returned. If you need to differentiate between `undefined` values in the queue and `pop()` return value -
128
+ check the queue `.length` before popping.
129
+
130
+ ```js
131
+ var denque = new Denque([1,2,3]);
132
+ denque.pop(); // 3
133
+ denque.pop(); // 2
134
+ denque.pop(); // 1
135
+ denque.pop(); // undefined
136
+ ```
137
+
138
+ **Aliases:** `removeBack`
139
+
140
+ <hr>
141
+
142
+ #### `shift()` -> `dynamic`
143
+
144
+ Shifts off the item at the front of this queue.
145
+
146
+ Note: The item will be removed from the queue. If you simply want to see what's at the front of the queue use [`peekFront()`](#peekfront---dynamic) or [`.peekAt(0)`](#peekAtint-index---dynamic).
147
+
148
+ If the queue is empty, `undefined` is returned. If you need to differentiate between `undefined` values in the queue and `shift()` return value -
149
+ check the queue `.length` before shifting.
150
+
151
+ ```js
152
+ var denque = new Denque([1,2,3]);
153
+ denque.shift(); // 1
154
+ denque.shift(); // 2
155
+ denque.shift(); // 3
156
+ denque.shift(); // undefined
157
+ ```
158
+
159
+ <hr>
160
+
161
+ #### `toArray()` -> `Array`
162
+
163
+ Returns the items in the queue as an array. Starting from the item in the front of the queue and ending to the item at the back of the queue.
164
+
165
+ ```js
166
+ var denque = new Denque([1,2,3]);
167
+ denque.push(4);
168
+ denque.unshift(0);
169
+ denque.toArray(); // [0,1,2,3,4]
170
+ ```
171
+
172
+ <hr>
173
+
174
+ #### `peekBack()` -> `dynamic`
175
+
176
+ Returns the item that is at the back of this queue without removing it.
177
+
178
+ If the queue is empty, `undefined` is returned.
179
+
180
+ ```js
181
+ var denque = new Denque([1,2,3]);
182
+ denque.push(4);
183
+ denque.peekBack(); // 4
184
+ ```
185
+
186
+ <hr>
187
+
188
+ #### `peekFront()` -> `dynamic`
189
+
190
+ Returns the item that is at the front of this queue without removing it.
191
+
192
+ If the queue is empty, `undefined` is returned.
193
+
194
+ ```js
195
+ var denque = new Denque([1,2,3]);
196
+ denque.push(4);
197
+ denque.peekFront(); // 1
198
+ ```
199
+
200
+ <hr>
201
+
202
+ #### `peekAt(int index)` -> `dynamic`
203
+
204
+ Returns the item that is at the given `index` of this queue without removing it.
205
+
206
+ The index is zero-based, so `.peekAt(0)` will return the item that is at the front, `.peekAt(1)` will return
207
+ the item that comes after and so on.
208
+
209
+ The index can be negative to read items at the back of the queue. `.peekAt(-1)` returns the item that is at the back of the queue,
210
+ `.peekAt(-2)` will return the item that comes before and so on.
211
+
212
+ Returns `undefined` if `index` is not a valid index into the queue.
213
+
214
+ ```js
215
+ var denque = new Denque([1,2,3]);
216
+ denque.peekAt(0); //1
217
+ denque.peekAt(1); //2
218
+ denque.peekAt(2); //3
219
+
220
+ denque.peekAt(-1); // 3
221
+ denque.peekAt(-2); // 2
222
+ denque.peekAt(-3); // 1
223
+ ```
224
+
225
+ **Note**: The implementation has O(1) random access using `.peekAt()`.
226
+
227
+ **Aliases:** `get`
228
+
229
+ <hr>
230
+
231
+ #### `remove(int index, int count)` -> `array`
232
+
233
+ Remove number of items from the specified index from the list.
234
+
235
+ Returns array of removed items.
236
+
237
+ Returns undefined if the list is empty.
238
+
239
+ ```js
240
+ var denque = new Denque([1,2,3,4,5,6,7]);
241
+ denque.remove(0,3); //[1,2,3]
242
+ denque.remove(1,2); //[5,6]
243
+ var denque1 = new Denque([1,2,3,4,5,6,7]);
244
+ denque1.remove(4, 100); //[5,6,7]
245
+ ```
246
+
247
+ <hr>
248
+
249
+ #### `removeOne(int index)` -> `dynamic`
250
+
251
+ Remove and return the item at the specified index from the list.
252
+
253
+ Returns undefined if the list is empty.
254
+
255
+ ```js
256
+ var denque = new Denque([1,2,3,4,5,6,7]);
257
+ denque.removeOne(4); // 5
258
+ denque.removeOne(3); // 4
259
+ denque1.removeOne(1); // 2
260
+ ```
261
+
262
+ <hr>
263
+
264
+ #### `splice(int index, int count, item1, item2, ...)` -> `array`
265
+
266
+ Native splice implementation.
267
+
268
+ Remove number of items from the specified index from the list and/or add new elements.
269
+
270
+ Returns array of removed items or empty array if count == 0.
271
+
272
+ Returns undefined if the list is empty.
273
+
274
+ ```js
275
+ var denque = new Denque([1,2,3,4,5,6,7]);
276
+ denque.splice(denque.length, 0, 8, 9, 10); // []
277
+ denque.toArray() // [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
278
+ denque.splice(3, 3, 44, 55, 66); // [4,5,6]
279
+ denque.splice(5,4, 666,667,668,669); // [ 66, 7, 8, 9 ]
280
+ denque.toArray() // [ 1, 2, 3, 44, 55, 666, 667, 668, 669, 10 ]
281
+ ```
282
+
283
+ <hr>
284
+
285
+ #### `isEmpty()` -> `boolean`
286
+
287
+ Return `true` if this queue is empty, `false` otherwise.
288
+
289
+ ```js
290
+ var denque = new Denque();
291
+ denque.isEmpty(); // true
292
+ denque.push(1);
293
+ denque.isEmpty(); // false
294
+ ```
295
+
296
+ <hr>
297
+
298
+ #### `clear()` -> `void`
299
+
300
+ Remove all items from this queue. Does not change the queue's capacity.
301
+
302
+ ```js
303
+ var denque = new Denque([1,2,3]);
304
+ denque.toString(); // "1,2,3"
305
+ denque.clear();
306
+ denque.toString(); // ""
307
+ ```
308
+ <hr>
309
+
310
+
311
+ ## Benchmarks
312
+
313
+ #### Platform info:
314
+ ```
315
+ Darwin 17.0.0 x64
316
+ Node.JS 9.4.0
317
+ V8 6.2.414.46-node.17
318
+ Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz × 8
319
+ ```
320
+
321
+ #### 1000 items in queue
322
+
323
+ (3 x shift + 3 x push ops per 'op')
324
+
325
+ denque x 64,365,425 ops/sec ±0.69% (92 runs sampled)
326
+ double-ended-queue x 26,646,882 ops/sec ±0.47% (94 runs sampled)
327
+
328
+ #### 2 million items in queue
329
+
330
+ (3 x shift + 3 x push ops per 'op')
331
+
332
+ denque x 61,994,249 ops/sec ±0.26% (95 runs sampled)
333
+ double-ended-queue x 26,363,500 ops/sec ±0.42% (91 runs sampled)
334
+
335
+ #### Splice
336
+
337
+ (1 x splice per 'op') - initial size of 100,000 items
338
+
339
+ denque.splice x 925,749 ops/sec ±22.29% (77 runs sampled)
340
+ native array splice x 7,777 ops/sec ±8.35% (50 runs sampled)
341
+
342
+ #### Remove
343
+
344
+ (1 x remove + 10 x push per 'op') - initial size of 100,000 items
345
+
346
+ denque.remove x 2,635,275 ops/sec ±0.37% (95 runs sampled)
347
+ native array splice - Fails to complete: "JavaScript heap out of memory"
348
+
349
+ #### Remove One
350
+
351
+ (1 x removeOne + 10 x push per 'op') - initial size of 100,000 items
352
+
353
+ denque.removeOne x 1,088,240 ops/sec ±0.21% (93 runs sampled)
354
+ native array splice x 5,300 ops/sec ±0.41% (96 runs sampled)
355
+
356
+ ---
357
+
358
+ Built and maintained with 💛 by [Invertase](https://invertase.io).
359
+
360
+ - [💼 Hire Us](https://invertase.io/hire-us)
361
+ - [☕️ Sponsor Us](https://opencollective.com/react-native-firebase)
362
+ - [👩‍💻 Work With Us](https://invertase.io/jobs)
@@ -0,0 +1,31 @@
1
+ declare class Denque<T = any> {
2
+ constructor();
3
+ constructor(array: T[]);
4
+ constructor(array: T[], options: IDenqueOptions);
5
+
6
+ push(item: T): number;
7
+ unshift(item: T): number;
8
+ pop(): T | undefined;
9
+ removeBack(): T | undefined;
10
+ shift(): T | undefined;
11
+ peekBack(): T | undefined;
12
+ peekFront(): T | undefined;
13
+ peekAt(index: number): T | undefined;
14
+ get(index: number): T | undefined;
15
+ remove(index: number, count: number): T[];
16
+ removeOne(index: number): T | undefined;
17
+ splice(index: number, count: number, ...item: T[]): T[] | undefined;
18
+ isEmpty(): boolean;
19
+ clear(): void;
20
+
21
+ toString(): string;
22
+ toArray(): T[];
23
+
24
+ length: number;
25
+ }
26
+
27
+ interface IDenqueOptions {
28
+ capacity?: number
29
+ }
30
+
31
+ export = Denque;