Gathering detailed insights and metrics for @zitterorg/iusto-ipsum
Gathering detailed insights and metrics for @zitterorg/iusto-ipsum
Gathering detailed insights and metrics for @zitterorg/iusto-ipsum
Gathering detailed insights and metrics for @zitterorg/iusto-ipsum
npm install @zitterorg/iusto-ipsum
Typescript
Module System
Node Version
NPM Version
54.1
Supply Chain
82.3
Quality
85.6
Maintenance
100
Vulnerability
99.3
License
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
0%
1
Compared to previous week
Last month
-33.3%
2
Compared to previous month
Last year
0%
10
Compared to previous year
41
A vanilla JavaScript library for checking the type of variables in a more robust and accurate way than the typeof operator.
Provides a simple and easy-to-use interface for checking the types of values in JavaScript.
Allows you to check the type of a single value or multiple values at once.
Provides options for customizing the behavior of the TypeOf
class.
Provides a set of methods for checking the type of values such as isNumber
, isObject
, isBigInt
, etc.
It also comes with some other useful methods such as isEmptyArray
, isBooleanTrue
, isNumberZero
, etc.
To install @zitterorg/iusto-ipsum
, you can use npm:
npm install @zitterorg/iusto-ipsum
1// See the output of the typeOfHelp method for a list of all the supported types and helper methods. 2import typeOfShorthand from "@zitterorg/iusto-ipsum"; 3const { 4 isString 5} = typeOfShorthand; 6console.log(isString("hello")); // true 7
1import { typeOfHelp } from "@zitterorg/iusto-ipsum"; 2typeOfHelp();
The typeOfHelp
function provides help information on the supported types and helper methods. It will console.log
the following string to the console:
The name of each type and helper method is a combination of a 'use case' name and a 'type/helper' name.
For instance, the method 'isString' which checks if one or all values are a string is a combination of the 'use case' name 'is' and the 'type/helper' name 'String'.
1import { TypeOf } from "@zitterorg/iusto-ipsum"; 2 3const typeOfInstance = new TypeOf("hello", 42, true); 4console.log(typeOfInstance.isString); // false 5console.log(typeOfInstance.someValueIsString); // true 6console.log(typeOfInstance.someValueNotNumber); // true 7 8const types = typeOfInstance.getTypeOf(); 9console.log(types); // ["string", "number", "boolean"] 10 11
A simple try-catch example for handling the error thrown when using the notTypeOf
method:
1import { TypeOf } from "@zitterorg/iusto-ipsum"; 2// Create a new instance of the TypeHelper class. Take note that no values are provided to the constructor. 3const tryTypeOf = new TypeOf(); 4try { 5 // This will throw an error because there are no values to check provided to the constructor. 6 tryTypeOf.notTypeOf('object'); 7} catch (error) { 8 console.error(error.name); // InvalidValuesToCheckError 9 console.error(error.message); // No values to check were provided! 10}
1import { TypeOf } from "@zitterorg/iusto-ipsum"; 2const optionsTypeOf = new TypeOf("hello", 42, true); 3 4optionsTypeOf.setOptions = { 5 enableCapitalizedTypeNames: true, 6 disableThrowErrors: true, 7}; 8console.log(optionsTypeOf.getTypeOf());
The getTypeOf
function allows you to get the type of a single value or multiple values at once.
1import { getTypeOf } from "@zitterorg/iusto-ipsum"; 2const myString = "hello"; 3const myNumber = 42; 4const myBoolean = true; 5 6const stringType = getTypeOf(myString); 7console.log(stringType); // "string" 8 9const types = getTypeOf(myString, myNumber, myBoolean); 10console.log(types); // ["string", "number", "boolean"]
constructor(...values: any[]): TypeOf
Creates a new instance of the TypeOf
class with the specified values and options.
values
: The values to check the type of.Throws an error if no values are provided to the constructor. With error name InvalidValuesToCheckError
and message No values to check were provided!
.
setOptions(options: TypeOfOptions): void
Sets the options for an instance of the TypeOf
class.
1TypeOfOptions = { 2 enableCapitalizedTypeNames?: boolean; 3 disableThrowErrors?: boolean; 4}
options
: An optional object with the following properties:
enableCapitalizedTypeNames
: A boolean value indicating whether to use capitalized type names. If true
, the TypeOf
class will return capitalized type names (e.g. String
instead of string
). If false
(the default), the TypeOf
class will use lowercase type names.disableThrowErrors
: A boolean value indicating whether to disable throwing errors. IfIf enableCapitalizedTypeNames
is set to true
, the getTypeOf
method will return capitalized type names (e.g. String
instead of string
). If enableCapitalizedTypeNames
is set to false
(the default), the getTypeOf
method will return lowercase type names.
If disableThrowErrors
is set to true true
, the TypeOf
class will not throw errors and instead return undefined
. It is important to remember that by returning undefined
instead of throwing errors, the TypeOf
class will not provide any information on why the error occurred. If disableThrowErrors
is set to false
(the default), the TypeOf
class will throw errors with information on why the error occurred.
Throws error if options
is not an object. With error name InvalidOptionsTypeError
and message Options must be an object!...
.
Throws error if options.enableCapitalizedTypeNames
is not a boolean. With error name InvalidOptionsError
and message The options provided are not valid!...
.
Throws error if options.disableThrowErrors
is not a boolean. With error name InvalidOptionsError
and message The options provided are not valid!...
.
Throws error if options.enableCapitalizedTypeNames
is not a boolean. With error name InvalidOptionsError
and message The options provided are not valid!...
.
Throws error if options.disableThrowErrors
is not a boolean. With error name InvalidOptionsError
and message The options provided are not valid!...
.
Example:
1import { TypeOf } from "@zitterorg/iusto-ipsum"; 2const typeOfInstance = new TypeOf("hello", 42, true); 3const options = { enableCapitalizedTypeNames: true, disableThrowErrors: true }; 4typeOfInstance.setOptions = options;
getOptions(): TypeOfOptions
Gets the options for an instance of the TypeOf
class.
enableCapitalizedTypeNames
and disableThrowErrors
.isTypeOf(type: string, options?: TypeOfOptions): boolean | undefined
Checks if all values are of the specified type.
type
: The type to check the values against.true
if all values are of the specified type, or false
if not. If disableThrowErrors is set to true
, it will return undefined
instead of throwing an error.notTypeOf(type: string, options?: TypeOfOptions): boolean | undefined
Checks if all values are not of the specified type.
type
: The type to check the values against.true
if all values are not of the specified type, or false
if not. If disableThrowErrors is set to true
, it will return undefined
instead of throwing an error.isTypeOf
method.isTypeOfValues(type: string, options?: TypeOfOptions): boolean[] | undefined
Checks if all values are of the specified type. Returns an array of booleans.
type
: The type to check the values against.true
, it will return undefined
instead of throwing an error.isTypeOf
method, except that it returns an array of booleans instead of a single boolean.1import { TypeOf } from "@zitterorg/iusto-ipsum"; 2const typeOfInstance = new TypeOf("hello", 42, true); 3const types = typeOfInstance.isTypeOfValues("string"); 4console.log(types); // [true, false, false]
notTypeOfValues(type: string, options?: TypeOfOptions): boolean[] | undefined
Checks if all values are not of the specified type. Returns an array of booleans.
type
: The type to check the values against.true
, it will return undefined
instead of throwing an error.notTypeOf
method, except that it returns an array of booleans instead of a single boolean.1import { TypeOf } from "@zitterorg/iusto-ipsum"; 2const typeOfInstance = new TypeOf("hello", 42, true); 3const types = typeOfInstance.notTypeOfValues("string"); 4console.log(types); // [false, true, true]
getTypeOf(options?: TypeOfOptions): string | string[] | undefined
Gets the type of the values as a string or an array of strings.
1import { TypeOf } from "@zitterorg/iusto-ipsum"; 2const typeOfInstance = new TypeOf("hello", 42, true); 3const options = { enableCapitalizedTypeNames: true, disableThrowErrors: true }; 4// since the you can pass options directly to the getTypeOf method, you can also do this instead of setting the options on the instance of the TypeOf class. 5const types = typeOfInstance.getTypeOf(options); 6console.log(types); // ["String", "Number", "Boolean"]
[method]: (...values: any[]) => boolean | boolean[]
An object with shorthand methods for checking the type of values. Each method is named after the type it checks prefixed with the use case.
See the output of the typeOfHelp
method for a list of all the supported types and helper methods.
For example, the isString
method checks if a value is a string.
getTypeOf(...values: any[]): string | string[]
Checks the type of a single value or multiple values at once.
values
: The values to check the type of.getTypeOfPretty(...values: any[]): string | string[]
Checks the type of a single value or multiple values at once and returns a pretty string.
values
: The values to check the type of.typeOf(...values: any[]): TypeOf
Creates a new instance of the TypeOf
class with the specified values and options.
values
: The values to check the type of.typeOfSilent(...values: any[]): TypeOf
Creates a new instance of the TypeOf
class with the specified values and options.
values
: The values to check the type of.typeOfHelp(): void
Console logs the following string with help information:
The name of each type and helper method is a combination of a 'use case' name and a 'type/helper' name.
For instance, the method 'isString' which checks if one or all values are a string is a combination of the 'use case' name 'is' and the 'type/helper' name 'String'.
The 'use case' names are:
is // checks if all values are of the specified 'type/helper'
not // checks if all values are not of the specified 'type/helper'
everyValueIs // same as the 'is' 'use case'
everyValueNot // same as the 'not' 'use case'
someValueIs // checks if at least one value is of the specified 'type/helper'
someValueNot // checks if at least one value is not of the specified 'type/helper'
The 'type/helper' names are:
Arguments
Array
Arraybuffer
Arrayiterator
Asyncfunction
Asyncgenerator
Asyncgeneratorfunction
Bigint
Bigint64array
Biguint64array
Boolean
Dataview
Date
Error
Float32array
Float64array
Function
Generator
Generatorfunction
Infinity
Int16array
Int32array
Int8array
Internal
Map
Mapiterator
Module
Modulenamespaceobject
Nan
Null
Number
Object
Promise
Proxy
Regexp
Set
Setiterator
String
Stringiterator
Symbol
Typedarray
Uint16array
Uint32array
Uint8array
Uint8clampedarray
Undefined
Weakmap
Weakset
EmptyArray
EmptyObject
EmptyString
Empty
BooleanTrue
BooleanFalse
NumberZero
NumberPositive
NumberNegative
NumberMaxSafeInteger
This project is licensed under the Mozilla Public License 2.0 - see the LICENSE file for details.
No vulnerabilities found.
No security vulnerabilities found.