generated from bartveneman/node-package-starter
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bart Veneman
committed
Apr 14, 2024
1 parent
23c2e76
commit 0894061
Showing
13 changed files
with
6,985 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages | ||
|
||
name: NPM Publish | ||
|
||
on: | ||
release: | ||
types: [created] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
- run: npm install --ignore-scripts --no-audit | ||
- run: npm test | ||
|
||
publish-npm: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
registry-url: https://registry.npmjs.org/ | ||
- run: npm install --ignore-scripts --no-audit | ||
- run: npm run build | ||
- run: npm publish | ||
env: | ||
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions | ||
|
||
name: Tests | ||
|
||
on: | ||
push: | ||
branches: [master] | ||
pull_request: | ||
branches: [master] | ||
|
||
jobs: | ||
lint: | ||
name: Lint JS | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
- name: Lint JS | ||
run: npx --yes oxlint@latest -D perf | ||
types: | ||
name: Types | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Use Node.js 20 | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
cache: "npm" | ||
- name: Install dependencies | ||
run: npm install --ignore-scripts --no-audit | ||
- name: Test types | ||
run: npm run check | ||
test: | ||
name: Unit tests | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Use Node.js 20 | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
cache: "npm" | ||
- name: Install dependencies | ||
run: npm install --ignore-scripts --no-audit | ||
- name: Run unit tests | ||
run: npm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
node_modules | ||
package-lock.json | ||
.nyc_output | ||
dist |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Compare two CSS <time> values | ||
* @param {string} a | ||
* @param {string} b | ||
* @returns {number} 0 if equal, smaller than 0 if A is less than B, >0 if A is greater than B. `ms` will be sorted before `s` | ||
* @example | ||
* compare('1s', '2s') // -1 | ||
* compare('1000ms', '1s') // 0 | ||
*/ | ||
export function compare(a, b) { | ||
const A = convert(a) | ||
const B = convert(b) | ||
|
||
// If times are the same, put ms in front of s | ||
if (A === B) { | ||
return /\d+ms$/i.test(a) ? -1 : 1 | ||
} | ||
|
||
return A - B | ||
} | ||
|
||
/** | ||
* Convert a time string to ms | ||
* @param {string} time | ||
* @returns {number} | ||
* @example | ||
* convert('1s') // 1000 | ||
* convert('1ms') // 1 | ||
* convert('+2ms') // 2 | ||
* convert('var(--foo)') // Number.MAX_SAFE_INTEGER - 1 | ||
* convert('bars') // Number.MAX_SAFE_INTEGER | ||
*/ | ||
export function convert(time) { | ||
if (/\d+ms$/i.test(time)) { | ||
return Number(time.slice(0, time.length - 2)) | ||
} | ||
|
||
if (/\d+s$/i.test(time)) { | ||
return Number(time.slice(0, time.length - 1)) * 1000 | ||
} | ||
|
||
if (time.startsWith('var(')) { | ||
return Number.MAX_SAFE_INTEGER - 1 | ||
} | ||
|
||
return Number.MAX_SAFE_INTEGER | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.