Skip to content

Str.Code.TS

Str.Code / TS

Import

typescript
import { Str } from '@wollybeard/kit'

// Access via namespace
Str.Code.TS.someFunction()
typescript
import * as Str from '@wollybeard/kit/str'

// Access via namespace
Str.Code.TS.someFunction()

Functions

[F] string

typescript
(str: string): string

Quote a string value for TypeScript code.

Examples:

typescript
Str
.Code.TS.string('hello')
// '"hello"'

[F] list

typescript
(items: string[]): string

Generate an array literal.

Examples:

typescript
Str
.Code.TS.list(['a', 'b', 'c'])
// '[a, b, c]'

[F] block

typescript
(content: string): string

Wrap content in curly braces.

Examples:

typescript
Str
.Code.TS.block('a: string')
// '{\na: string\n}'

[F] object

typescript
(entries: readonly (readonly [string, string])[]): string

Generate an object literal from entries.

Examples:

typescript
Str
.Code.TS.object([['name', '"Alice"'], ['age', '30']])
// '{\nname: "Alice",\nage: 30\n}'

[F] typeAlias

typescript
(name: string, type: string): string

Parameters:

  • name - Type name
  • type - Type expression

Returns: Type alias declaration

Generate a type alias.

Examples:

typescript
Str
.Code.TS.typeAlias('UserId', 'string')
// 'type UserId = string'
Str
.Code.TS.typeAlias('Point', '{ x: number; y: number }')
// 'type Point = { x: number; y: number }'

[F] typeAliasWithOptions

typescript
(options: TypeAliasOptions): string

Generate a type alias with optional JSDoc and type parameters.

Examples:

typescript
Str
.Code.TS.typeAliasWithOptions({
name
: 'Result',
type
: 'T | Error',
parameters
: ['T'],
tsDoc
: 'A result that may be successful or an error',
export
: true,
}) // /** // * A result that may be successful or an error // *\/ // export type Result<T> = T | Error

[F] interfaceDecl

typescript
(options: InterfaceOptions): string

Generate an interface declaration.

Examples:

typescript
Str
.Code.TS.interfaceDecl({
name
: 'User',
block
: 'id: string\nname: string',
tsDoc
: 'Represents a user',
export
: true,
}) // /** // * Represents a user // *\/ // export interface User { // id: string // name: string // }

[F] exportDecl

typescript
(declaration: string): string

Generate an export declaration.

Examples:

typescript
Str
.Code.TS.exportDecl('const foo = 1')
// 'export const foo = 1'

[F] reexportAll

typescript
(input: { from: string; type?: boolean; }): string

Re-export all exports from a module.

Examples:

typescript
Str
.Code.TS.reexportAll({
from
: './path' })
// 'export * from './path''
Str
.Code.TS.reexportAll({
from
: './path',
type
: true })
// 'export type * from './path''

[F] reexportNamespace

typescript
(input: { as: string; from: string; type?: boolean; }): string

Re-export all exports as a namespace.

Examples:

typescript
Str
.Code.TS.reexportNamespace({
as
: 'Name',
from
: './path' })
// 'export * as Name from './path''
Str
.Code.TS.reexportNamespace({
as
: 'Name',
from
: './path',
type
: true })
// 'export type * as Name from './path''

[F] reexportNamed

typescript
(input: { names: string | string[] | Record<string, string>; from: string; type?: boolean; }): string

Re-export named exports from a module. Supports simple names, arrays, and aliased names.

Examples:

typescript
// export { Name } from './path'
Str
.Code.TS.reexportNamed({
names
: 'Name',
from
: './path' })
// export { a, b, c } from './path'
Str
.Code.TS.reexportNamed({
names
: ['a', 'b', 'c'],
from
: './path' })
// export { oldName as newName } from './path'
Str
.Code.TS.reexportNamed({
names
: {
oldName
: 'newName' },
from
: './path' })
// export type { Name } from './path'
Str
.Code.TS.reexportNamed({
names
: 'Name',
from
: './path',
type
: true })

[F] importAll

typescript
(input: { as: string; from: string; type?: boolean; }): string

Import all exports as a namespace.

Examples:

typescript
Str.Code.TS.importAll({ 
as
: 'Name',
from
: './path' })
// 'import * as Name from './path'' Str.Code.TS.importAll({
as
: 'Name',
from
: './path',
type
: true })
// 'import type * as Name from './path''

[F] importNamed

typescript
(input: { names: string | string[] | Record<string, string>; from: string; type?: boolean; }): string

Import named exports from a module. Supports simple names, arrays, and aliased names.

Examples:

typescript
// import { Name } from './path'
Str.Code.TS.importNamed({ 
names
: 'Name',
from
: './path' })
// import { a, b, c } from './path' Str.Code.TS.importNamed({
names
: ['a', 'b', 'c'],
from
: './path' })
// import { oldName as newName } from './path' Str.Code.TS.importNamed({
names
: {
oldName
: 'newName' },
from
: './path' })
// import type { Name } from './path' Str.Code.TS.importNamed({
names
: 'Name',
from
: './path',
type
: true })

Types

[I] TypeAliasOptions

typescript
interface TypeAliasOptions {
  /**
   * Type name
   */
  name: string

  /**
   * Type expression
   */
  type: string

  /**
   * Optional JSDoc comment content (will be formatted automatically)
   */
  tsDoc?: string | null

  /**
   * Optional type parameters (e.g., `['T', 'U extends string']`)
   */
  parameters?: string[] | null

  /**
   * Whether to export the type (default: true)
   */
  export?: boolean
}

Options for generating a type alias with metadata.

[I] InterfaceOptions

typescript
interface InterfaceOptions {
  /**
   * Interface name
   */
  name: string

  /**
   * Interface body (fields)
   */
  block?: string

  /**
   * Optional JSDoc comment content (will be formatted automatically)
   */
  tsDoc?: string | null

  /**
   * Optional type parameters (e.g., `['T', 'U extends string']`)
   */
  parameters?: string[] | null

  /**
   * Optional extends clause (e.g., `['Base', 'Mixin']`)
   */
  extends?: string[] | null

  /**
   * Whether to export the interface (default: true)
   */
  export?: boolean
}

Options for generating an interface.