Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Convert.IsHex and Convert.FromString #14

Merged
merged 6 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Publish
on:
push:
tags:
- v[0-9]+.[0-9]+.[0-9]+
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "22.x"
cache: "yarn"
- name: Install dependencies
run: yarn
- name: Build
run: npm run build
- name: Publish to NPM
run: |
npm set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
- name: Publish to GitHub
uses: softprops/action-gh-release@v2
with:
make_latest: true
generate_release_notes: true
23 changes: 5 additions & 18 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,16 @@ jobs:

strategy:
matrix:
node-version: [18.x]
node-version: [22.x]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
cache: "yarn"

- name: Install dependencies
run: yarn
Expand All @@ -40,6 +29,4 @@ jobs:
run: npm run coverage

- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
uses: coverallsapp/github-action@v2
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017-2022 Peculiar Ventures, LLC
Copyright (c) 2017-2024 Peculiar Ventures, LLC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
30 changes: 14 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,23 @@
},
"homepage": "https://github.com/PeculiarVentures/pvtsutils#readme",
"dependencies": {
"tslib": "^2.6.1"
"tslib": "^2.8.1"
},
"devDependencies": {
"@types/mocha": "^10.0.1",
"@types/node": "^20.4.8",
"coveralls": "^3.1.1",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"rimraf": "^5.0.1",
"rollup": "^3.27.2",
"rollup-plugin-dts": "^5.3.1",
"rollup-plugin-typescript2": "^0.35.0",
"ts-node": "^10.9.1",
"@types/mocha": "^10.0.10",
"@types/node": "^22.9.1",
"mocha": "^10.8.2",
"nyc": "^17.1.0",
"rimraf": "^6.0.1",
"rollup": "^4.27.3",
"rollup-plugin-dts": "^6.1.1",
"rollup-plugin-typescript2": "^0.36.0",
"ts-node": "^10.9.2",
"tslint": "^6.1.3",
"typescript": "^5.1.6"
"typescript": "^5.6.3"
},
"resolutions": {
"json5": "^2.2.2",
"semver": "^6.3.1",
"tough-cookie": "^4.1.3"
"braces": "^3.0.3",
"cross-spawn": "^7.0.6"
}
}
}
3 changes: 2 additions & 1 deletion rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export default [
compilerOptions: {
module: "ES2015",
removeComments: true,
}
},
exclude: ["test/**/*.ts"],
}
}),
],
Expand Down
2 changes: 1 addition & 1 deletion src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ declare function atob(data: string): string;

const STRING_TYPE = "string";

const HEX_REGEX = /^[0-9a-f]+$/i;
const HEX_REGEX = /^[0-9a-f\s]+$/i;
const BASE64_REGEX = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
const BASE64URL_REGEX = /^[a-zA-Z0-9-_]+$/;

Expand Down
7 changes: 7 additions & 0 deletions test/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ describe("Convert", () => {
const hex = Convert.ToHex(buf);
assert.strictEqual(hex, "010203");
});
it("decode with space and new line chars", () => {
const buf = Convert.FromHex(" 01\n02\r03 04\n");
assert.strictEqual(buf.byteLength, 4);
});
});

context("utf16", () => {
Expand Down Expand Up @@ -129,6 +133,9 @@ describe("Convert", () => {
it("wrong", () => {
assert.strictEqual(Convert.isHex("1234567890ABCDEF!"), false);
});
it("spaces and new lines", () => {
assert.strictEqual(Convert.isHex("1234\n5678 90AB\rCDEF"), true);
});
});

context("isBase64", () => {
Expand Down
Loading