JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q46032F
  • License MIT

Lightweight GUID Implementation for Typescript

Package Exports

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@slimpleton/ts-guid) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    Typescript Guid

    A Typescript safe implementation of a GUID that allows for validation of the format while limiting boilerplate to reference the value itself. Uses types not classes to be more lightweight / reusable

    Installation and Usage

    Installation

    npm i @slimpleton13/ts-guid --save

    Basic Usage

    export class Xyz{
        public id: Guid;
        constructor(){
            this.id = createRandomGuid();
        }
        //or
        constructor(id: string){
            this.id = parseGuid(id);
        }
        //or
        constructor(id: `${string}-${string}-${string}-${string}-${string}`){
            this.id = parseExactGuid(id);
        }
    }
    

    Methods Included

    Method Description
    createRandomGuid(): Guid Creates a random Guid using crypto.randomUUID() and returns it strictly typed
    parseGuid(val: string): Guid Attempts to parse the value with loose Guid format
    parseExactGuid(val: string): Guid Attempts to parse the value with strict Guid format