Str.Code.TS
Str.Code / TS
Import
import { Str } from '@wollybeard/kit'
// Access via namespace
Str.Code.TS.someFunction()
import * as Str from '@wollybeard/kit/str'
// Access via namespace
Str.Code.TS.someFunction()
Functions
[F]
string
(str: string): string
Quote a string value for TypeScript code.
Examples:
Str.Code.TS.string('hello')
// '"hello"'
[F]
list
(items: string[]): string
Generate an array literal.
Examples:
Str.Code.TS.list(['a', 'b', 'c'])
// '[a, b, c]'
[F]
block
(content: string): string
Wrap content in curly braces.
Examples:
Str.Code.TS.block('a: string')
// '{\na: string\n}'
[F]
object
(entries: readonly (readonly [string, string])[]): string
Generate an object literal from entries.
Examples:
Str.Code.TS.object([['name', '"Alice"'], ['age', '30']])
// '{\nname: "Alice",\nage: 30\n}'
[F]
typeAlias
(name: string, type: string): string
Parameters:
name
- Type nametype
- Type expression
Returns: Type alias declaration
Generate a type alias.
Examples:
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
(options: TypeAliasOptions): string
Generate a type alias with optional JSDoc and type parameters.
Examples:
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
(options: InterfaceOptions): string
Generate an interface declaration.
Examples:
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
(declaration: string): string
Generate an export declaration.
Examples:
Str.Code.TS.exportDecl('const foo = 1')
// 'export const foo = 1'
[F]
reexportAll
(input: { from: string; type?: boolean; }): string
Re-export all exports from a module.
Examples:
Str.Code.TS.reexportAll({ from: './path' })
// 'export * from './path''
Str.Code.TS.reexportAll({ from: './path', type: true })
// 'export type * from './path''
[F]
reexportNamespace
(input: { as: string; from: string; type?: boolean; }): string
Re-export all exports as a namespace.
Examples:
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
(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:
// 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
(input: { as: string; from: string; type?: boolean; }): string
Import all exports as a namespace.
Examples:
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
(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:
// 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
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
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.