bit-sequence 1.1.0 → 1.2.0

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.
@@ -0,0 +1,29 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: 'github-actions'
4
+ directory: '/'
5
+ schedule:
6
+ interval: 'daily'
7
+ commit-message:
8
+ prefix: 'chore'
9
+ include: 'scope'
10
+ cooldown:
11
+ default-days: 5
12
+ - package-ecosystem: 'npm'
13
+ directory: '/'
14
+ schedule:
15
+ interval: 'daily'
16
+ commit-message:
17
+ prefix: 'chore'
18
+ include: 'scope'
19
+ cooldown:
20
+ default-days: 5
21
+ - package-ecosystem: 'gomod'
22
+ directory: '/go'
23
+ schedule:
24
+ interval: 'daily'
25
+ commit-message:
26
+ prefix: 'chore'
27
+ include: 'scope'
28
+ cooldown:
29
+ default-days: 5
@@ -0,0 +1,47 @@
1
+ name: Go CI
2
+ on: [push, pull_request]
3
+
4
+ jobs:
5
+ test:
6
+ strategy:
7
+ fail-fast: false
8
+ matrix:
9
+ os: [macos-latest, ubuntu-latest, windows-latest]
10
+ runs-on: ${{ matrix.os }}
11
+ defaults:
12
+ run:
13
+ working-directory: go
14
+ steps:
15
+ - name: Checkout Repository
16
+ uses: actions/checkout@v6
17
+ - name: Setup Go
18
+ uses: actions/setup-go@v6
19
+ with:
20
+ go-version: '1.25'
21
+ cache-dependency-path: go/go.mod
22
+ - name: Run tests
23
+ run: go test -v ./...
24
+ - name: Vet
25
+ run: go vet ./...
26
+ - name: Check formatting
27
+ if: runner.os != 'Windows'
28
+ run: |
29
+ test -z "$(gofmt -l .)" || (gofmt -d . && exit 1)
30
+
31
+ staticcheck:
32
+ runs-on: ubuntu-latest
33
+ defaults:
34
+ run:
35
+ working-directory: go
36
+ steps:
37
+ - name: Checkout Repository
38
+ uses: actions/checkout@v6
39
+ - name: Setup Go
40
+ uses: actions/setup-go@v6
41
+ with:
42
+ go-version: '1.25'
43
+ cache-dependency-path: go/go.mod
44
+ - name: Install staticcheck
45
+ run: go install honnef.co/go/tools/cmd/staticcheck@latest
46
+ - name: Run staticcheck
47
+ run: staticcheck ./...
@@ -0,0 +1,56 @@
1
+ name: Test & Maybe Release
2
+ on: [push, pull_request]
3
+
4
+ jobs:
5
+ test:
6
+ strategy:
7
+ fail-fast: false
8
+ matrix:
9
+ node: [lts/*, current]
10
+ os: [macos-latest, ubuntu-latest, windows-latest]
11
+ runs-on: ${{ matrix.os }}
12
+ steps:
13
+ - name: Checkout Repository
14
+ uses: actions/checkout@v6
15
+ - name: Use Node.js ${{ matrix.node }}
16
+ uses: actions/setup-node@v6
17
+ with:
18
+ node-version: ${{ matrix.node }}
19
+ - name: Install Dependencies
20
+ run: npm install --no-progress
21
+ - name: Check build is up to date
22
+ run: |
23
+ npm run build
24
+ git diff --exit-code || (echo "::error::Build artifacts not committed. Run 'npm run build' and commit the changes." && exit 1)
25
+ - name: Run tests
26
+ run: npm test
27
+
28
+ release:
29
+ name: Release
30
+ needs: [test]
31
+ runs-on: ubuntu-latest
32
+ if: github.event_name == 'push' && github.ref == 'refs/heads/master'
33
+ permissions:
34
+ contents: write
35
+ issues: write
36
+ pull-requests: write
37
+ id-token: write
38
+ steps:
39
+ - name: Checkout
40
+ uses: actions/checkout@v6
41
+ with:
42
+ fetch-depth: 0
43
+ - name: Setup Node.js
44
+ uses: actions/setup-node@v6
45
+ with:
46
+ node-version: lts/*
47
+ registry-url: 'https://registry.npmjs.org'
48
+ - name: Install dependencies
49
+ run: npm install --no-progress --no-package-lock --no-save
50
+ - name: Build
51
+ run: npm run build
52
+ - name: Release
53
+ env:
54
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55
+ NPM_CONFIG_PROVENANCE: true
56
+ run: npx semantic-release
package/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ ## [1.2.0](https://github.com/rvagg/bit-sequence/compare/v1.1.0...v1.2.0) (2026-02-16)
2
+
3
+ ### Features
4
+
5
+ * dep & CI updates & minor modernisation ([d37d229](https://github.com/rvagg/bit-sequence/commit/d37d229fea152b35e0329af0304bf9abb502abd7))
6
+
7
+ ### Trivial Changes
8
+
9
+ * **deps:** bump actions/setup-go from 5 to 6 ([#3](https://github.com/rvagg/bit-sequence/issues/3)) ([8786d6d](https://github.com/rvagg/bit-sequence/commit/8786d6d92408d6ffe069eae6b5cd8bb00c4d2919))
package/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # bit-sequence
2
2
 
3
- **Turn an arbitrary sequence of bits from a byte array and turn it into an integer**
3
+ [![NPM](https://nodei.co/npm/bit-sequence.svg?style=flat&data=n,v&color=blue)](https://nodei.co/npm/bit-sequence/)
4
+
5
+ **Turn an arbitrary sequence of bits from a byte array into an integer**
4
6
 
5
7
  * [JavaScript](#javascript)
6
8
  * [Example](#example)
@@ -8,9 +10,11 @@
8
10
  * [Go](#go)
9
11
  * [License and Copyright](#license-and-copyright)
10
12
 
11
- ## JavaScript
13
+ ## Requirements
12
14
 
13
- [![NPM](https://nodei.co/npm/bit-sequence.svg)](https://nodei.co/npm/bit-sequence/)
15
+ Node.js >= 20
16
+
17
+ ## JavaScript
14
18
 
15
19
  Given an `Array`-like containing bytes (unsigned 8-bit integers), extract an arbitrary sequence of the underlying bits and convert them into an unsigned integer value.
16
20
 
@@ -19,8 +23,8 @@ Useful for cases where a sub-sequence of bits within a longer byte sequence is u
19
23
  ### Example
20
24
 
21
25
  ```js
22
- const bitSequence = require('bit-sequence')
23
- const assert = require('assert')
26
+ import bitSequence from 'bit-sequence'
27
+ import assert from 'node:assert'
24
28
  const bytes = new Uint8Array([ 0b00010101, 0b10101000, 0b00000000, 0b00000000 ])
25
29
  // extract bits from here ^ to here ^
26
30
  const int = bitSequence(bytes, 7, 11)
package/go/go.mod CHANGED
@@ -1,3 +1,3 @@
1
1
  module github.com/rvagg/bit-sequence/go
2
2
 
3
- go 1.12
3
+ go 1.25
@@ -4,7 +4,7 @@
4
4
  * @param {number} bitLength
5
5
  * @returns {number}
6
6
  */
7
- function bitSequence (bytes, bitStart, bitLength) {
7
+ export default function bitSequence (bytes, bitStart, bitLength) {
8
8
  // making an assumption that bytes is an Array-like that will give us one
9
9
  // byte per element, so either an Array full of 8-bit integers or a
10
10
  // Uint8Array or a Node.js Buffer, or something like that
@@ -54,5 +54,3 @@ function bitSequence (bytes, bitStart, bitLength) {
54
54
 
55
55
  return result
56
56
  }
57
-
58
- module.exports = bitSequence
package/js/test.js CHANGED
@@ -1,5 +1,6 @@
1
- const assert = require('assert')
2
- const bitSequence = require('./bit-sequence.js')
1
+ import { test } from 'node:test'
2
+ import assert from 'node:assert'
3
+ import bitSequence from './bit-sequence.js'
3
4
 
4
5
  function binaryStringToBytes (s) {
5
6
  const byteLength = Math.ceil(s.length / 8)
@@ -11,104 +12,92 @@ function binaryStringToBytes (s) {
11
12
  return bytes
12
13
  }
13
14
 
14
- // sanity check binaryStringToBytes
15
- ;[
16
- '00000001:01',
17
- '10000000:80',
18
- '11111111:ff',
19
- '11000000:c0',
20
- '11110000:f0',
21
- '1111111111111111:ffff',
22
- '0000000000000001:0001',
23
- '000000000000000000000001:000001',
24
- '111111111111111111111111:ffffff',
25
- '100000001000000010000000:808080',
26
- '10000000100000001000000010000000:80808080',
27
- '10000000111111111000000011111111:80ff80ff',
28
- '001:01',
29
- '111:07',
30
- '1111:0f',
31
- '01111:0f',
32
- '001111:0f',
33
- '0000001111:000f',
34
- '10000000000001111:01000f'
35
- ].forEach((s) => {
36
- const [ binary, hex ] = s.split(':')
37
- const bytesHex = Array.prototype.map.call(
38
- binaryStringToBytes(binary),
39
- (b) => b.toString(16).padStart(2, '0')
40
- ).join('')
41
- // console.log(binary, '=>', binaryStringToBytes(binary).toString('hex'), '<>', hex, '?', parseInt(binary, 2).toString(16))
42
- assert.strictEqual(bytesHex, hex)
43
- // sanity check the sanity check by reading the binary
44
- assert.strictEqual(bytesHex.replace(/^0+/, ''), parseInt(binary, 2).toString(16))
15
+ test('binaryStringToBytes sanity check', () => {
16
+ ;[
17
+ '00000001:01',
18
+ '10000000:80',
19
+ '11111111:ff',
20
+ '11000000:c0',
21
+ '11110000:f0',
22
+ '1111111111111111:ffff',
23
+ '0000000000000001:0001',
24
+ '000000000000000000000001:000001',
25
+ '111111111111111111111111:ffffff',
26
+ '100000001000000010000000:808080',
27
+ '10000000100000001000000010000000:80808080',
28
+ '10000000111111111000000011111111:80ff80ff',
29
+ '001:01',
30
+ '111:07',
31
+ '1111:0f',
32
+ '01111:0f',
33
+ '001111:0f',
34
+ '0000001111:000f',
35
+ '10000000000001111:01000f'
36
+ ].forEach((s) => {
37
+ const [binary, hex] = s.split(':')
38
+ const bytesHex = Array.prototype.map.call(
39
+ binaryStringToBytes(binary),
40
+ (b) => b.toString(16).padStart(2, '0')
41
+ ).join('')
42
+ assert.strictEqual(bytesHex, hex)
43
+ assert.strictEqual(bytesHex.replace(/^0+/, ''), parseInt(binary, 2).toString(16))
44
+ })
45
45
  })
46
46
 
47
- const testCases = [
48
- '00000001',
49
- '11111111',
50
- '01010101',
51
- '10001000',
52
- '0000000000000001',
53
- '0000000100000001',
54
- '1111111111111111',
55
- '1010101010101010',
56
- '0101010101010101',
57
- '1001001001001001',
58
- '0100100100100100',
59
- '1000100010001000',
60
- '0100010001000100',
61
- '1111111100000000',
62
- '0000000011111111',
63
- '0000111111110000',
64
- '000000000000000000000001',
65
- '111111111111111111111111',
66
- '001001100100110010011111',
67
- '00000000000000000000000000000001',
68
- '11111111111111111111111111111111',
69
- '10000000000000000000000000000001',
70
- '10001100010110011110001010111010',
71
- '1111111111111111111111111111111111111111111111111111111111111111',
72
- '0000000000000000000000000000000000000000000000000000000000000001',
73
- '1000000000000000000000000000000000000000000000000000000000000001',
74
- '1010110100111110101110101001010001000000001101011101110010011111',
75
- '11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111',
76
- '1111101000010110000011111100000101110000010110111001100000000000',
77
- '10010101000110001000101011111111101000010110000011111100000101110000010110111001111000011001000000001000111101010010101001110000'
78
- ]
47
+ test('bitSequence extracts correct bit sequences', () => {
48
+ const testCases = [
49
+ '00000001',
50
+ '11111111',
51
+ '01010101',
52
+ '10001000',
53
+ '0000000000000001',
54
+ '0000000100000001',
55
+ '1111111111111111',
56
+ '1010101010101010',
57
+ '0101010101010101',
58
+ '1001001001001001',
59
+ '0100100100100100',
60
+ '1000100010001000',
61
+ '0100010001000100',
62
+ '1111111100000000',
63
+ '0000000011111111',
64
+ '0000111111110000',
65
+ '000000000000000000000001',
66
+ '111111111111111111111111',
67
+ '001001100100110010011111',
68
+ '00000000000000000000000000000001',
69
+ '11111111111111111111111111111111',
70
+ '10000000000000000000000000000001',
71
+ '10001100010110011110001010111010',
72
+ '1111111111111111111111111111111111111111111111111111111111111111',
73
+ '0000000000000000000000000000000000000000000000000000000000000001',
74
+ '1000000000000000000000000000000000000000000000000000000000000001',
75
+ '1010110100111110101110101001010001000000001101011101110010011111',
76
+ '11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111',
77
+ '1111101000010110000011111100000101110000010110111001100000000000',
78
+ '10010101000110001000101011111111101000010110000011111100000101110000010110111001111000011001000000001000111101010010101001110000'
79
+ ]
79
80
 
80
- let makeFixture = false
81
- if (process.argv[2] == '--fixture') {
82
- makeFixture = true
83
- }
84
- let asserts = 0
85
- let tooBig = 0
86
- testCases.forEach((s) => {
87
- const bytes = binaryStringToBytes(s)
81
+ let asserts = 0
82
+ let tooBig = 0
83
+ testCases.forEach((s) => {
84
+ const bytes = binaryStringToBytes(s)
88
85
 
89
- for (let start = 0; start < bytes.length * 8; start++) {
90
- for (let length = 1; length <= bytes.length * 8 - start; length++) {
91
- const expected = parseInt(s.substring(start, start + length), 2)
92
- if (makeFixture && length <= 32) {
93
- console.log([
94
- Buffer.from(binaryStringToBytes(s)).toString('hex'),
95
- start,
96
- length,
97
- expected
98
- ].join(','))
99
- }
100
- const actual = bitSequence(bytes, start, length)
101
- if (actual != expected && actual > Number.MAX_SAFE_INTEGER) {
102
- tooBig++
103
- continue
86
+ for (let start = 0; start < bytes.length * 8; start++) {
87
+ for (let length = 1; length <= bytes.length * 8 - start; length++) {
88
+ const expected = parseInt(s.substring(start, start + length), 2)
89
+ const actual = bitSequence(bytes, start, length)
90
+ if (actual !== expected && actual > Number.MAX_SAFE_INTEGER) {
91
+ tooBig++
92
+ continue
93
+ }
94
+ asserts++
95
+ assert.strictEqual(actual, expected, `[${s}] start=${start} length=${length} ${actual} <> ${expected}`)
96
+ assert.ok(actual >= 0, 'sanity check that we\'re only dealing with unsigned integers')
104
97
  }
105
- // console.log(`[${s}] start=${start} length=${length} ${actual} <> ${expected}`)
106
- asserts++
107
- assert.strictEqual(actual, expected, `[${s}] start=${start} length=${length} ${actual} <> ${expected}`)
108
- assert.ok(actual >= 0, 'sanity check that we\'re only dealing with unsigned integers')
109
98
  }
110
- }
111
- })
99
+ })
112
100
 
113
- assert.ok(asserts > 10000, 'did a lot of asserts')
114
- assert.ok(tooBig < 200, 'not too many non-matches beyond MAX_SAFE_INTEGER')
101
+ assert.ok(asserts > 10000, 'did a lot of asserts')
102
+ assert.ok(tooBig < 200, 'not too many non-matches beyond MAX_SAFE_INTEGER')
103
+ })
package/package.json CHANGED
@@ -1,16 +1,133 @@
1
1
  {
2
2
  "name": "bit-sequence",
3
- "version": "1.1.0",
4
- "description": "Turn an arbitrary sequence of bits from a byte array and turn it into an integer",
3
+ "version": "1.2.0",
4
+ "description": "Turn an arbitrary sequence of bits from a byte array into an integer",
5
+ "type": "module",
5
6
  "main": "js/bit-sequence.js",
6
- "types": "js/bit-sequence.d.ts",
7
+ "types": "types/bit-sequence.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./js/bit-sequence.js",
11
+ "types": "./types/bit-sequence.d.ts"
12
+ }
13
+ },
14
+ "engines": {
15
+ "node": ">=20"
16
+ },
7
17
  "scripts": {
8
- "test": "node js/test.js"
18
+ "lint": "standard js/*.js",
19
+ "build": "npm run build:types",
20
+ "build:types": "tsc --build",
21
+ "test:unit": "node --test js/test.js",
22
+ "test": "npm run lint && npm run build:types && npm run test:unit"
9
23
  },
10
24
  "author": "Rod <rod@vagg.org> (http://r.va.gg/)",
11
25
  "license": "Apache-2.0",
12
26
  "repository": {
13
27
  "type": "git",
14
28
  "url": "git://github.com/rvagg/bit-sequence.git"
29
+ },
30
+ "devDependencies": {
31
+ "@semantic-release/changelog": "^6.0.3",
32
+ "@semantic-release/commit-analyzer": "^13.0.1",
33
+ "@semantic-release/git": "^10.0.1",
34
+ "@semantic-release/github": "^12.0.6",
35
+ "@semantic-release/npm": "^13.1.4",
36
+ "@semantic-release/release-notes-generator": "^14.1.0",
37
+ "conventional-changelog-conventionalcommits": "^9.1.0",
38
+ "semantic-release": "^25.0.3",
39
+ "standard": "^17.1.2",
40
+ "typescript": "^5.9.3"
41
+ },
42
+ "typesVersions": {
43
+ "*": {
44
+ "*": [
45
+ "types/*"
46
+ ],
47
+ "types/*": [
48
+ "types/*"
49
+ ]
50
+ }
51
+ },
52
+ "release": {
53
+ "branches": [
54
+ "master"
55
+ ],
56
+ "plugins": [
57
+ [
58
+ "@semantic-release/commit-analyzer",
59
+ {
60
+ "preset": "conventionalcommits",
61
+ "releaseRules": [
62
+ {
63
+ "breaking": true,
64
+ "release": "major"
65
+ },
66
+ {
67
+ "revert": true,
68
+ "release": "patch"
69
+ },
70
+ {
71
+ "type": "feat",
72
+ "release": "minor"
73
+ },
74
+ {
75
+ "type": "fix",
76
+ "release": "patch"
77
+ },
78
+ {
79
+ "type": "chore",
80
+ "release": "patch"
81
+ },
82
+ {
83
+ "type": "docs",
84
+ "release": "patch"
85
+ },
86
+ {
87
+ "type": "test",
88
+ "release": "patch"
89
+ },
90
+ {
91
+ "scope": "no-release",
92
+ "release": false
93
+ }
94
+ ]
95
+ }
96
+ ],
97
+ [
98
+ "@semantic-release/release-notes-generator",
99
+ {
100
+ "preset": "conventionalcommits",
101
+ "presetConfig": {
102
+ "types": [
103
+ {
104
+ "type": "feat",
105
+ "section": "Features"
106
+ },
107
+ {
108
+ "type": "fix",
109
+ "section": "Bug Fixes"
110
+ },
111
+ {
112
+ "type": "chore",
113
+ "section": "Trivial Changes"
114
+ },
115
+ {
116
+ "type": "docs",
117
+ "section": "Trivial Changes"
118
+ },
119
+ {
120
+ "type": "test",
121
+ "section": "Tests"
122
+ }
123
+ ]
124
+ }
125
+ }
126
+ ],
127
+ "@semantic-release/changelog",
128
+ "@semantic-release/npm",
129
+ "@semantic-release/github",
130
+ "@semantic-release/git"
131
+ ]
15
132
  }
16
133
  }
package/tsconfig.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "compilerOptions": {
3
+ "allowJs": true,
4
+ "checkJs": true,
5
+ "forceConsistentCasingInFileNames": true,
6
+ "noImplicitReturns": false,
7
+ "noImplicitAny": true,
8
+ "noImplicitThis": true,
9
+ "noFallthroughCasesInSwitch": true,
10
+ "noUnusedLocals": true,
11
+ "noUnusedParameters": true,
12
+ "strictFunctionTypes": false,
13
+ "strictNullChecks": true,
14
+ "strictPropertyInitialization": true,
15
+ "strictBindCallApply": true,
16
+ "strict": true,
17
+ "alwaysStrict": true,
18
+ "esModuleInterop": true,
19
+ "target": "ES2022",
20
+ "module": "NodeNext",
21
+ "moduleResolution": "NodeNext",
22
+ "declaration": true,
23
+ "declarationMap": true,
24
+ "outDir": "types",
25
+ "skipLibCheck": true,
26
+ "stripInternal": true,
27
+ "emitDeclarationOnly": true,
28
+ "baseUrl": "."
29
+ },
30
+ "include": [
31
+ "js/bit-sequence.js"
32
+ ],
33
+ "exclude": [
34
+ "node_modules",
35
+ "types/*"
36
+ ]
37
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @param {Uint8Array} bytes
3
+ * @param {number} bitStart
4
+ * @param {number} bitLength
5
+ * @returns {number}
6
+ */
7
+ export default function bitSequence(bytes: Uint8Array, bitStart: number, bitLength: number): number;
8
+ //# sourceMappingURL=bit-sequence.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bit-sequence.d.ts","sourceRoot":"","sources":["../js/bit-sequence.js"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,2CALW,UAAU,YACV,MAAM,aACN,MAAM,GACJ,MAAM,CAmDlB"}
@@ -0,0 +1 @@
1
+ {"root":["../js/bit-sequence.js"],"version":"5.9.3"}
package/.travis.yml DELETED
@@ -1,19 +0,0 @@
1
- language: node_js
2
- matrix:
3
- include:
4
- - name: "Node.js 8"
5
- node_js: 8
6
- - name: "Node.js 10"
7
- node_js: 10
8
- - name: "Node.js 12"
9
- node_js: 12
10
- - name: "Node.js current"
11
- node_js: "node"
12
- - name: "Node.js LTS"
13
- node_js: "lts/*"
14
- - name: "Go"
15
- language: go
16
- go: 1.x
17
- script: cd go && go test
18
- script:
19
- - npm test
@@ -1,9 +0,0 @@
1
- export = bitSequence;
2
- /**
3
- * @param {Uint8Array} bytes
4
- * @param {number} bitStart
5
- * @param {number} bitLength
6
- * @returns {number}
7
- */
8
- declare function bitSequence(bytes: Uint8Array, bitStart: number, bitLength: number): number;
9
- //# sourceMappingURL=bit-sequence.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bit-sequence.d.ts","sourceRoot":"","sources":["./bit-sequence.js"],"names":[],"mappings":";AAAA;;;;;GAKG;AACH,oCALW,UAAU,YACV,MAAM,aACN,MAAM,GACJ,MAAM,CAmDlB"}