Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@maddimathon/utility-typescript

maddimathon605MIT2.0.0-betaTypeScript support: included

TypeScript utilities (types, functions, classes) to use in various projects.

javascript-library, javascript-utilities, javascript-utility, npm-package, npm-package-typescript, typescript-library, typescript-utilities, typescript-utility, typescript-utility-types

readme


title: ReadMe

Utility TypeScript @ 2.0.0-beta

TypeScript utilities (types, functions, classes) to use in various projects.

Probably not best to use in production/client-side without a bundler (and including only the required exports) to avoid bulk, inefficiency, and alpha/beta items.

The library aims to be pretty configurable, but it's definitely targeted towards my personal needs/preferences rather than (web) developers in general.

Changelog

Read it from the source or the docs site.

Install

npm i -D @maddimathon/utility-typescript@2.0.0-beta
npm i -D github:maddimathon/utility-typescript#2.0.0-beta

Use

For an overview of all exported items, including types, see the docs website below.

Read Documentation

Exports & Entry Points

There are four defined entry points, including the root, though it should be possible to target individual files (carefully and at your own risk, paths may change without being considered a breaking change). The root entry point exports the other entry points as modules.

import {
    type Types,
    classes,
    functions,
} from '@maddimathon/utility-typescript';

import type { ... } from '@maddimathon/utility-typescript/types';

import { ... } from '@maddimathon/utility-typescript/classes';
import { ... } from '@maddimathon/utility-typescript/functions';

Development & Coding Practices

This library is maintained by Maddi Mathon and is currently unlikely to accept other contributions.

Each file that defines items/exports should limit its exports to one item and its associated types, if applicable. Occasionally (and judiciously), it may make more sense to define a small number of closely-related items in the same file.

Directory Structure

All files required for development but ommitted from the published package should be in src/.

Files compiled in order to be included in the published package should be written to dist/.

Documentation should be a valid HTML static site (for use with GitHub Pages) with a home page at docs/index.html.

Scripts used for development (building, publishing, testing, etc.) should be in .scripts/. Subfolders for classes, functions, and variables separate resources from scripts meant to be run via npm.

Naming Conventions

Long and clear is better than short and confusing.

Abstract classes should start with Abstract (e.g., AbstractConfigurableClass).

Classes made only to be children of other classes should be prefixed with their parent class (e.g., ParentClass_Child).

Documentation

Documentation is good and helpful. The docs website for this package is mostly auto-generated from block comments and typing in the source. Keeping the readme and changelog up to date is also important.

TypeDoc

Documentation for the included JavaScript is generated from the TypeScript types and block comments in the source. Every new addition should be thoroughly documented from the start.

To include source code in documentation, add the @source block tag (uses typedoc-plugin-inline-sources).

Unit Testing

Unit tests are written in the source but run after compile and minimize (via Build or Test scripts). Tests should be written in a file with the same path but with .test added before the extension — e.g., myFunction.ts is tested by myFunction.test.ts.

TypeScript

Every subdirectory should have its own index.ts that re-exports the contents of its files. Types should also be tested using the utility types in {@link Types.Test}.

License

This library uses the MIT license. Please read and understand the license — I promise it’s short!

changelog


title: Changelog

Utility TypeScript Changelog

All notable changes to this project will be documented in this file after/on each release.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning, i.e.:

Given a version number [MAJOR].[MINOR].[PATCH], increment the:

  • [MAJOR] version when you make incompatible changes
  • [MINOR] version when you add backwards-compatible functionality
  • [PATCH] version when you make backwards-compatible bug fixes

2.0.0-beta — 2025-06-09

External testing complete, upgrading to beta.

2.0.0-alpha.1 — 2025-06-09

Fixed

  • Added NodeFiles.exists() checks to NodeFiles.copyFile(), NodeFiles.mkdir(), NodeFiles.readDir(), NodeFiles.readFile()
  • Fixed NodeFiles.mkdir() to be recursive by default

2.0.0-alpha — 2025-06-09

Renamed & Moved

  • AbstractBuildStage.runStage() changed name to runSubStage()
  • Meta type namespace was changed to Debug
  • NodeFiles methods:
    • deleteFiles() → delete()
    • writeFiles() → write()
  • NodeFiles types:
    • NodeFiles.Args.copyFileArgs → NodeFiles.Args.copyFile
    • NodeFiles.Args.readDirArgs → NodeFiles.Args.readDir
    • NodeFiles.Args.readFileArgs → NodeFiles.Args.readFile
    • NodeFiles.Args.writeFileArgs → NodeFiles.Args.writeFile
  • The following type namespaces’ contents are now global:
    • Arrays, Functions, Node, StringLiterals

Removed

  • Removed distinguishArrays option from typeOf() and removed typeOf args completely (now empty)
  • compileTypescript() method from AbstractStage (in build scripts)
  • abstractArgs() static method from AbstractConfigurableClass
  • abstractArgs() static method from AbstractBuildStage
  • NodeFunctions class removed
  • Functions class removed
  • Types:
    • mergeArgs namespace
    • MergeObjects
    • Node namespace (now had no contents)
    • NodeConsole.CmdErrorHandler

Misc. Breaking

  • NodeConsole.prompt is now an instance of NodeConsole_Prompt and not a method

Added

  • AbstractConfigurableClass method - valueOf()
  • NodeFiles methods (untested):
    • basename()
    • copyFile()
    • dirname()
    • exists()
    • getStats()
    • isDirectory()
    • isFile()
    • isSymLink()
    • mkdir()
    • readDir()
  • Additional NodeConsole_Prompt and NodeConsole_Error classes
  • Basic testing for NodeConsole.prompt (including types)
  • Added cmd method to AbstractStage (in build scripts) - better error handling
  • Types:
    • Json namespace with common schemas - TsConfig, PackageJson
    • Classify (with tests)
    • RecursiveRequired (with tests)
    • KeysOptional & KeysRequired (with tests)
    • PartialExcept & RecursivePartialExcept (with tests)
    • RequiredPartially & RecursiveRequiredPartially (with tests)

Changed

  • NodeConsole - Better errors and error handling (incluing prompt timeouts and <kbd>cntl<kbd> + <kbd>C<kbd>)
  • Added constructor params optional param to AnyClass type
  • Improved documentation
  • Improved Classify type

Fixed

  • Corrected vulnerable outdated inherited dependencies — cross-spawn, lodash, minimatch
  • MessageMaker - default node painter now checks for the existance of process.stdout.getColorDepth function
  • Added tests Test types namespace

1.0.0 — 2025-05-10

First full release!

Breaking

  • Changed ts output directory from dist/js to dist

0.4.4 — 2025-05-10

Fixed

  • Some exports for subpaths were missing the js/ subfolder in dist/
  • Release script was replacing the placeholders in the replacement script

0.4.3 — 2025-05-08

Changed

  • Minor build script improvements

Fixed

  • Fixed @inquirer/prompts dependency (was erroneously in devDependencies)
  • Snapshot stage's files weren't limited to files only, which slowed it significantly

0.4.2 — 2025-05-04

Added

  • AbstractBuildStage new method - isSubStageIncluded()

0.4.0 — 2025-05-04

Added

  • Added AbstractBuildStage - and updated build scripts accordingly
  • Added object type - MergeObjects - allows prettier types for merged objects (e.g., in mergeArgs())

Changed

  • Moved AbstractStage (build script) properties to AbstractBuildStage - fns, stages
  • Moved AbstractStage (build script) methods to AbstractBuildStage - buildArgs(), msgArgs(), progressLog(), run(), runStage(), startEndNotice(), verboseLog()

Fixed

  • Slight improvements to mergeArgs() typing

Removed

  • Removed replace-in-files-cli dependency and updated AbstractStage with custom implementation
  • Removed start npm scripts
  • Removed browser-sync dev dependency

0.3.0 — 2025-05-04

Breaking

  • Removed BuildFunctions
  • Moved BuildFunctions.releasePath and BuildFunctions.pkgVersion to AbstractStage
  • Moved BuildFunctions methods to AbstractStage - copyFiles(), datestamp(), datetimestamp(), glob(), timestamp()
  • Moved BuildFunctions.implodeWithIndent() to MessageMaker
  • Moved BuildFunctions.cmd() to NodeConsole

Added

  • NodeFiles methods - deleteFiles(), readFile(), writeFile()
  • NodeConsole (beta) method - cmdArgs()

Changed

  • NodeFiles.uniquePath() - slight performance improvements

Fixed

  • Minor build script improvements

Removed

  • Removed minify, prettify, catchErrCLI methods from AbstractStage (build scripts) - was unused
  • Removed hangingIndent methods from BuildFunctions (build scripts) - was protected

0.2.0 — 2025-05-02

Added

  • NodeFiles class for paths & files within node
  • NodeFiles methods - changeBaseName(), pathRelative(), pathResolve(), uniquePath()

Changed

  • Removed minimize in Build script — seemed to be causing occasaional issues

0.1.2 — 2025-05-02

Final quick fix and test to package publishing.

0.1.1 — 2025-05-02

Trying to fix npm publish workflow.

0.1.0 — 2025-05-02

Initial release; everything is new!

  • Set up the template from template-npm-library
  • Complete build scripts and system, including stages: Compile, Build, Test, Document, Snapshot, Package, Release
    • Publishes package to NPM (via GitHub workflow), updates GitHub repo meta, and creates a GitHub release
  • Automated documentation via TypeDoc
  • Testing with Jest and custom utility types

Classes

  • ./abstract - AbstractConfigurableClass
  • Some untested beta classes:
    • Functions, MessageMaker, VariableInspector
    • ./node - NodeConsole, NodeFunctions

Functions

  • ./arrays - arrayUnique()
  • ./objects - mergeArgs()
  • ./regex - escRegExp(), escRegExpReplace()
  • ./strings - slugify(), softWrapText(), timestamp(), toTitleCase()
  • typeOf()

Types

  • Type submodules: Arrays, Functions, Meta, Node, Objects, StringLiterals, Test
  • Some simple utility types