npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@huz-com/scalar

v1.0.30

Published

Handles primitive/scalar types as plain, array, map or map of

Downloads

90

Readme

Huz.Com > Component > Scalar

Handles primitive/scalar types as plain, array, map or map of

Standards

  • Language: TS
  • Eslint: Yes
  • Static Code Analysis: Yes IntelliJ Code Inspections
  • DDD - Document Driven: Yes
  • EDD - Exception Driven: Yes
  • TDD - Test Driven: Yes go to test folder
  • Standards Complied: Huz Standards

Commands

  • npm run clear // clears "dist" folder
  • npm run lint // runs eslint for static code analysis
  • npm run test // runs test files in "test" folder
  • npm run build // builds JS files at "dist" folder
  • npm publish or npm run publix // publishes "dist" folder to npm

Install

npm i @huz-com/scalar

Shared Options

Name | Type | Default | cast | castArray | castMap | Info --- | --- | --- | --- | --- | --- | --- log | boolean | true | [x] | [x] | [x] | logs when a problem error | boolean | false | [x] | [x] | [x] | throws when a problem mandatory | boolean | false | [x] | [o] | [o] | problem if null unique | boolean | false | [o] | [x] | [o] | removes duplicated items in array keepNullItems | boolean | false | [o] | [x] | [o] | keeps null items in array (default: remove nulls) minItems | integer | null | [o] | [x] | [o] | problem if array size is less than maxItems | integer | null | [o] | [x] | [o] | problem if array size is greater than keepNullValues | boolean | false | [o] | [o] | [x] | keeps null values in map (default: remove nulls) minKeys | integer | null | [o] | [o] | [x] | problem if object key size is less than maxKeys | integer | null | [o] | [o] | [x] | problem if object key size is greater than

Types

stringType/codeType/namerType/uuidType

  • Returns a string in any event ==> string|null
  • Trims texts (else noTrim:true)
  • Converts empty string to null (else noTrim:true)

Specific Options

Name | Type | Default | cast | castArray | castMap | Info --- | --- | --- | --- | --- | --- | --- noTrim | boolean | false | [x] | [x] | [x] | ignore trim (except uuidType) minLength | integer | null | [x] | [x] | [x] | problem if text length is less than (except uuidType) maxLength | integer | null | [x] | [x] | [x] | problem if text length is greater than (except uuidType) pattern | string | null | [x] | [x] | [x] | for only codeType and namerType

Most Used Function

  • stringType.is(value: any): boolean
  • stringType.cast(value: any, opt?: Options, req?: Request): string|null
  • stringType.castArray(value: any, opt?: Options, req?: Request): Array<string> // or Array<string|null> with keepNullItems:true
  • stringType.castMap(value: any, opt?: Options, req?: Request): Record<string, string> // or Record<string, string|null> with keepNullValues:true
  • stringType.castMapOf(value: any, opt?: Options, req?: Request): Record<string, any>

Samples

Call | Result --- | --- stringType.cast(undefined) | null stringType.cast(5) | "5" stringType.cast(true) | "true" stringType.cast(" ") | null stringType.cast(" foo bar ") | "foo bar" stringType.cast([" foo"]) | "foo" stringType.cast({id:5}) | "5" id property is special stringType.cast(() => 5) | "5" stringType.cast(" foo bar ", {noTrim:true}) | " foo bar " stringType.cast("foo bar", {error: true, minLength:10}) | throws stringType.cast("foo bar", {minLength:10}) | logs stringType.cast(" ", {error: true, mandatory:true}) | throws stringType.cast({a:1}) | logs stringType.castArray(null) | [] stringType.castArray("foo bar ") | ["foo bar"] stringType.castArray([5,true," foo bar", () => 4.5, {id:5}, null]) | ["5", "true", "foo bar", "4.5", "5"] stringType.castMap(null) | {} stringType.castMap({k1: 5, k2: true, k3: " foo bar", k4: () => 4.5, k5: {id:5}, k6: null}) | {k1: "5", k2: "true", k3: "foo bar", k4: "4.5", k5: "5"}

intType/floatType

  • Returns a number in any event ==> number|null
  • Converts infinite numbers to null
  • Converts nan numbers to null
  • Floors if number is float for only intType

Specific Options

Name | Type | Default | cast | castArray | castMap | Info --- | --- | --- | --- | --- | --- | --- def | integer | null | [x] | [x] | [x] | if null use default value min | integer | null | [x] | [x] | [x] | problem if value is less than max | integer | null | [x] | [x] | [x] | problem if value is greater than

Most Used Function

  • intType.is(value: any): boolean
  • intType.cast(value: any, opt?: Options, req?: Request): number|null
  • intType.castArray(value: any, opt?: Options, req?: Request): Array<number> // or Array<number|null> with keepNullItems:true
  • intType.castMap(value: any, opt?: Options, req?: Request): Record<string, number> // or Record<string, number|null> with keepNullValues:true
  • intType.castMapOf(value: any, opt?: Options, req?: Request): Record<number, any>

Samples

Call | Result --- | --- intType.cast(undefined) | null intType.cast("foo", {def:4}) | 4 intType.cast("5") | 5 intType.cast(true) | 1 intType.cast(false) | 0 intType.cast({id:5}) | 5 id property is special intType.cast(() => 5) | 5 intType.cast([5]) | 5 intType.cast(5.3) | 5 intType.cast(" foo bar ", {def: 5}) | 5 intType.cast("foo", {def: 5}) | 5 intType.cast("foo", {mandatory:true}) | logs intType.cast("5.3", {min:6, error: true}) | throws intType.castArray(undefined) | [] intType.castArray("5") | [5] intType.castArray([5,null]) | [5] intType.castArray(["5",null], {keepNullItems: true}) | [5, null] intType.castMap(undefined) | {} intType.castMap({k1:5, k2: null}) | {k1: 5} intType.castMap({k1:{id:5}, k2: null}, {keepNullValues: true}) | {k1: 5, k2: null}

boolType

  • Returns a boolean in any event ==> boolean|null
  • Converts most-used text to boolean [ true, t, yes, y, on, false, f, no, n, off ]
  • Converts positive numbers to true
  • Converts negative and zero numbers to false

Specific Options

Name | Type | Default | cast | castArray | castMap | Info --- | --- | --- | --- | --- | --- | --- def | boolean | null | [x] | [x] | [x] | if null use default value

Most Used Function

  • boolType.is(value: any): boolean
  • boolType.cast(value: any, opt?: Options, req?: Request): boolean|null
  • boolType.castArray(value: any, opt?: Options, req?: Request): Array<boolean> // or Array<boolean|null> with keepNullItems:true
  • boolType.castMap(value: any, opt?: Options, req?: Request): Record<string, boolean> // or Record<string, boolean|null> with keepNullValues:true

Samples

Call | Result --- | --- boolType.cast(undefined) | null boolType.cast(5) | true boolType.cast(-1) | false boolType.cast("on") | true boolType.cast("off") | false boolType.cast(() => "t") | true boolType.cast(["yes"]) | true boolType.cast(" foo bar ", {def: false}) | false boolType.cast("foo", {mandatory:true}) | logs boolType.castArray(undefined) | [] boolType.castArray("5") | [true] boolType.castArray(["on",null]) | [true] boolType.castArray(["off",null], {keepNullItems: true}) | [false, null] boolType.castMap(undefined) | {} boolType.castMap({k1:5, k2: null}) | {k1: true} boolType.castMap({k1:false, k2: null}, {keepNullValues: true}) | {k1: false, k2: null}

functionType

  • Returns a function in any event ==> function|null
  • Checks argument size if need
  • Supports default function if null

Specific Options

Name | Type | Default | cast | castArray | castMap | Info --- | --- | --- | --- | --- | --- | --- def | Function | null | [x] | [x] | [x] | if null use default value min | integer | null | [x] | [x] | [x] | problem if argument size is less than max | integer | null | [x] | [x] | [x] | problem if argument size is greater than

Most Used Function

  • functionType.is(value: any): boolean
  • functionType.cast(value: any, opt?: Options, req?: Request): Function|null
  • functionType.castArray(value: any, opt?: Options, req?: Request): Array<Function> // or Array<Function|null> with keepNullItems:true
  • functionType.castMap(value: any, opt?: Options, req?: Request): Record<string, Function> // or Record<string, Function|null> with keepNullValues:true

Samples

Call | Result --- | --- functionType.cast(undefined) | null functionType.cast(undefined, {def: () => 'foo'}) | () => 'foo' functionType.cast((p1) => 2 * p1, {min: 2}) | logs functionType.cast("foo", {mandatory:true, error: true}) | throws "foo" is not a function functionType.castArray(undefined) | [] functionType.castArray([() => 'foo',null]) | [() => 'foo'] functionType.castArray([() => 'foo',null], {keepNullItems: true}) | [() => 'foo', null] functionType.castMap(undefined) | {} functionType.castMap({k1:() => 'foo', k2: null}) | {k1: () => 'foo'} functionType.castMap({k1:() => 'foo', k2: null}, {keepNullValues: true}) | {k1: () => 'foo', k2: null}

Other Types

  • @todo
  • dateType

    Converts any date related (string, number, integer array, Date, Moment) value Date type

    • Date
    • Date[] | Array<Date>
    • {[key: string]: Date} | Record<string, Date>
  • isoDatetimeType [format: yyyy-mm-ddTHH:ii:ss.eee.Z]

    Converts any date related (string, number, integer array, Date, Moment) value ISO Datetime format

    • string
    • string[] | Array<string>
    • {[key: string]: string} | Record<string, string>
  • isoDateType [format: yyyy-mm-dd]

    Converts any date related (string, number, integer array, Date, Moment) value ISO Date format

    • string
    • string[] | Array<string>
    • {[key: string]: string} | Record<string, string>
  • isoTimeType [format: HH:ii:ss.eee.Z]

    Converts any date related (string, number, integer array, Date, Moment) value ISO Time format

    • string
    • string[] | Array<string>
    • {[key: string]: string} | Record<string, string>
  • momentType

    Converts any date related (string, number, integer array, Date, Moment) value Moment class

    • Moment
    • Moment[] | Array<Moment>
    • {[key: string]: Moment} | Record<string, Moment>
  • regExpType

    Validates Regexp (also converts string to RegExp)

    • RegExp
    • RegExp[] | Array<RegExp>
    • {[key: string]: RegExp} | Record<string, RegExp>
  • anyType

    For anonymous scalar type usage

    • any
    • any[] | Array<any>
    • {[key: string]: any} | Record<string, any>
  • arrayType

    For anonymous array usage

    • any[] | Array<any>
    • any[][] | Array<Array<any>>
    • {[key: string]: any[]} | Record<string, Array<any>>
  • objectType

    For anonymous object (also be called as map or record) usage

    • {[key: string]: any} | Record<string, any>
    • {[key: string]: any}[] | Array<Record<string, any>>
    • {[key: string]: {[sub: string]: any}} | Record<string, Record<string, any>>