(options?: {
readonly splitRegExp?: RegExp | ReadonlyArray<RegExp> | undefined
readonly stripRegExp?: RegExp | ReadonlyArray<RegExp> | undefined
readonly delimiter?: string | undefined
readonly transform?: (
part: string,
index: number,
parts: ReadonlyArray<string>
) => string
}): (self: string) => string
(
self: string,
options?: {
readonly splitRegExp?: RegExp | ReadonlyArray<RegExp> | undefined
readonly stripRegExp?: RegExp | ReadonlyArray<RegExp> | undefined
readonly delimiter?: string | undefined
readonly transform?: (
part: string,
index: number,
parts: ReadonlyArray<string>
) => string
}
): stringNormalizes a string by splitting it into word parts, transforming each part, and joining the parts with a configurable delimiter.
When to use
Use when you need custom word-case output with a delimiter or part transform that the fixed case helpers do not provide.
export const const noCase: {
(options?: {
readonly splitRegExp?:
| RegExp
| ReadonlyArray<RegExp>
| undefined
readonly stripRegExp?:
| RegExp
| ReadonlyArray<RegExp>
| undefined
readonly delimiter?: string | undefined
readonly transform?: (
part: string,
index: number,
parts: ReadonlyArray<string>
) => string
}): (self: string) => string
(
self: string,
options?: {
readonly splitRegExp?:
| RegExp
| ReadonlyArray<RegExp>
| undefined
readonly stripRegExp?:
| RegExp
| ReadonlyArray<RegExp>
| undefined
readonly delimiter?: string | undefined
readonly transform?: (
part: string,
index: number,
parts: ReadonlyArray<string>
) => string
}
): string
}
Normalizes a string by splitting it into word parts, transforming each part,
and joining the parts with a configurable delimiter.
When to use
Use when you need custom word-case output with a delimiter or part transform
that the fixed case helpers do not provide.
noCase: {
(options: | {
readonly splitRegExp?:
| RegExp
| ReadonlyArray<RegExp>
| undefined
readonly stripRegExp?:
| RegExp
| ReadonlyArray<RegExp>
| undefined
readonly delimiter?: string | undefined
readonly transform?: (
part: string,
index: number,
parts: ReadonlyArray<string>
) => string
}
| undefined
options?: {
readonly splitRegExp?: RegExp | readonly RegExp[] | undefinedsplitRegExp?: RegExp | interface ReadonlyArray<T>ReadonlyArray<RegExp> | undefined
readonly stripRegExp?: RegExp | readonly RegExp[] | undefinedstripRegExp?: RegExp | interface ReadonlyArray<T>ReadonlyArray<RegExp> | undefined
readonly delimiter?: string | undefineddelimiter?: string | undefined
readonly transform?: | ((
part: string,
index: number,
parts: ReadonlyArray<string>
) => string)
| undefined
transform?: (part: stringpart: string, index: numberindex: number, parts: readonly string[]parts: interface ReadonlyArray<T>ReadonlyArray<string>) => string
}): (self: stringself: string) => string
(self: stringself: string, options: | {
readonly splitRegExp?:
| RegExp
| ReadonlyArray<RegExp>
| undefined
readonly stripRegExp?:
| RegExp
| ReadonlyArray<RegExp>
| undefined
readonly delimiter?: string | undefined
readonly transform?: (
part: string,
index: number,
parts: ReadonlyArray<string>
) => string
}
| undefined
options?: {
readonly splitRegExp?: RegExp | readonly RegExp[] | undefinedsplitRegExp?: RegExp | interface ReadonlyArray<T>ReadonlyArray<RegExp> | undefined
readonly stripRegExp?: RegExp | readonly RegExp[] | undefinedstripRegExp?: RegExp | interface ReadonlyArray<T>ReadonlyArray<RegExp> | undefined
readonly delimiter?: string | undefineddelimiter?: string | undefined
readonly transform?: | ((
part: string,
index: number,
parts: ReadonlyArray<string>
) => string)
| undefined
transform?: (part: stringpart: string, index: numberindex: number, parts: readonly string[]parts: interface ReadonlyArray<T>ReadonlyArray<string>) => string
}): string
} = dual<(...args: Array<any>) => any, (input: string, options?: {
readonly splitRegExp?: RegExp | ReadonlyArray<RegExp> | undefined;
readonly stripRegExp?: RegExp | ReadonlyArray<RegExp> | undefined;
readonly delimiter?: string | undefined;
readonly transform?: (part: string, index: number, parts: ReadonlyArray<string>) => string;
}) => string>(isDataFirst: (args: IArguments) => boolean, body: (input: string, options?: {
readonly splitRegExp?: RegExp | ReadonlyArray<RegExp> | undefined;
readonly stripRegExp?: RegExp | ReadonlyArray<RegExp> | undefined;
readonly delimiter?: string | undefined;
readonly transform?: (part: string, index: number, parts: ReadonlyArray<string>) => string;
}) => string): ((...args: Array<any>) => any) & ((input: string, options?: {
readonly splitRegExp?: RegExp | ReadonlyArray<RegExp> | undefined;
readonly stripRegExp?: RegExp | ReadonlyArray<RegExp> | undefined;
readonly delimiter?: string | undefined;
readonly transform?: (part: string, index: number, parts: ReadonlyArray<string>) => string;
}) => string) (+1 overload)
Creates a function that can be called in data-first style or data-last
(pipe-friendly) style.
When to use
Use to expose one implementation through both direct and pipe-friendly
call styles.
Details
Pass either the arity of the uncurried function or a predicate that decides
whether the current call is data-first. Arity is the common case. Use a
predicate when optional arguments make arity ambiguous.
Example (Selecting data-first or data-last style by arity)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(2, (self, that) => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Defining overloads with call signatures)
import { Function, pipe } from "effect"
const sum: {
(that: number): (self: number) => number
(self: number, that: number): number
} = Function.dual(2, (self: number, that: number): number => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Selecting data-first or data-last style with a predicate)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(
(args) => args.length === 2,
(self, that) => self + that
)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
dual((args: IArgumentsargs) => typeof args: IArgumentsargs[0] === "string", (input: stringinput: string, options: | {
readonly splitRegExp?:
| RegExp
| ReadonlyArray<RegExp>
| undefined
readonly stripRegExp?:
| RegExp
| ReadonlyArray<RegExp>
| undefined
readonly delimiter?: string | undefined
readonly transform?: (
part: string,
index: number,
parts: ReadonlyArray<string>
) => string
}
| undefined
options?: {
readonly splitRegExp?: RegExp | readonly RegExp[] | undefinedsplitRegExp?: RegExp | interface ReadonlyArray<T>ReadonlyArray<RegExp> | undefined
readonly stripRegExp?: RegExp | readonly RegExp[] | undefinedstripRegExp?: RegExp | interface ReadonlyArray<T>ReadonlyArray<RegExp> | undefined
readonly delimiter?: string | undefineddelimiter?: string | undefined
readonly transform?: | ((
part: string,
index: number,
parts: ReadonlyArray<string>
) => string)
| undefined
transform?: (part: stringpart: string, index: numberindex: number, parts: readonly string[]parts: interface ReadonlyArray<T>ReadonlyArray<string>) => string
}): string => {
const const delimiter: stringdelimiter = options: | {
readonly splitRegExp?:
| RegExp
| ReadonlyArray<RegExp>
| undefined
readonly stripRegExp?:
| RegExp
| ReadonlyArray<RegExp>
| undefined
readonly delimiter?: string | undefined
readonly transform?: (
part: string,
index: number,
parts: ReadonlyArray<string>
) => string
}
| undefined
options?.delimiter?: string | undefineddelimiter ?? " "
const const transform: (
part: string,
index: number,
parts: ReadonlyArray<string>
) => string
transform = options: | {
readonly splitRegExp?:
| RegExp
| ReadonlyArray<RegExp>
| undefined
readonly stripRegExp?:
| RegExp
| ReadonlyArray<RegExp>
| undefined
readonly delimiter?: string | undefined
readonly transform?: (
part: string,
index: number,
parts: ReadonlyArray<string>
) => string
}
| undefined
options?.transform?: | ((
part: string,
index: number,
parts: ReadonlyArray<string>
) => string)
| undefined
transform ?? const toLowerCase: <T extends string>(
self: T
) => Lowercase<T>
Converts a string to lowercase.
Example (Converting strings to lowercase)
import { pipe, String } from "effect"
import * as assert from "node:assert"
assert.deepStrictEqual(pipe("A", String.toLowerCase), "a")
assert.deepStrictEqual(String.toLowerCase("HELLO"), "hello")
toLowerCase
return const normalizeCase: (
input: string,
splitRegExp: ReadonlyArray<RegExp>,
stripRegExp: RegExp,
delimiter: string,
transform: (
part: string,
index: number,
parts: ReadonlyArray<string>
) => string
) => string
normalizeCase(input: stringinput, const SPLIT_REGEXP: RegExp[]SPLIT_REGEXP, const STRIP_REGEXP: RegExpSTRIP_REGEXP, const delimiter: stringdelimiter, const transform: (
part: string,
index: number,
parts: ReadonlyArray<string>
) => string
transform)
})