Skip to main content Link Search Menu Expand Document (external link)

Validate overview

Argument validation utilities for the note CLI.

Added in v0.1.0


Table of contents


Models

TitleInput (interface)

Parsed title input containing all derived values.

Signature

export interface TitleInput {
  /** Original words as provided */
  readonly words: Array.NonEmptyReadonlyArray<string>
  /** Joined title with spaces preserved */
  readonly title: string
  /** URL-safe slug derived from title */
  readonly slug: string
}

Added in v0.1.0

Schema

TitleInput

Schema that transforms a non-empty array of validated title words into a TitleInput containing the derived title and slug.

Uses mutable tuple type for compatibility with @effect/cli Args.atLeast(1).

Signature

export declare const TitleInput: Schema.Schema<TitleInput, [string, ...string[]], never>

Example

import * as Schema from "effect/Schema"
import { TitleInput } from "note/Validate"

const result = Schema.decodeUnknownSync(TitleInput)(["hello", "world"])
// result: { words: ["hello", "world"], title: "hello world", slug: "hello-world" }

Added in v0.1.0

TitleWord

Schema that validates a string is a plain title word.

Rejects strings that look like:

  • Flags (starting with - or --, or containing =)
  • Filenames (containing . with no spaces)

Signature

export declare const TitleWord: Schema.filter<Schema.filter<typeof Schema.String>>

Example

import * as Schema from "effect/Schema"
import { TitleWord } from "note/Validate"

// Valid title words pass through
Schema.decodeUnknownSync(TitleWord)("hello") // "hello"
Schema.decodeUnknownSync(TitleWord)("my-title") // "my-title"

Added in v0.1.0

Validation

looksLikeFilename

Checks if an argument looks like a filename (has dot, no spaces).

Returns true if the argument contains a dot AND has no spaces. This catches cases like “file.md”, “test.txt”, “config.json”.

Signature

export declare const looksLikeFilename: (arg: string) => boolean

Example

import { looksLikeFilename } from "note/Validate"

looksLikeFilename("file.md") // true
looksLikeFilename("test.txt") // true
looksLikeFilename("hello world") // false

Added in v0.1.0

looksLikeFlag

Checks if an argument looks like a flag (starts with - or –, or contains =).

Returns true if the argument:

  • Starts with “-“ (short flag or long flag)
  • Contains “=” (key=value syntax)

Signature

export declare const looksLikeFlag: (arg: string) => boolean

Example

import { looksLikeFlag } from "note/Validate"

looksLikeFlag("--help") // true
looksLikeFlag("-v") // true
looksLikeFlag("key=value") // true
looksLikeFlag("hello") // false

Added in v0.1.0