diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..6313b56 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto eol=lf diff --git a/.github/workflows/prebuild.yml b/.github/workflows/prebuild.yml index ad6fabc..9e85b51 100644 --- a/.github/workflows/prebuild.yml +++ b/.github/workflows/prebuild.yml @@ -6,74 +6,74 @@ jobs: strategy: matrix: include: - - os: ubuntu-22.04 - platform: linux - arch: x64 - - os: ubuntu-22.04-arm64 - platform: linux - arch: arm64 - - os: ubuntu-22.04 - platform: android - arch: x64 - - os: ubuntu-22.04 - platform: android - arch: ia32 - - os: ubuntu-22.04 - platform: android - arch: arm64 - - os: ubuntu-22.04 - platform: android - arch: arm - - os: macos-14 - platform: darwin - arch: x64 - - os: macos-14 - platform: darwin - arch: arm64 - - os: macos-14 - platform: ios - arch: arm64 - - os: macos-14 - platform: ios - arch: arm64 - tags: -simulator - flags: --simulator - - os: macos-14 - platform: ios - arch: x64 - tags: -simulator - flags: --simulator - - os: windows-2022 - platform: win32 - arch: x64 - - os: windows-2022 - platform: win32 - arch: arm64 + - os: ubuntu-22.04 + platform: linux + arch: x64 + - os: ubuntu-22.04-arm64 + platform: linux + arch: arm64 + - os: ubuntu-22.04 + platform: android + arch: x64 + - os: ubuntu-22.04 + platform: android + arch: ia32 + - os: ubuntu-22.04 + platform: android + arch: arm64 + - os: ubuntu-22.04 + platform: android + arch: arm + - os: macos-14 + platform: darwin + arch: x64 + - os: macos-14 + platform: darwin + arch: arm64 + - os: macos-14 + platform: ios + arch: arm64 + - os: macos-14 + platform: ios + arch: arm64 + tags: -simulator + flags: --simulator + - os: macos-14 + platform: ios + arch: x64 + tags: -simulator + flags: --simulator + - os: windows-2022 + platform: win32 + arch: x64 + - os: windows-2022 + platform: win32 + arch: arm64 runs-on: ${{ matrix.os }} name: ${{ matrix.platform }}-${{ matrix.arch }}${{ matrix.tags }} steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: - node-version: lts/* - - run: npm install -g bare-runtime bare-make - - run: npm install - - run: bare-make generate --platform ${{ matrix.platform }} --arch ${{ matrix.arch }} ${{ matrix.flags }} - - run: bare-make build - - run: bare-make install - - uses: actions/upload-artifact@v4 - with: - name: ${{ matrix.platform }}-${{ matrix.arch }}${{ matrix.tags }} - path: prebuilds/* + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: lts/* + - run: npm install -g bare-runtime bare-make + - run: npm install + - run: bare-make generate --platform ${{ matrix.platform }} --arch ${{ matrix.arch }} ${{ matrix.flags }} + - run: bare-make build + - run: bare-make install + - uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.platform }}-${{ matrix.arch }}${{ matrix.tags }} + path: prebuilds/* merge: runs-on: ubuntu-latest needs: prebuild steps: - - uses: actions/download-artifact@v4 - with: - path: prebuilds - merge-multiple: true - - uses: actions/upload-artifact@v4 - with: - name: prebuilds - path: prebuilds + - uses: actions/download-artifact@v4 + with: + path: prebuilds + merge-multiple: true + - uses: actions/upload-artifact@v4 + with: + name: prebuilds + path: prebuilds diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cb82702..27db340 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,25 +11,25 @@ jobs: strategy: matrix: include: - - os: ubuntu-latest - platform: linux - arch: x64 - - os: macos-latest - platform: darwin - arch: arm64 - - os: windows-latest - platform: win32 - arch: x64 + - os: ubuntu-latest + platform: linux + arch: x64 + - os: macos-latest + platform: darwin + arch: arm64 + - os: windows-latest + platform: win32 + arch: x64 runs-on: ${{ matrix.os }} name: ${{ matrix.platform }}-${{ matrix.arch }} steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: - node-version: lts/* - - run: npm install -g bare-runtime bare-make - - run: npm install - - run: bare-make generate --platform ${{ matrix.platform }} --arch ${{ matrix.arch }} --debug - - run: bare-make build - - run: bare-make install - - run: npm test + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: lts/* + - run: npm install -g bare-runtime bare-make + - run: npm install + - run: bare-make generate --platform ${{ matrix.platform }} --arch ${{ matrix.arch }} --debug + - run: bare-make build + - run: bare-make install + - run: npm test diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..c18a05d --- /dev/null +++ b/.prettierrc @@ -0,0 +1 @@ +"prettier-config-standard" diff --git a/README.md b/README.md index 4d63632..d26e81b 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ npm i bare-hrtime ## Usage -``` js +```js const hrtime = require('bare-hrtime') hrtime() // returns [seconds, nanoseconds] diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..60f6c44 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,9 @@ +declare function hrtime( + prev?: ArrayLike +): [seconds: number, nanoseconds: number] + +declare namespace hrtime { + export function bigint(): bigint +} + +export = hrtime diff --git a/index.js b/index.js index 6d7f666..75e90b6 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,7 @@ const binding = require('./binding') const EMPTY = Uint32Array.of(0, 0) -module.exports = exports = function hrtime (prev = EMPTY) { +module.exports = exports = function hrtime(prev = EMPTY) { if (prev instanceof Uint32Array === false) prev = Uint32Array.from(prev) if (prev.length !== 2) { diff --git a/package.json b/package.json index 5394f11..0310fe2 100644 --- a/package.json +++ b/package.json @@ -2,9 +2,16 @@ "name": "bare-hrtime", "version": "2.0.10", "description": "High-resolution timers for JavaScript", - "main": "index.js", + "exports": { + ".": { + "types": "./index.d.ts", + "default": "./index.js" + }, + "./package": "./package.json" + }, "files": [ "index.js", + "index.d.ts", "binding.c", "binding.js", "CMakeLists.txt", @@ -12,7 +19,7 @@ ], "addon": true, "scripts": { - "test": "standard && bare test.js" + "test": "prettier . --check && bare test.js" }, "repository": { "type": "git", @@ -27,6 +34,7 @@ "devDependencies": { "brittle": "^3.2.1", "cmake-bare": "^1.1.6", - "standard": "^17.0.0" + "prettier": "^3.4.2", + "prettier-config-standard": "^7.0.0" } }