Skip to content

Commit

Permalink
fjl - Tightened up some types and 'string' module member impls.
Browse files Browse the repository at this point in the history
  • Loading branch information
elycruz committed Dec 17, 2023
1 parent 5bcfe97 commit 586ffff
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/fjl/src/boolean/equal.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Equality combinator.
*/
export const equal = <T = any>(a: T, b: T) => a === b,
export const equal = <T>(a: T, b: T) => a === b,

/**
* Curried version of `equal`
Expand Down
4 changes: 2 additions & 2 deletions packages/fjl/src/function/compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import {Unary} from "../types";
* Composes all functions passed in from right to left passing each function's return value to
* the function on the left of itself.
*/
export const compose = <T = any>(...fns: Unary<T>[]): Unary<T> =>
(arg0: T): T => reduceRight((value: T, fn: Unary) => fn(value), arg0, fns);
export const compose = <T>(...fns: Unary<T>[]): Unary<T> =>
(arg0: T): T => reduceRight((value: T, fn: Unary<T>) => fn(value), arg0, fns);
11 changes: 8 additions & 3 deletions packages/fjl/src/string/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ export const
* Lower cases first character of a non-empty string.
* @throws {Error} - Throws error if receiving anything that is not a string.
*/
lcaseFirst = (xs: string): string => xs[0].toLowerCase() + xs.substring(1),
lcaseFirst = (xs: string): string => !xs ? '' : xs[0].toLowerCase() + xs.substring(1),

/**
* Upper cases first character of a non-empty string.
* @throws {Error} - Throws error if receiving anything that is not a string.
*/
ucaseFirst = (xs: string): string => xs[0].toUpperCase() + xs.substring(1),
ucaseFirst = (xs: string): string => !xs ? '' : xs[0].toUpperCase() + xs.substring(1),

/**
* Camel cases a string.
Expand All @@ -69,7 +69,6 @@ export const
}
return (upperCaseFirst ? id : lcaseFirst)(
xs.split(pattern)
.filter(Boolean)
.map(str => ucaseFirst(str.toLowerCase()))
.join('')
);
Expand All @@ -83,9 +82,15 @@ export const
*/
classCase = (xs: string): string => camelCase(xs, FirstCharCase.Upper),

/**
* Generates a random character.
*/
randChar = (min = 0, max = 0x10FFFF): string =>
String.fromCharCode(randNatNum(min, max)),

/**
* Generates a random string.
*/
randStr = (min = 0, max = 100): string =>
range(min, max)
.reduce(str => str + randChar(min, max), '')
Expand Down

0 comments on commit 586ffff

Please sign in to comment.