Skip to content

Commit

Permalink
fix: tweak types
Browse files Browse the repository at this point in the history
  • Loading branch information
revelt committed Apr 18, 2022
1 parent b44dc8d commit e1e4166
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
22 changes: 11 additions & 11 deletions packages/string-trim-spaces-only/src/main.ts
Expand Up @@ -29,7 +29,7 @@ interface Res {
ranges: Ranges;
}

function trimSpaces(str: string, originalOpts?: Partial<Opts>): Res {
function trimSpaces(str: string, opts?: Partial<Opts>): Res {
// insurance:
if (typeof str !== "string") {
throw new Error(
Expand All @@ -40,18 +40,18 @@ function trimSpaces(str: string, originalOpts?: Partial<Opts>): Res {
)}`
);
}
// opts preparation:
let opts = { ...defaults, ...originalOpts };
// resolvedOpts preparation:
let resolvedOpts = { ...defaults, ...opts };

function check(char: string): boolean {
return (
(opts.classicTrim && !char.trim()) ||
(!opts.classicTrim &&
((opts.space && char === " ") ||
(opts.cr && char === "\r") ||
(opts.lf && char === "\n") ||
(opts.tab && char === "\t") ||
(opts.nbsp && char === "\u00a0")))
(resolvedOpts.classicTrim && !char.trim()) ||
(!resolvedOpts.classicTrim &&
((resolvedOpts.space && char === " ") ||
(resolvedOpts.cr && char === "\r") ||
(resolvedOpts.lf && char === "\n") ||
(resolvedOpts.tab && char === "\t") ||
(resolvedOpts.nbsp && char === "\u00a0")))
);
}

Expand Down Expand Up @@ -87,7 +87,7 @@ function trimSpaces(str: string, originalOpts?: Partial<Opts>): Res {
break;
}
// if we traversed the whole string this way and didn't stumble on a non-
// space/whitespace character (depending on opts.classicTrim), this means
// space/whitespace character (depending on resolvedOpts.classicTrim), this means
// whole thing can be trimmed:
if (i === str.length - 1) {
// this means there are only spaces/whitespace from beginning to the end
Expand Down
2 changes: 1 addition & 1 deletion packages/string-trim-spaces-only/types/index.d.ts
Expand Up @@ -17,6 +17,6 @@ interface Res {
res: string;
ranges: Ranges;
}
declare function trimSpaces(str: string, originalOpts?: Partial<Opts>): Res;
declare function trimSpaces(str: string, opts?: Partial<Opts>): Res;

export { defaults, trimSpaces, version };

0 comments on commit e1e4166

Please sign in to comment.