Skip to content

Commit 55ff729

Browse files
committed
Refactor to TypeScript
1 parent eba9c7a commit 55ff729

File tree

15 files changed

+482
-647
lines changed

15 files changed

+482
-647
lines changed

.eslintignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

.eslintrc.yml

Lines changed: 0 additions & 2 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 16 additions & 218 deletions
Original file line numberDiff line numberDiff line change
@@ -1,230 +1,28 @@
1-
name: ci
1+
name: CI
22

33
on:
4-
- pull_request
5-
- push
4+
- pull_request
5+
- push
66

77
permissions:
88
contents: read
99

1010
jobs:
1111
test:
12-
permissions:
13-
checks: write # for coverallsapp/github-action to create new checks
14-
contents: read # for actions/checkout to fetch code
12+
name: Node.js ${{ matrix.node-version }}
1513
runs-on: ubuntu-latest
1614
strategy:
1715
matrix:
18-
name:
19-
- Node.js 0.8
20-
- Node.js 0.10
21-
- Node.js 0.12
22-
- io.js 1.x
23-
- io.js 2.x
24-
- io.js 3.x
25-
- Node.js 4.x
26-
- Node.js 5.x
27-
- Node.js 6.x
28-
- Node.js 7.x
29-
- Node.js 8.x
30-
- Node.js 9.x
31-
- Node.js 10.x
32-
- Node.js 11.x
33-
- Node.js 12.x
34-
- Node.js 13.x
35-
- Node.js 14.x
36-
- Node.js 15.x
37-
- Node.js 16.x
38-
- Node.js 17.x
39-
- Node.js 18.x
40-
- Node.js 19.x
41-
- Node.js 20.x
42-
- Node.js 21.x
43-
- Node.js 22.x
44-
45-
include:
46-
47-
- name: Node.js 0.8
48-
node-version: "0.8"
49-
npm-i: mocha@2.5.3
50-
npm-rm: nyc
51-
52-
- name: Node.js 0.10
53-
node-version: "0.10"
54-
npm-i: mocha@3.5.3 nyc@10.3.2
55-
56-
- name: Node.js 0.12
57-
node-version: "0.12"
58-
npm-i: mocha@3.5.3 nyc@10.3.2
59-
60-
- name: io.js 1.x
61-
node-version: "1.8"
62-
npm-i: mocha@3.5.3 nyc@10.3.2
63-
64-
- name: io.js 2.x
65-
node-version: "2.5"
66-
npm-i: mocha@3.5.3 nyc@10.3.2
67-
68-
- name: io.js 3.x
69-
node-version: "3.3"
70-
npm-i: mocha@3.5.3 nyc@10.3.2
71-
72-
- name: Node.js 4.x
73-
node-version: "4.9"
74-
npm-i: mocha@5.2.0 nyc@11.9.0
75-
76-
- name: Node.js 5.x
77-
node-version: "5.12"
78-
npm-i: mocha@5.2.0 nyc@11.9.0
79-
80-
- name: Node.js 6.x
81-
node-version: "6.17"
82-
npm-i: mocha@6.2.2 nyc@14.1.1
83-
84-
- name: Node.js 7.x
85-
node-version: "7.10"
86-
npm-i: mocha@6.2.2 nyc@14.1.1
87-
88-
- name: Node.js 8.x
89-
node-version: "8.17"
90-
npm-i: mocha@7.1.2 nyc@14.1.1
91-
92-
- name: Node.js 9.x
93-
node-version: "9.11"
94-
npm-i: mocha@7.1.2 nyc@14.1.1
95-
96-
- name: Node.js 10.x
97-
node-version: "10.24"
98-
npm-i: mocha@8.4.0
99-
100-
- name: Node.js 11.x
101-
node-version: "11.15"
102-
npm-i: mocha@8.4.0
103-
104-
- name: Node.js 12.x
105-
node-version: "12.22"
106-
npm-i: mocha@9.2.2
107-
108-
- name: Node.js 13.x
109-
node-version: "13.14"
110-
npm-i: mocha@9.2.2
111-
112-
- name: Node.js 14.x
113-
node-version: "14.21"
114-
115-
- name: Node.js 15.x
116-
node-version: "15.14"
117-
118-
- name: Node.js 16.x
119-
node-version: "16.20"
120-
121-
- name: Node.js 17.x
122-
node-version: "17.9"
123-
124-
- name: Node.js 18.x
125-
node-version: "18.18"
126-
127-
- name: Node.js 19.x
128-
node-version: "19.9"
129-
130-
- name: Node.js 20.x
131-
node-version: "20.9"
132-
133-
- name: Node.js 21.x
134-
node-version: "21.7"
135-
136-
- name: Node.js 22.x
137-
node-version: "22.0"
138-
139-
steps:
140-
- uses: actions/checkout@v6.0.0
141-
142-
- name: Install Node.js ${{ matrix.node-version }}
143-
shell: bash -eo pipefail -l {0}
144-
run: |
145-
nvm install --default ${{ matrix.node-version }}
146-
if [[ "${{ matrix.node-version }}" == 0.* && "$(cut -d. -f2 <<< "${{ matrix.node-version }}")" -lt 10 ]]; then
147-
nvm install --alias=npm 0.10
148-
nvm use ${{ matrix.node-version }}
149-
if [[ "$(npm -v)" == 1.1.* ]]; then
150-
nvm exec npm npm install -g npm@1.1
151-
ln -fs "$(which npm)" "$(dirname "$(nvm which npm)")/npm"
152-
else
153-
sed -i '1s;^.*$;'"$(printf '#!%q' "$(nvm which npm)")"';' "$(readlink -f "$(which npm)")"
154-
fi
155-
npm config set strict-ssl false
156-
fi
157-
dirname "$(nvm which ${{ matrix.node-version }})" >> "$GITHUB_PATH"
158-
159-
- name: Configure npm
160-
run: |
161-
if [[ "$(npm config get package-lock)" == "true" ]]; then
162-
npm config set package-lock false
163-
else
164-
npm config set shrinkwrap false
165-
fi
166-
167-
- name: Remove npm module(s) ${{ matrix.npm-rm }}
168-
run: npm rm --silent --save-dev ${{ matrix.npm-rm }}
169-
if: matrix.npm-rm != ''
170-
171-
- name: Install npm module(s) ${{ matrix.npm-i }}
172-
run: npm install --save-dev ${{ matrix.npm-i }}
173-
if: matrix.npm-i != ''
174-
175-
- name: Setup Node.js version-specific dependencies
176-
shell: bash
177-
run: |
178-
# eslint for linting
179-
# - remove on Node.js < 8
180-
if [[ "$(cut -d. -f1 <<< "${{ matrix.node-version }}")" -lt 8 ]]; then
181-
node -pe 'Object.keys(require("./package").devDependencies).join("\n")' | \
182-
grep -E '^eslint(-|$)' | \
183-
sort -r | \
184-
xargs -n1 npm rm --silent --save-dev
185-
fi
186-
187-
- name: Install Node.js dependencies
188-
run: npm install
189-
190-
- name: List environment
191-
id: list_env
192-
shell: bash
193-
run: |
194-
echo "node@$(node -v)"
195-
echo "npm@$(npm -v)"
196-
npm -s ls ||:
197-
(npm -s ls --depth=0 ||:) | awk -F'[ @]' 'NR>1 && $2 { print "::set-output name=" $2 "::" $3 }'
198-
199-
- name: Run tests
200-
shell: bash
201-
run: |
202-
if npm -ps ls nyc | grep -q nyc; then
203-
npm run test-ci
204-
else
205-
npm test
206-
fi
207-
208-
- name: Lint code
209-
if: steps.list_env.outputs.eslint != ''
210-
run: npm run lint
211-
212-
- name: Collect code coverage
213-
uses: coverallsapp/github-action@master
214-
if: steps.list_env.outputs.nyc != ''
215-
with:
216-
github-token: ${{ secrets.GITHUB_TOKEN }}
217-
flag-name: run-${{ matrix.test_number }}
218-
parallel: true
219-
220-
coverage:
221-
permissions:
222-
checks: write # for coverallsapp/github-action to create new checks
223-
needs: test
224-
runs-on: ubuntu-latest
16+
node-version:
17+
- "20"
18+
- "*"
22519
steps:
226-
- name: Upload code coverage
227-
uses: coverallsapp/github-action@master
228-
with:
229-
github-token: ${{ secrets.GITHUB_TOKEN }}
230-
parallel-finished: true
20+
- uses: actions/checkout@v5
21+
- uses: actions/setup-node@v4
22+
with:
23+
node-version: ${{ matrix.node-version }}
24+
- run: npm install
25+
- run: npm test
26+
- uses: codecov/codecov-action@v5
27+
with:
28+
name: Node.js ${{ matrix.node-version }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
node_modules
33
coverage
44
package-lock.json
5+
dist/

HISTORY.md

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,45 @@
1-
1.2.1 / 2019-05-10
2-
==================
1+
# 1.2.1 / 2019-05-10
32

4-
* Improve error when `str` is not a string
3+
- Improve error when `str` is not a string
54

6-
1.2.0 / 2016-06-01
7-
==================
5+
# 1.2.0 / 2016-06-01
86

9-
* Add `combine` option to combine overlapping ranges
7+
- Add `combine` option to combine overlapping ranges
108

11-
1.1.0 / 2016-05-13
12-
==================
9+
# 1.1.0 / 2016-05-13
1310

14-
* Fix incorrectly returning -1 when there is at least one valid range
15-
* perf: remove internal function
11+
- Fix incorrectly returning -1 when there is at least one valid range
12+
- perf: remove internal function
1613

17-
1.0.3 / 2015-10-29
18-
==================
14+
# 1.0.3 / 2015-10-29
1915

20-
* perf: enable strict mode
16+
- perf: enable strict mode
2117

22-
1.0.2 / 2014-09-08
23-
==================
18+
# 1.0.2 / 2014-09-08
2419

25-
* Support Node.js 0.6
20+
- Support Node.js 0.6
2621

27-
1.0.1 / 2014-09-07
28-
==================
22+
# 1.0.1 / 2014-09-07
2923

30-
* Move repository to jshttp
24+
- Move repository to jshttp
3125

32-
1.0.0 / 2013-12-11
33-
==================
26+
# 1.0.0 / 2013-12-11
3427

35-
* Add repository to package.json
36-
* Add MIT license
28+
- Add repository to package.json
29+
- Add MIT license
3730

38-
0.0.4 / 2012-06-17
39-
==================
31+
# 0.0.4 / 2012-06-17
4032

41-
* Change ret -1 for unsatisfiable and -2 when invalid
33+
- Change ret -1 for unsatisfiable and -2 when invalid
4234

43-
0.0.3 / 2012-06-17
44-
==================
35+
# 0.0.3 / 2012-06-17
4536

46-
* Fix last-byte-pos default to len - 1
37+
- Fix last-byte-pos default to len - 1
4738

48-
0.0.2 / 2012-06-14
49-
==================
39+
# 0.0.2 / 2012-06-14
5040

51-
* Add `.type`
41+
- Add `.type`
5242

53-
0.0.1 / 2012-06-11
54-
==================
43+
# 0.0.1 / 2012-06-11
5544

56-
* Initial release
45+
- Initial release

README.md

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ $ npm install range-parser
2323
<!-- eslint-disable no-unused-vars -->
2424

2525
```js
26-
var parseRange = require('range-parser')
26+
var parseRange = require("range-parser");
2727
```
2828

2929
### parseRange(size, header, options)
@@ -32,21 +32,19 @@ Parse the given `header` string where `size` is the size of the selected
3232
representation that is to be partitioned into subranges. An array of subranges
3333
will be returned or negative numbers indicating an error parsing.
3434

35-
* `-2` signals a malformed header string
36-
* `-1` signals an unsatisfiable range
37-
38-
<!-- eslint-disable no-undef -->
35+
- `-2` signals a malformed header string
36+
- `-1` signals an unsatisfiable range
3937

4038
```js
4139
// parse header from request
42-
var subranges = parseRange(size, req.headers.range)
40+
var subranges = parseRange(size, req.headers.range);
4341

4442
// the type of the subranges
45-
if (subranges.type === 'bytes') {
43+
if (subranges.type === "bytes") {
4644
// the ranges
4745
subranges.forEach(function (r) {
4846
// do something with r.start and r.end
49-
})
47+
});
5048
}
5149
```
5250

@@ -60,10 +58,8 @@ Specifies if overlapping & adjacent subranges should be combined, defaults to
6058
`false`. When `true`, ranges will be combined and returned as if they were
6159
specified that way in the header.
6260

63-
<!-- eslint-disable no-undef -->
64-
6561
```js
66-
parseRange(100, 'bytes=50-55,0-10,5-10,56-60', { combine: true })
62+
parseRange(100, "bytes=50-55,0-10,5-10,56-60", { combine: true });
6763
// => [
6864
// { start: 0, end: 10 },
6965
// { start: 50, end: 60 }

0 commit comments

Comments
 (0)