Skip to content

Commit

Permalink
Merge changes from next into main (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
trevor-anderson committed Jun 17, 2024
2 parents b1b67bb + afaf096 commit c64d389
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.

---

## [1.4.8-next.1](https://github.com/Nerdware-LLC/ts-string-helpers/compare/v1.4.7...v1.4.8-next.1) (2024-06-17)

## [1.4.7](https://github.com/Nerdware-LLC/ts-string-helpers/compare/v1.4.6...v1.4.7) (2024-06-08)

## [1.4.6](https://github.com/Nerdware-LLC/ts-string-helpers/compare/v1.4.5...v1.4.6) (2024-06-05)
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nerdware/ts-string-helpers",
"version": "1.4.7",
"version": "1.4.8-next.1",
"description": "TypeScript string utils for sanitization, validation, and formatting.",
"author": {
"name": "Trevor Anderson",
Expand Down Expand Up @@ -79,7 +79,7 @@
},
"overrides": {
"@serverless-guru/prettier-plugin-import-order": {
"prettier": "^3"
"prettier": "$prettier"
}
}
}
2 changes: 1 addition & 1 deletion src/sanitize/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import { getSanitizerFn } from "./_helpers.js";
* Removes all invalid email characters from `str` (see
* [RFC 5322](https://datatracker.ietf.org/doc/html/rfc5322)).
*/
export const sanitizeEmail = getSanitizerFn(/[^a-zA-Z0-9-._@+]/g);
export const sanitizeEmail = getSanitizerFn(/[^a-zA-Z0-9_@.+-]/g);
2 changes: 1 addition & 1 deletion src/sanitize/id.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe("sanitize: id", () => {
test("removes all non-ID characters", () => {
const input = `ab c${ZERO_WIDTH_SPACE}1 23${NULL_CONTROL_CHAR}~!@#$%^&*()_+-={}|:"<>?[]\\;',./`;
const result = sanitizeID(input);
expect(result).toBe("abc123#_-");
expect(result).toBe("abc123#-");
expect(result).not.toMatch(ZERO_WIDTH_AND_CONTROL_CHAR_REGEX);
});
});
4 changes: 2 additions & 2 deletions src/sanitize/id.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { getSanitizerFn } from "./_helpers.js";

/**
* Removes non-alphanumeric characters from `str` which are not `_`, `-`, or `#`.
* Removes non-alphanumeric characters from `str` which are not `#` or `-`.
*
* > Why those characters? This was designed with DynamoDB keys in mind.
*/
export const sanitizeID = getSanitizerFn(/[^a-zA-Z0-9-_#]/g);
export const sanitizeID = getSanitizerFn(/[^a-zA-Z0-9#-]/g);
10 changes: 6 additions & 4 deletions src/validate/id.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { isValidID } from "./id.js";
describe("validate: id", () => {
// POSITIVE TEST CASES:

test(`returns true when given a string containing only alphanumeric characters, "-", "_", and/or "#"`, () => {
expect(isValidID("fake-id#abc_123")).toBe(true);
test(`returns true when given a string containing only alphanumeric characters, "#", and/or "-"`, () => {
expect(isValidID("fake-id#abc123")).toBe(true);
});

// NEGATIVE TEST CASES:
Expand All @@ -19,9 +19,11 @@ describe("validate: id", () => {
expect(isValidID("fake-id#abc 123")).toBe(false);
});
test("returns false when given a string containing a disallowed special character", () => {
expect(isValidID("fake-id#abc_123.456!")).toBe(false);
expect(isValidID("fake-id#abc123_456")).toBe(false);
expect(isValidID("fake-id#abc123.456")).toBe(false);
expect(isValidID("fake-id#abc123456!")).toBe(false);
});
test("returns false when given a string containing a null unicode character", () => {
expect(isValidID("fake-id#abc_123\u0000")).toBe(false);
expect(isValidID("fake-id#abc123\u0000")).toBe(false);
});
});
4 changes: 2 additions & 2 deletions src/validate/id.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getRegexValidatorFn } from "./_helpers.js";

/**
* Returns `true` if `value` only contains alphanumeric characters, `_`, `-`, or `#`.
* Returns `true` if `value` only contains alphanumeric characters, `#`, or `-`.
*/
export const isValidID = getRegexValidatorFn(/^[a-zA-Z0-9-_#]{6,250}$/);
export const isValidID = getRegexValidatorFn(/^[a-zA-Z0-9#-]{6,250}$/);

0 comments on commit c64d389

Please sign in to comment.