import { isNonEmptyString } from 'ts-data-forge'; import { type NonEmptyString } from 'ts-type-forge'; import { string, type StringConstraintsResultType, type StringTypeConstraints, } from '../../../primitives/index.mjs'; import { type Type } from '../../../type.mjs'; export type { NonEmptyString } from 'ts-type-forge'; /** * The constraints accepted by {@link nonEmptyString}: every {@link string} * constraint except `nonempty`, which is always implied. */ export type NonEmptyStringConstraints = Omit; export function nonEmptyString(defaultValue?: string): Type; export function nonEmptyString( defaultValue: string, constraints: C, ): Type>>; export function nonEmptyString( defaultValue: string = ' ', constraints?: NonEmptyStringConstraints, ): Type { // `nonempty` is always implied; the remaining constraints (if any) are // forwarded to `string`, which validates them at runtime and refines the // result type the same way it does for a plain string type. return string(defaultValue, { nonempty: true, ...constraints }); } if (import.meta.vitest !== undefined) { test('defaultValue', () => { // eslint-disable-next-line ts-data-forge/no-unnecessary-type-guard assert.isTrue(isNonEmptyString(' ')); }); }