Sha256: a1d1e49ccd2ac07ed8a49a3f98dfd2f7357cf03649b9e348b58b97bb75116f18

Contents?: true

Size: 1.02 KB

Versions: 24

Compression:

Stored size: 1.02 KB

Contents

/**
Join an array of strings and/or numbers using the given string as a delimiter.

Use-case: Defining key paths in a nested object. For example, for dot-notation fields in MongoDB queries.

@example
```
import type {Join} from 'type-fest';

// Mixed (strings & numbers) items; result is: 'foo.0.baz'
const path: Join<['foo', 0, 'baz'], '.'> = ['foo', 0, 'baz'].join('.');

// Only string items; result is: 'foo.bar.baz'
const path: Join<['foo', 'bar', 'baz'], '.'> = ['foo', 'bar', 'baz'].join('.');

// Only number items; result is: '1.2.3'
const path: Join<[1, 2, 3], '.'> = [1, 2, 3].join('.');
```

@category Array
@category Template literal
*/
export type Join<
	Strings extends Array<string | number>,
	Delimiter extends string,
> = Strings extends [] ? '' :
	Strings extends [string | number] ? `${Strings[0]}` :
	// @ts-expect-error `Rest` is inferred as `unknown` here: https://github.com/microsoft/TypeScript/issues/45281
	Strings extends [string | number, ...infer Rest] ? `${Strings[0]}${Delimiter}${Join<Rest, Delimiter>}` :
	string;

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
immosquare-cleaner-0.1.51 node_modules/type-fest/source/join.d.ts
immosquare-cleaner-0.1.50 node_modules/type-fest/source/join.d.ts
immosquare-cleaner-0.1.49 node_modules/type-fest/source/join.d.ts
immosquare-cleaner-0.1.48 node_modules/type-fest/source/join.d.ts
immosquare-cleaner-0.1.47 node_modules/type-fest/source/join.d.ts
immosquare-cleaner-0.1.46 node_modules/type-fest/source/join.d.ts
immosquare-cleaner-0.1.45 node_modules/type-fest/source/join.d.ts
immosquare-cleaner-0.1.44 node_modules/type-fest/source/join.d.ts
immosquare-cleaner-0.1.43 node_modules/type-fest/source/join.d.ts
immosquare-cleaner-0.1.42 node_modules/type-fest/source/join.d.ts
immosquare-cleaner-0.1.41 node_modules/type-fest/source/join.d.ts
immosquare-cleaner-0.1.40 node_modules/type-fest/source/join.d.ts
immosquare-cleaner-0.1.39 node_modules/type-fest/source/join.d.ts
immosquare-cleaner-0.1.38 node_modules/type-fest/source/join.d.ts
immosquare-cleaner-0.1.32 node_modules/boxen/node_modules/type-fest/source/join.d.ts
immosquare-cleaner-0.1.31 node_modules/boxen/node_modules/type-fest/source/join.d.ts
immosquare-cleaner-0.1.30 node_modules/boxen/node_modules/type-fest/source/join.d.ts
immosquare-cleaner-0.1.29 node_modules/boxen/node_modules/type-fest/source/join.d.ts
immosquare-cleaner-0.1.28 node_modules/boxen/node_modules/type-fest/source/join.d.ts
immosquare-cleaner-0.1.27 node_modules/boxen/node_modules/type-fest/source/join.d.ts