/
README.md.rx
65 lines (40 loc) · 2.05 KB
/
README.md.rx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# jslice
{{ npm.link("jslice") }} is a small `JavaScript/TypeScript` library for slicing arrays using `slice strings`.
The `slice` syntax is heavily inspired by its counterpart in `python`.
I felt the need for `jslice` when I was working on {{ gh.link("iaseth/josn", "josn") }}.
I am using {{ gh.link("iaseth/readmix", "readmix") }} for generating this README.
You can view the source file [here](https://github.com/iaseth/jslice/blob/master/README.md.rx).
## Table of contents
{{ tableOfContents(doc) }}
## Installation
You can install {{ npm.link("jslice") }} with the following command:
=> npm i jslice
Now you can import `jslice` in your project as follows.
=> const jslice = require("jslice");
=> const { isSlice, slice } = jslice;
## What is a slice string?
A slice string is any string of the form `start:end`,
where `start` and `end` are integers, that can be used for slicing an array.
Here, `start` is the first element that is part of the resulting slice,
`end` is the first element that is not in the resulting slice.
Both these arguments are optional. By default, `start` is set to `0` and `end` is set to the array length.
So, `0:20` is just the same as `:20`.
And, for an array of length 10, `4:10` is just the same as `4:`.
Both these arguments can be negative.
A negative value is counted from the end of the array.
So, `-1` refers to the last element in array.
## Documentation
`jslice` exports just 2 functions - `isSlice(str)` and `slice(arr, str)`.
| Function | Returns | Description |
| ----------------- | --------- | ----------------------------------------------------------------- |
| `isSlice(str)` | `boolean` | Checks whether the given string is a valid slice string or not. |
| `slice(arr, str)` | `array` | Returns a slice of the array `arr` according to the slice string. |
## Package details
{{ npm.packageDetails() }}
## Dependencies
{{ npm.dependencyTable() }}
## Dev dependencies
{{ npm.devDependencyTable() }}
## License
{{ "LICENSE.md" | File }}
{{ giveCredit() }}