Skip to content

Commit

Permalink
fix(#142): update normalizeSync input type to string only (#143)
Browse files Browse the repository at this point in the history
* fix(#142):  update normalizeSync input type to string only
* Update README.md

---------

Signed-off-by: Harvey Sanders <[email protected]>
Co-authored-by: The web walker <[email protected]>
  • Loading branch information
harveysanders and motss authored Mar 24, 2024
1 parent fda88b1 commit 4376983
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 27 deletions.
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

0 comments on commit 4376983

Please sign in to comment.