Metakit / @doeixd/metakit

Str

namespace · packages/metakit/src/ops/str.ts:12

export * as Str from './ops/str.js'

String primitives (str.len, str.startsWith, str.contains, str.lowerAscii, str.trim, the code-point orders str.lt, str.lte, str.gt, str.gte) and derived helper (Str.isEmpty). Null-strict: a null string gives null, and text holding a NUL character is refused (unportable), before null.

str.len counts Unicode code points ([...s].length) so JavaScript, Postgres (char_length), and SQLite (length) agree identically on surrogate pairs and emoji. Text is compared by character, as a database holds it: a lone surrogate, which UTF-8 cannot encode, reads as U+FFFD.

In the guides

Members

Str.byCodePoint

function · packages/metakit/src/ops/str.ts:123

function byCodePoint(a: string, b: string): number

-1, 0 or 1 as a is before, at or after b by code point, which UTF-16 order is not.

Str.codePointLength

function · packages/metakit/src/ops/str.ts:22

function codePointLength(s: string): number

Count Unicode code points in s (matches Postgres char_length and SQLite length).

Str.concat

function · packages/metakit/src/ops/str.ts:185

function concat<A extends NullableText, B extends NullableText>(
  left: A,
  right: B,
): Expr<EnvOfInput<A> & EnvOfInput<B>, string | NullOf<A> | NullOf<B>>

Concatenate two strings.

Str.concatOp

const · packages/metakit/src/ops/str.ts:103

const concatOp = { id, returns, nulls, refuses, evaluate }

Str.contains

function · packages/metakit/src/ops/str.ts:168

function contains<S extends NullableText, Sub extends NullableText>(
  value: S,
  substring: Sub,
): Expr<EnvOfInput<S> & EnvOfInput<Sub>, boolean | NullOf<S> | NullOf<Sub>>

True when value contains substring.

Str.containsOp

const · packages/metakit/src/ops/str.ts:75

const containsOp = { id, returns, nulls, refuses, evaluate }

Str.endsWith

function · packages/metakit/src/ops/str.ts:161

function endsWith<S extends NullableText, P extends NullableText>(
  value: S,
  suffix: P,
): Expr<EnvOfInput<S> & EnvOfInput<P>, boolean | NullOf<S> | NullOf<P>>

True when value ends with suffix.

Str.endsWithOp

const · packages/metakit/src/ops/str.ts:67

const endsWithOp = { id, returns, nulls, refuses, evaluate }

Str.gt

const · packages/metakit/src/ops/str.ts:205

const gt: TextOrder

left sorts after right by code point.

Str.gte

const · packages/metakit/src/ops/str.ts:207

const gte: TextOrder

left sorts after right, or is it, by code point.

Str.gteOp

const · packages/metakit/src/ops/str.ts:147

const gteOp: Node.Op<'str.gte'>

Str.gtOp

const · packages/metakit/src/ops/str.ts:146

const gtOp: Node.Op<'str.gt'>

Str.isEmpty

function · packages/metakit/src/ops/str.ts:210

function isEmpty<S extends NullableText>(value: S): Expr<EnvOfInput<S>, boolean>

Derived helper: Eq.is(Str.len(s), 0); false for a null string, whose length is null.

Str.len

function · packages/metakit/src/ops/str.ts:150

function len<S extends NullableText>(
  value: S,
): Expr<EnvOfInput<S>, number | NullOf<S>>

Unicode code-point length of a string (always >= 0).

Str.lenOp

const · packages/metakit/src/ops/str.ts:50

const lenOp = { id, returns, nulls, refuses, evaluate }

Str.lowerAscii

function · packages/metakit/src/ops/str.ts:175

function lowerAscii<S extends NullableText>(
  value: S,
): Expr<EnvOfInput<S>, string | NullOf<S>>

value with A to Z lowered and every other character kept: no locale's casing.

Str.lowerAsciiOp

const · packages/metakit/src/ops/str.ts:83

const lowerAsciiOp = { id, returns, nulls, refuses, evaluate }

Str.lt

const · packages/metakit/src/ops/str.ts:201

const lt: TextOrder

left sorts before right by code point (a database's binary, or COLLATE "C", order).

Str.lte

const · packages/metakit/src/ops/str.ts:203

const lte: TextOrder

left sorts before right, or is it, by code point.

Str.lteOp

const · packages/metakit/src/ops/str.ts:145

const lteOp: Node.Op<'str.lte'>

Str.ltOp

const · packages/metakit/src/ops/str.ts:144

const ltOp: Node.Op<'str.lt'>

Str.NullableText

type · packages/metakit/src/ops/str.ts:19

type NullableText = ExprInput<never, string | null>

A text operand; where it may be null, so may the result.

Str.startsWith

function · packages/metakit/src/ops/str.ts:154

function startsWith<S extends NullableText, P extends NullableText>(
  value: S,
  prefix: P,
): Expr<EnvOfInput<S> & EnvOfInput<P>, boolean | NullOf<S> | NullOf<P>>

True when value begins with prefix.

Str.startsWithOp

const · packages/metakit/src/ops/str.ts:59

const startsWithOp = { id, returns, nulls, refuses, evaluate }

Str.trim

function · packages/metakit/src/ops/str.ts:192

function trim<S extends NullableText>(
  value: S,
): Expr<EnvOfInput<S>, string | NullOf<S>>

value without leading or trailing space, tab, line feed or carriage return.

Str.trimOp

const · packages/metakit/src/ops/str.ts:114

const trimOp = { id, returns, nulls, refuses, evaluate }

Str.upperAscii

function · packages/metakit/src/ops/str.ts:180

function upperAscii<S extends NullableText>(
  value: S,
): Expr<EnvOfInput<S>, string | NullOf<S>>

value with a to z upper-cased and every other character kept: no locale's casing.

Str.upperAsciiOp

const · packages/metakit/src/ops/str.ts:93

const upperAsciiOp = { id, returns, nulls, refuses, evaluate }

Str.wellFormed

function · packages/metakit/src/nodeOps.ts:108

function wellFormed(text: string): string

text as SQLite's and Postgres's drivers hold it: each lone surrogate as U+FFFD.