Skip to content

Commit ea10397

Browse files
committed
fix: lint and tests
1 parent 409780d commit ea10397

10 files changed

Lines changed: 64 additions & 10 deletions

File tree

src/_internals/sanitize-to-alphanumeric/sanitize-to-alphanumeric.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@
1212
* ```
1313
*/
1414
export const sanitizeToAlphanumeric = (value: string | number): string =>
15-
value.toString().replace(/[^A-Za-z0-9]/g, "").toUpperCase();
15+
value
16+
.toString()
17+
.replace(/[^A-Za-z0-9]/g, "")
18+
.toUpperCase();

src/_internals/test/runtime-deno.ts

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function createMock<TArgs extends unknown[] = unknown[], TResult = unknown>(
126126
return mockFn;
127127
}
128128

129-
function createExpect(actual: unknown) {
129+
function createMatchers(actual: unknown) {
130130
return {
131131
toBe(expected: unknown) {
132132
if (!Object.is(actual, expected)) {
@@ -156,6 +156,23 @@ function createExpect(actual: unknown) {
156156
throw createAssertionError(`Expected value to contain ${String(expected)}`);
157157
}
158158
},
159+
toMatch(expected: RegExp | string) {
160+
if (typeof actual !== "string") {
161+
throw createAssertionError("Expected value to be a string");
162+
}
163+
164+
if (expected instanceof RegExp) {
165+
if (!expected.test(actual)) {
166+
throw createAssertionError(`Expected ${actual} to match ${String(expected)}`);
167+
}
168+
169+
return;
170+
}
171+
172+
if (!actual.includes(expected)) {
173+
throw createAssertionError(`Expected ${actual} to contain ${expected}`);
174+
}
175+
},
159176
toContainEqual(expected: unknown) {
160177
if (!Array.isArray(actual)) {
161178
throw createAssertionError("Expected value to be an array");
@@ -225,6 +242,32 @@ function createExpect(actual: unknown) {
225242
throw createAssertionError("Expected object to match");
226243
}
227244
},
245+
};
246+
}
247+
248+
function createExpect(actual: unknown) {
249+
const matchers = createMatchers(actual);
250+
251+
return {
252+
...matchers,
253+
get resolves() {
254+
const promise = Promise.resolve(actual);
255+
256+
return Object.fromEntries(
257+
Object.entries(createMatchers(undefined)).map(([name]) => [
258+
name,
259+
async (...args: unknown[]) => {
260+
const resolved = await promise;
261+
const resolvedMatchers = createMatchers(resolved) as Record<
262+
string,
263+
(...args: unknown[]) => unknown
264+
>;
265+
266+
return resolvedMatchers[name](...args);
267+
},
268+
]),
269+
);
270+
},
228271
get rejects() {
229272
return {
230273
async toThrow(expected?: new (...args: any[]) => unknown) {

src/get-cep-info-by-address/get-cep-info-by-address.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ export type GetCepInfoByAddressOptions = {
4242

4343
const VALID_STATE_CODES = new Set<StateCode>(STATES.map((state) => state.code));
4444

45-
const isStateCode = (value: string): value is StateCode => VALID_STATE_CODES.has(value as StateCode);
45+
const isStateCode = (value: string): value is StateCode =>
46+
VALID_STATE_CODES.has(value as StateCode);
4647

4748
const normalizeAddressPart = (value: string): string =>
4849
value

src/parse-boleto/parse-boleto.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ import { LENGTH } from "../format-boleto/constants";
77
* @param {string|number} value - The boleto value to be parsed.
88
* @returns {string} The boleto value without formatting.
99
*/
10-
export const parseBoleto = (value: string | number): string => sanitizeToDigits(value).slice(0, LENGTH);
10+
export const parseBoleto = (value: string | number): string =>
11+
sanitizeToDigits(value).slice(0, LENGTH);

src/parse-cep/parse-cep.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ import { LENGTH } from "../format-cep/constants";
77
* @param {string|number} value - The CEP value to be parsed.
88
* @returns {string} The CEP value without formatting.
99
*/
10-
export const parseCep = (value: string | number): string => sanitizeToDigits(value).slice(0, LENGTH);
10+
export const parseCep = (value: string | number): string =>
11+
sanitizeToDigits(value).slice(0, LENGTH);

src/parse-cnh/parse-cnh.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { sanitizeToDigits } from "../_internals/sanitize-to-digits/sanitize-to-digits";
22
import { LENGTH } from "./constants";
33

4-
export const parseCnh = (value: string | number): string => sanitizeToDigits(value).slice(0, LENGTH);
4+
export const parseCnh = (value: string | number): string =>
5+
sanitizeToDigits(value).slice(0, LENGTH);

src/parse-cpf/parse-cpf.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ import { LENGTH } from "../format-cpf/constants";
77
* @param {string|number} value - The CPF value to be parsed.
88
* @returns {string} The CPF value without formatting.
99
*/
10-
export const parseCpf = (value: string | number): string => sanitizeToDigits(value).slice(0, LENGTH);
10+
export const parseCpf = (value: string | number): string =>
11+
sanitizeToDigits(value).slice(0, LENGTH);

src/parse-phone/parse-phone.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ import { LENGTH } from "./constants";
77
* @param {string|number} value - The phone value to be parsed.
88
* @returns {string} The phone value without formatting.
99
*/
10-
export const parsePhone = (value: string | number): string => sanitizeToDigits(value).slice(0, LENGTH);
10+
export const parsePhone = (value: string | number): string =>
11+
sanitizeToDigits(value).slice(0, LENGTH);

src/parse-pis/parse-pis.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ import { LENGTH } from "../format-pis/constants";
77
* @param {string|number} value - The PIS value to be parsed.
88
* @returns {string} The PIS value without formatting.
99
*/
10-
export const parsePis = (value: string | number): string => sanitizeToDigits(value).slice(0, LENGTH);
10+
export const parsePis = (value: string | number): string =>
11+
sanitizeToDigits(value).slice(0, LENGTH);
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { sanitizeToDigits } from "../_internals/sanitize-to-digits/sanitize-to-digits";
22
import { LENGTH } from "./constants";
33

4-
export const parseVoterId = (value: string | number): string => sanitizeToDigits(value).slice(0, LENGTH);
4+
export const parseVoterId = (value: string | number): string =>
5+
sanitizeToDigits(value).slice(0, LENGTH);

0 commit comments

Comments
 (0)