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

fix(#142): update normalizeSync input type to string only #143

Merged
merged 2 commits into from
Mar 24, 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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ await normalize('söme stüff with áccènts'); // 'some stuff with accents'

## API Reference

### normalize([input])
### `normalize([input])`

- `input` <?[string][string-mdn-url]> Optional input string that contains accents/ diacritics.
- `input` <[string][string-mdn-url]> Input string that contains accents/diacritics.
- returns: <[Promise][promise-mdn-url]<[string][string-mdn-url]>> Promise which resolves with normalized input string.

This method normalizes any accents/ diacritics found in a given input string and output a normalized string as a result.

### normalizeSync([input])
### `normalizeSync([input])`

This methods works the same as `normalize([input])` except that this is the synchronous version.

Expand Down
60 changes: 39 additions & 21 deletions package-lock.json

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

3 changes: 1 addition & 2 deletions src/normalize-sync.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { diacritics } from './diacritics.js';

export function normalizeSync(input?: string | null): string {
export function normalizeSync(input: string): string {
if ('string' !== typeof(input)) {
throw new TypeError(`Expected 'input' to be of type string, but received '${input}'`);
}
Expand Down Expand Up @@ -28,6 +28,5 @@ export function normalizeSync(input?: string | null): string {
);

return normalized == null ? s : normalized.letter;
// return null == normalized ? s : normalized.letter;
});
}
2 changes: 1 addition & 1 deletion src/normalize.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { normalizeSync } from './normalize-sync.js';

export async function normalize(input?: string | null): Promise<string> {
export async function normalize(input: string): Promise<string> {
return normalizeSync(input);
}
1 change: 1 addition & 0 deletions src/tests/error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe(normalize.name, () => {
undefined,
])('throws error when calling normalize(%s)', async (testInput) => {
try {
// @ts-expect-error - Intentionally passing invalid input
await normalize(testInput);
} catch (error) {
expect(error).toEqual(
Expand Down
Loading