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

Package detail

@ganbarodigital/ts-lib-packagename

ganbarodigital7BSD-3-Clause0.3.2TypeScript support: included

Provides a PackageName type

readme

PackageName Type for Typescript

Node.js CI

Introduction

This TypeScript micro-library provides a PackageName type, along with helpers for validating the data.

Quick Start

# run this from your Terminal
npm install @ganbarodigital/ts-lib-packagename/v1
// add this import to your Typescript code
import { PackageName, packageNameFrom } from "@ganbarodigital/ts-lib-packagename/lib/v1"

VS Code users: once you've added a single import anywhere in your project, you'll then be able to auto-import anything else that this library exports.

V1 API

PackageName

/**
 * represents the name of a TypeScript package
 *
 * the package can be:
 * - any valid NPM package name
 * - and can include sub-package names too
 *
 * Sub-package names can include uppercase characters.
 *
 * examples of valid PackageNames include:
 *
 * - ts-lib-packagename
 * - @ganbarodigital/ts-lib-packagename
 * - @ganbarodigital/ts-lib-packagename/v1
 * - @ganbarodigital/ts-lib-packagename/V1/types
 *
 * Relative module names are not supported.
 *
 * At runtime, PackageName resolves to being just a `string`.
 */
export type PackageName = string & { "@ganbarodigital/PackageName": "@ganbarodigital/PackageName" };

PackageName is a type. (Strictly speaking, it's a branded type.) Use it to represent a valid TypeScript package name in type-safe code.

Use packageNameFrom() to create PackageName values.

packageNameFrom()

import { OnError, THROW_THE_ERROR } from "@ganbarodigital/ts-lib-error-reporting/lib/v1";

/**
 * smart constructor. Checks that the input string is a valid package name,
 * and converts it into a PackageName type.
 */
export function packageNameFrom(name: string, onError: OnError = THROW_THE_ERROR): PackageName;

packageNameFrom() is a smart constructor. Use it to turn strings into PackageName types.

isPackageNameData()

/**
 * data guard. confirms if a proposed name for a PackageName fits
 * our legal scheme or not.
 */
export function isPackageNameData(name: string): boolean;

isPackageNameData() is a data guard. Use it to determine if the input string contains a valid PackageName or not.

We do not check that the named package actually exists. We only check that the name meets our naming structure.

mustBePackageNameData()

import { OnError, THROW_THE_ERROR } from "@ganbarodigital/ts-lib-error-reporting/lib/v1";

/**
 * data guarantee. calls the supplied OnError handler if the input string
 * does not meet the specification for a valid PackageName.
 */
export function mustBePackageNameData(name: string, onError: OnError = THROW_THE_ERROR): void;

mustBePackageNameData() is a data guarantee. Use it to ensure that you're handling a valid PackageName string.

NPM Scripts

npm run clean

Use npm run clean to delete all of the compiled code.

npm run build

Use npm run build to compile the Typescript into plain Javascript. The compiled code is placed into the lib/ folder.

npm run build does not compile the unit test code.

npm run test

Use npm run test to compile and run the unit tests. The compiled code is placed into the lib/ folder.

npm run cover

Use npm run cover to compile the unit tests, run them, and see code coverage metrics.

Metrics are written to the terminal, and are also published as HTML into the coverage/ folder.

changelog

CHANGELOG

Introduction

This CHANGELOG tells you:

  • when a release was made
  • what is in each release

It also tells you what changes have been completed, and will be included in the next tagged release.

For each release, changes are grouped under these headings:

  • Backwards-Compatibility Breaks: a list of any backwards-compatibility breaks
  • New: a list of new features. If the feature came from a contributor via a PR, make sure you link to the PR and give them a mention here.
  • Fixes: a list of bugs that have been fixed. If there's an issue for the bug, make sure you link to the GitHub issue here.
  • Dependencies: a list of dependencies that have been added / updated / removed.
  • Tools: a list of bundled tools that have been added / updated / removed.

develop branch

The following changes have been completed, and will be included in the next tagged release.

v0.3.2

Released Tuesday, 19th May 2020.

Fixes

  • No longer relies on the internal export file from ts-lib-error-reporting

Dependencies

  • Upgraded to @ganbarodigital/ts-lib-error-reporting v0.3.3.
  • Upgraded to TypeScript v3.9.x

v0.3.1

Released Monday, 18th May 2020.

Dependencies

  • Upgraded to v0.3.0 of @ganbarodigital/ts-lib-http-types
    • should have been done in the v0.3.0 release!

Tools

  • Upgraded the 'scripts' section in package.json to the latest standard.

v0.3.0

Released Friday, 17th April 2020.

Dependencies

  • Upgraded to v0.3 of `@ganbarodigital/ts-lib-error-reporting'

v0.2.4

Released Monday, 6th April 2020.

Dependencies

  • Upgraded everything to fix a vulnerability in minimist
  • Moved TypeScript et al into the devDependencies section

v0.2.3

Released Thursday, 20th February 2020.

Refactor

  • We now republish internal types/functions from ts-lib-error-reporting
    • addresses ongoing circular dependency problems
    • ensures we never get out-of-sync with the definitions in ts-lib-error-reporting

v0.2.2

Released Thursday, 20th February 2020.

Dependencies

  • Added explicit dep on ts-lib-http-types
    • needed after upstream changes to ts-lib-error-reporting

v0.2.1

Released Thursday, 20th February 2020.

Dependencies

  • Updated to latest release of ts-lib-error-reporting.

v0.2.0

Released Thursday, 20th February 2020.

Backwards-Compatibility Breaks

  • All error handling has been switched over to the @ganbarodigital/ts-lib-error-reporting library.

v0.1.0

Released Sunday, 2nd February 2020.

New

  • Added PackageName type.
  • Added isPackageNameData() data guard.
  • Added mustBePackageNameData() data guarantee.
  • Added packageNameFrom() smart constructor.