@webreflection/utils 0.0.0 → 0.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.
- package/.github/dependabot.yml +13 -0
- package/.github/workflows/node.js.yml +31 -0
- package/README.md +18 -0
- package/package.json +27 -3
- package/src/shared-array-buffer.js +28 -0
- package/test/shared-array-buffer.js +22 -0
- package/test/with-resolvers.js +11 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Keep GitHub Actions up to date with GitHub's Dependabot...
|
|
2
|
+
# https://docs.github.com/en/code-security/dependabot/working-with-dependabot/keeping-your-actions-up-to-date-with-dependabot
|
|
3
|
+
# https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file#package-ecosystem
|
|
4
|
+
version: 2
|
|
5
|
+
updates:
|
|
6
|
+
- package-ecosystem: github-actions
|
|
7
|
+
directory: /
|
|
8
|
+
groups:
|
|
9
|
+
github-actions:
|
|
10
|
+
patterns:
|
|
11
|
+
- "*" # Group all Actions updates into a single larger pull request
|
|
12
|
+
schedule:
|
|
13
|
+
interval: weekly
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
|
|
2
|
+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
|
|
3
|
+
|
|
4
|
+
name: build
|
|
5
|
+
|
|
6
|
+
on: [push, pull_request]
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
build:
|
|
10
|
+
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
|
|
13
|
+
strategy:
|
|
14
|
+
matrix:
|
|
15
|
+
node-version: [22]
|
|
16
|
+
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v4
|
|
19
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
20
|
+
uses: actions/setup-node@v4
|
|
21
|
+
with:
|
|
22
|
+
node-version: ${{ matrix.node-version }}
|
|
23
|
+
cache: 'npm'
|
|
24
|
+
- run: npm ci
|
|
25
|
+
- run: npm run build --if-present
|
|
26
|
+
- run: npm run test
|
|
27
|
+
- run: npm run coverage --if-present
|
|
28
|
+
- name: Coveralls
|
|
29
|
+
uses: coverallsapp/github-action@master
|
|
30
|
+
with:
|
|
31
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# @webreflection/utils
|
|
2
|
+
|
|
3
|
+
[](https://coveralls.io/github/WebReflection/utils?branch=main)
|
|
4
|
+
|
|
5
|
+
<sup>**Social Media Photo by [benjamin lehman](https://unsplash.com/@abject) on [Unsplash](https://unsplash.com/)**</sup>
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
A [collection](./src/) of utility functions.
|
|
9
|
+
|
|
10
|
+
```js
|
|
11
|
+
// example: a shim based on ArrayBuffer if native is `false`
|
|
12
|
+
import { SharedArrayBuffer, native } from 'https://esm.run/@webreflection/utils/shared-array-buffer';
|
|
13
|
+
|
|
14
|
+
// example: self bound Promise.withResolvers()
|
|
15
|
+
import withResolvers from 'https://esm.run/@webreflection/utils/with-resolvers';
|
|
16
|
+
|
|
17
|
+
const { promise, resolve, reject } = withResolvers();
|
|
18
|
+
```
|
package/package.json
CHANGED
|
@@ -1,13 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webreflection/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
|
+
"./shared-array-buffer": "./src/shared-array-buffer.js",
|
|
6
7
|
"./with-resolvers": "./src/with-resolvers.js",
|
|
7
8
|
"./package.json": "./package.json"
|
|
8
9
|
},
|
|
9
|
-
"
|
|
10
|
+
"tests": [
|
|
11
|
+
"shared-array-buffer",
|
|
12
|
+
"with-resolvers"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"coverage": "mkdir -p ./coverage; c8 report --reporter=text-lcov > ./coverage/lcov.info",
|
|
16
|
+
"test": "c8 node -e 'let q=Promise.resolve();for(const t of require(`./package.json`).tests)q=q.then(()=>import(`./test/${t}.js`));'"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"shared",
|
|
20
|
+
"utility",
|
|
21
|
+
"utils"
|
|
22
|
+
],
|
|
10
23
|
"author": "Andrea Giammarchi",
|
|
11
24
|
"license": "MIT",
|
|
12
|
-
"description": "A collection of utility functions"
|
|
25
|
+
"description": "A collection of utility functions",
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/WebReflection/utils.git"
|
|
29
|
+
},
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/WebReflection/utils/issues"
|
|
32
|
+
},
|
|
33
|
+
"homepage": "https://github.com/WebReflection/utils#readme",
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"c8": "^10.1.3"
|
|
36
|
+
}
|
|
13
37
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//@ts-check
|
|
2
|
+
|
|
3
|
+
let { SharedArrayBuffer: SAB } = globalThis, native = true;
|
|
4
|
+
|
|
5
|
+
try {
|
|
6
|
+
//@ts-ignore due valid options not recognized
|
|
7
|
+
new SAB(4, { maxByteLength: 8 });
|
|
8
|
+
}
|
|
9
|
+
catch (_) {
|
|
10
|
+
native = false;
|
|
11
|
+
SAB = /** @type {SharedArrayBufferConstructor} */(
|
|
12
|
+
/** @type {unknown} */(
|
|
13
|
+
class SharedArrayBuffer extends ArrayBuffer {
|
|
14
|
+
get growable() {
|
|
15
|
+
//@ts-ignore due valid property not recognized
|
|
16
|
+
return super.resizable;
|
|
17
|
+
}
|
|
18
|
+
/** @param {number} newLength */
|
|
19
|
+
grow(newLength) {
|
|
20
|
+
//@ts-ignore due valid method not recognized
|
|
21
|
+
super.resize(newLength);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
)
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { SAB as SharedArrayBuffer, native };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const { SharedArrayBuffer: SAB } = globalThis;
|
|
2
|
+
|
|
3
|
+
globalThis.SharedArrayBuffer = null;
|
|
4
|
+
|
|
5
|
+
const { SharedArrayBuffer, native } = await import("../src/shared-array-buffer.js");
|
|
6
|
+
|
|
7
|
+
globalThis.SharedArrayBuffer = SAB;
|
|
8
|
+
|
|
9
|
+
console.assert(!native);
|
|
10
|
+
|
|
11
|
+
const gsab = new SharedArrayBuffer(4, { maxByteLength: 8 });
|
|
12
|
+
|
|
13
|
+
console.assert(gsab.byteLength === 4);
|
|
14
|
+
console.assert(gsab.growable);
|
|
15
|
+
|
|
16
|
+
gsab.grow(8);
|
|
17
|
+
|
|
18
|
+
console.assert(gsab.byteLength === 8);
|
|
19
|
+
|
|
20
|
+
const fsab = new SharedArrayBuffer(6);
|
|
21
|
+
console.assert(fsab.byteLength === 6);
|
|
22
|
+
console.assert(!fsab.growable);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import withResolvers from '../src/with-resolvers.js';
|
|
2
|
+
|
|
3
|
+
const { promise, resolve, reject } = withResolvers();
|
|
4
|
+
|
|
5
|
+
console.assert(typeof reject === 'function');
|
|
6
|
+
console.assert(typeof resolve === 'function');
|
|
7
|
+
console.assert(promise instanceof Promise);
|
|
8
|
+
|
|
9
|
+
resolve('OK');
|
|
10
|
+
|
|
11
|
+
console.log(await promise);
|