Skip to content

Commit

Permalink
Fixed some documentation and test-structure issues
Browse files Browse the repository at this point in the history
  • Loading branch information
robtimus committed Apr 20, 2024
1 parent e4cce9c commit e0c2837
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
3 changes: 3 additions & 0 deletions src/obfuscators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ export interface ObfuscatePortionOptions {
maskChar?: string;
}

/**
* @returns an immutable obfuscator that obfuscates a specific portion of its input.
*/
export function obfuscatePortion(options: ObfuscatePortionOptions): Obfuscator {
function validateNonNegativeNumber(value: number | undefined, name: string): number {
value = value ?? 0;
Expand Down
2 changes: 1 addition & 1 deletion src/splitPoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Obfuscator, obfuscateCustom } from "./obfuscators";

/**
* A point in a string to split obfuscation.
* Like {@link Obfuscator.untilLength}, this can be used to combine obfuscators. For instance, to obfuscate email addresses:
* Like {@link Obfuscator.untilLength} this can be used to combine obfuscators, e.g. to obfuscate email addresses.
* Unlike {@link Obfuscator.untilLength} it's not possible to chain splitting, but it's of course possible to nest it.
* @example
* const localPartObfuscator = obfuscatePortion({
Expand Down
34 changes: 17 additions & 17 deletions test/untilLength.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,26 +106,26 @@ describe("obfuscateWithFixedLength(3).untilLength(4)", () => {
expect(obfuscated).toBe(expected);
});
});
});

describe("invalid prefix lengths", () => {
it("first", () => {
const obfuscator = obfuscateNone;
expect(() => obfuscator.untilLength(0)).toThrow("0 <= 0");
});
describe("invalid prefix lengths", () => {
it("first", () => {
const obfuscator = obfuscateNone;
expect(() => obfuscator.untilLength(0)).toThrow("0 <= 0");
});

it("second", () => {
const obfuscator = obfuscateNone.untilLength(1).then(obfuscateAll());
expect(() => obfuscator.untilLength(1)).toThrow("1 <= 1");
});
it("second", () => {
const obfuscator = obfuscateNone.untilLength(1).then(obfuscateAll());
expect(() => obfuscator.untilLength(1)).toThrow("1 <= 1");
});

it("third", () => {
const obfuscator = obfuscateNone.untilLength(1).then(obfuscateAll()).untilLength(2).then(obfuscateNone);
expect(() => obfuscator.untilLength(2)).toThrow("2 <= 2");
});
it("third", () => {
const obfuscator = obfuscateNone.untilLength(1).then(obfuscateAll()).untilLength(2).then(obfuscateNone);
expect(() => obfuscator.untilLength(2)).toThrow("2 <= 2");
});

it("fourth", () => {
const obfuscator = obfuscateNone.untilLength(1).then(obfuscateAll()).untilLength(2).then(obfuscateNone).untilLength(3).then(obfuscateAll());
expect(() => obfuscator.untilLength(3)).toThrow("3 <= 3");
});
it("fourth", () => {
const obfuscator = obfuscateNone.untilLength(1).then(obfuscateAll()).untilLength(2).then(obfuscateNone).untilLength(3).then(obfuscateAll());
expect(() => obfuscator.untilLength(3)).toThrow("3 <= 3");
});
});

0 comments on commit e0c2837

Please sign in to comment.