source: frontend/node_modules/hoopy/README.md

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 3.2 KB
Line 
1# hoopy
2
3[![Build status](https://gitlab.com/philbooth/hoopy/badges/master/pipeline.svg)](https://gitlab.com/philbooth/hoopy/pipelines)
4[![Package status](https://img.shields.io/npm/v/hoopy.svg)](https://www.npmjs.com/package/hoopy)
5[![Downloads](https://img.shields.io/npm/dm/hoopy.svg)](https://www.npmjs.com/package/hoopy)
6[![License](https://img.shields.io/npm/l/hoopy.svg)](https://opensource.org/licenses/MIT)
7
8
9Like an array, but rounder.
10
11* [Huh?](#huh)
12* [What's it useful for?](#whats-it-useful-for)
13* [How do I install it?](#how-do-i-install-it)
14* [How do I use it?](#how-do-i-use-it)
15 * [Loading the library](#loading-the-library)
16 * [Creating arrays](#creating-arrays)
17 * [Accessing array items](#accessing-array-items)
18 * [Growing the array](#growing-the-array)
19* [Is there a change log?](#is-there-a-change-log)
20* [How do I set up the dev environment?](#how-do-i-set-up-the-dev-environment)
21* [What license is it released under?](#what-license-is-it-released-under)
22
23## Huh?
24
25Hoopy is a circular array
26data type.
27It extends `Array`
28so that out-of-bounds indices
29wrap back round
30to the start of the array
31(or if they're negative indices,
32they wrap back round
33to the end of the array).
34
35## What's it useful for?
36
37If you want a fixed-length buffer
38for streamed I/O,
39Hoopy can do that for you.
40
41## How do I install it?
42
43Via `npm`:
44
45```
46npm i hoopy --save
47```
48
49Or if you just want the git repo:
50
51```
52git clone git@gitlab.com:philbooth/hoopy.git
53```
54
55## How do I use it?
56
57### Loading the library
58
59```js
60const Hoopy = require('hoopy');
61```
62
63### Creating arrays
64
65```js
66const hoopy = new Hoopy(10);
67assert(Array.isArray(hoopy));
68```
69
70You must pass
71a `size` argument
72to the `Hoopy` constructor,
73otherwise it will throw.
74
75### Accessing array items
76
77```js
78for (let i = 0; i < hoopy.length; ++i) {
79 hoopy[i] = i;
80 console.log(hoopy[i]);
81}
82```
83
84You can read and write array items
85using square brackets for indexing
86as you would with a normal array.
87However, if you write to
88an out-of-bounds index,
89it will not increase
90the length of the array.
91Instead the index is applied
92modulo the array length,
93wrapping back round to the start.
94Negative indices work in reverse,
95wrapping back round to the end
96of the array.
97
98The methods
99`push`, `pop`, `shift` and `unshift`
100will throw if called.
101Future versions of the library
102may implement sane behaviour
103for them.
104All of the other `Array` methods
105work normally.
106
107### Growing the array
108
109```js
110hoopy.grow(50);
111```
112
113The `grow` method
114adds items to the array.
115It takes one argument,
116which is the number
117of items to grow the array by.
118The new length of the array
119will be the old length
120plus the number you pass to `grow`.
121
122If the current state of the array
123includes overflowed indices,
124`grow` will take care
125to move those items
126in to the freshly-created
127available space,
128so that the correct order is maintained
129for your data.
130
131The caller is responsible
132for ensuring they don't overwrite
133unprocessed items.
134If you need to increase
135the size of the array,
136you must call `grow`.
137
138## Is there a change log?
139
140[Yes](CHANGELOG.md).
141
142## How do I set up the dev environment?
143
144To install the dependencies:
145
146```
147npm i
148```
149
150To run the tests:
151
152```
153npm t
154```
155
156To lint the code:
157
158```
159npm run lint
160```
161
162## What license is it released under?
163
164[MIT](LICENSE).
165
Note: See TracBrowser for help on using the repository browser.