GithubHelp home page GithubHelp logo

openinf / openinf-util-types Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 2.0 350 KB

Fundamental JavaScript type-related utilities

Home Page: https://github.com/OpenINF/openinf-util-types#readme

License: Other

TypeScript 100.00%
utilities types typechecking javascript functional predicate helpers helpers-library library javascript-library

openinf-util-types's Introduction

OpenINF logo

@openinf/util-types

Fundamental JavaScript type-related utilities


'View on npm' 'License: MIT/Apache-2.0'


The high-level goal of @openinf/util-types is to serve as a Node.js package containing utilities for fundamental JavaScript type-related operations primarily enabling users to perform native typechecking and simplify type coercion. We are constantly working to improve this repository, so please feel free to contribute if you notice any omissions or errors.

Thanks!


Platform: Node.js LTS

Supported Node.js Environments

  • v4:Argon (Ar)
  • v6:Boron (B)
  • v8:Carbon (C)
  • v10:Dubnium (Db)
  • v12:Erbium (Er)
  • v14:Fermium (Fm)
  • v16:Gallium (Ga)
  • v18:Hydrogen (H)

Code Style: Prettier Commit Style: Conventional Commits Chat on Matrix





Table of Contents





Installation Corepack logo


@openinf/util-types runs on supported versions of Node.js and is available via npm, pnpm, or yarn.

Using the npm CLI

See the official documentation for this command for more information.

npm i @openinf/util-types

Using the pnpm CLI

See the official documentation for this command for more information.

pnpm add @openinf/util-types

Using the Yarn 1 CLI (Classic)

See the official documentation for this command for more information.

yarn add @openinf/util-types

Usage

Import the helper functions based on your platform.

import { isObject } from '@openinf/util-types';

const maybeObject = null;

if (isObject(maybeObject)) {
  console.log('The value of `maybeObject` is of type Object.');
} else {
  console.log('The value of `maybeObject` is not of type Object.');
}



API

toString(value)string

Returns the ECMAScript [[Class]] internal property of the passed value.

isUndefined(value)boolean

Determines whether the passed value is actually of type undefined.

isObject(value)boolean

Determines whether the passed value is of type Object.

isOrdinaryFunction(value)boolean

Determines whether the passed value is of type Function.

isBooleanObject(value)boolean

Determines whether the passed value is actually a Boolean object.

isSymbolObject(value)boolean

Determines whether the passed value is actually a Symbol object.

isNativeError(value)boolean

Determines whether the passed value is one of the native error types:

isNumberObject(value)boolean

Determines whether the passed value is actually a Number object (boxed primitive).

isBigIntObject(value)boolean

Determines whether the passed value is actually a BigInt object (boxed primitive).

isFiniteNumber(value)boolean

Determines whether the passed value is of number type and finite. NaN and Infinity are not considered a finite number. String numbers are not considered numbers.

isMath(value)boolean

Determines whether the passed value is actually the Math global object.

isDate(value)boolean

Determines whether the passed value is of type Date.

isStringObject(value)boolean

Determines whether the passed value is actually a String object.

isRegExp(value)boolean

Determines whether the passed value is of type RegExp.

isArray(value)boolean

Determines whether the passed value is of type Array.

toArray(arrayLike)Array<T>

Converts an array-like object to an array.

isInt8Array(value)boolean

Determines whether the passed value is of type Int8Array.

isUint8Array(value)boolean

Determines whether the passed value is of type Uint8Array.

isUint8ClampedArray(value)boolean

Determines whether the passed value is of type Uint8ClampedArray.

isInt16Array(value)boolean

Determines whether the passed value is of type Int16Array.

isUint16Array(value)boolean

Determines whether the passed value is of type Uint16Array.

isInt32Array(value)boolean

Determines whether the passed value is of type Int32Array.

isUint32Array(value)boolean

Determines whether the passed value is of type Uint32Array.

isFloat32Array(value)boolean

Determines whether the passed value is of type Float32Array.

isFloat64Array(value)boolean

Determines whether the passed value is of type Float64Array.

isBigInt64Array(value)boolean

Determines whether the passed value is of type BigInt64Array.

isBigUint64Array(value)boolean

Determines whether the passed value is of type BigUint64Array.

isArrayBufferView(value)boolean

Determines whether the passed value is an ArrayBufferView, which is a helper type representing any of the following JavaScript TypedArray types:

isTypedArray(value)boolean

Determines if value is one of the TypedArray element types:

isMap(value)boolean

Determines whether the passed value is of type Map.

isMapIterator(value)boolean

Determines whether the passed value is of type Map Iterator.

isSet(value)boolean

Determines whether the passed value is of type Set.

isSetIterator(value)boolean

Determines whether the passed value is of type Set Iterator.

isWeakMap(value)boolean

Determines whether the passed value is of type WeakMap.

isWeakSet(value)boolean

Determines whether the passed value is of type WeakSet.

isArrayBuffer(value)boolean

Determines whether the passed value is of type ArrayBuffer.

isSharedArrayBuffer(value)boolean

Determines whether the passed value is of type SharedArrayBuffer.

isAnyArrayBuffer(value)boolean

Determines whether the passed value is one of either ArrayBuffer or SharedArrayBuffer.

isDataView(value)boolean

Determines whether the passed value is of type DataView.

isPromise(value)boolean

Determines whether the passed value is of type Promise.

isGeneratorObject(value)boolean

Determines whether the passed value is actually a Generator object.

isGeneratorFunction(value)boolean

Determines whether the passed value is of type GeneratorFunction.

isAsyncFunction(value)boolean

Determines whether the passed value is of type AsyncFunction.

isArgumentsObject(value)boolean

Determines whether the passed value is actually an arguments object.

isBoxedPrimitive(value)boolean

Determines whether the passed value is a primitive wrapped by its object equivalent (a.k.a. "boxed"). Except for null and undefined, all primitive values have object equivalents that wrap around the primitive values:

isModuleNamespaceObject(value)boolean

Determines whether the passed value is a Module namespace object.

isPrimitive(value)boolean

Determines whether the passed value is of a primitive data type.

toString(value) ⇒ string

Returns the ECMAScript [[Class]] internal property of the passed value.

Kind: global function
Returns: string - A specification-defined classification of objects.

Param Type Description
value unknown The value to be checked.

isUndefined(value) ⇒ boolean

Determines whether the passed value is actually of type undefined.

Kind: global function
Returns: boolean - true if the value is undefined; otherwise, false.

Param Type Description
value unknown The value to be checked.

isObject(value) ⇒ boolean

Determines whether the passed value is of type Object.

Kind: global function
Returns: boolean - true if the value is an Object; otherwise, false.

Param Type Description
value unknown The value to be checked.

isOrdinaryFunction(value) ⇒ boolean

Determines whether the passed value is of type Function.

Kind: global function
Returns: boolean - true if the value is a Function; otherwise, false.

Param Type Description
value unknown The value to be checked.

isBooleanObject(value) ⇒ boolean

Determines whether the passed value is actually a Boolean object.

Kind: global function
Returns: boolean - true if the value is a Boolean object; otherwise, false.

Param Type Description
value unknown The value to be checked.

isSymbolObject(value) ⇒ boolean

Determines whether the passed value is actually a Symbol object.

Kind: global function
Returns: boolean - true if the value is a Symbol object; otherwise, false.

Param Type Description
value unknown The value to be checked.

isNativeError(value) ⇒ boolean

Determines whether the passed value is one of the native error types:

Kind: global function
Returns: boolean - true if the value is a native error; otherwise, false.

Param Type Description
value unknown The value to be checked.

isNumberObject(value) ⇒ boolean

Determines whether the passed value is actually a Number object (boxed primitive).

Kind: global function
Returns: boolean - true if the value is a Number object; otherwise, false.

Param Type Description
value unknown The value to be checked.

isBigIntObject(value) ⇒ boolean

Determines whether the passed value is actually a BigInt object (boxed primitive).

Kind: global function
Returns: boolean - true if the value is a BigInt object; otherwise, false.

Param Type Description
value unknown The value to be checked.

isFiniteNumber(value) ⇒ boolean

Determines whether the passed value is of number type and finite. NaN and Infinity are not considered a finite number. String numbers are not considered numbers.

Kind: global function
Returns: boolean - true if the value is a finite number; otherwise, false.

Param Type Description
value unknown The value to be checked.

isMath(value) ⇒ boolean

Determines whether the passed value is actually the Math global object.

Kind: global function
Returns: boolean - true if the value is the Math object; otherwise, false.

Param Type Description
value unknown The value to be checked.

isDate(value) ⇒ boolean

Determines whether the passed value is of type Date.

Kind: global function
Returns: boolean - true if the value is a Date; otherwise, false.

Param Type Description
value unknown The value to be checked.

isStringObject(value) ⇒ boolean

Determines whether the passed value is actually a String object.

Kind: global function
Returns: boolean - true if the value is a String object; otherwise, false.

Param Type Description
value unknown The value to be checked.

isRegExp(value) ⇒ boolean

Determines whether the passed value is of type RegExp.

Kind: global function
Returns: boolean - true if the value is a RegExp; otherwise, false.

Param Type Description
value unknown The value to be checked.

isArray(value) ⇒ boolean

Determines whether the passed value is of type Array.

Kind: global function
Returns: boolean - true if the value is an Array; otherwise, false.

Param Type Description
value unknown The value to be checked.

toArray(arrayLike) ⇒ Array<T>

Converts an array-like object to an array.

Kind: global function

Param Type
arrayLike ArrayLike<T> | string

isInt8Array(value) ⇒ boolean

Determines whether the passed value is of type Int8Array.

Kind: global function
Returns: boolean - true if the value is an Int8Array; otherwise, false.

Param Type Description
value unknown The value to be checked.

isUint8Array(value) ⇒ boolean

Determines whether the passed value is of type Uint8Array.

Kind: global function
Returns: boolean - true if the value is a Uint8Array; otherwise, false.

Param Type Description
value unknown The value to be checked.

isUint8ClampedArray(value) ⇒ boolean

Determines whether the passed value is of type Uint8ClampedArray.

Kind: global function
Returns: boolean - true if the value is a Uint8ClampedArray; otherwise, false.

Param Type Description
value unknown The value to be checked.

isInt16Array(value) ⇒ boolean

Determines whether the passed value is of type Int16Array.

Kind: global function
Returns: boolean - true if the value is an Int16Array; otherwise, false.

Param Type Description
value unknown The value to be checked.

isUint16Array(value) ⇒ boolean

Determines whether the passed value is of type Uint16Array.

Kind: global function
Returns: boolean - true if the value is a Uint16Array; otherwise, false.

Param Type Description
value unknown The value to be checked.

isInt32Array(value) ⇒ boolean

Determines whether the passed value is of type Int32Array.

Kind: global function
Returns: boolean - true if the value is an Int32Array; otherwise, false.

Param Type Description
value unknown The value to be checked.

isUint32Array(value) ⇒ boolean

Determines whether the passed value is of type Uint32Array.

Kind: global function
Returns: boolean - true if the value is a Uint32Array; otherwise, false.

Param Type Description
value unknown The value to be checked.

isFloat32Array(value) ⇒ boolean

Determines whether the passed value is of type Float32Array.

Kind: global function
Returns: boolean - true if the value is a Float32Array; otherwise, false.

Param Type Description
value unknown The value to be checked.

isFloat64Array(value) ⇒ boolean

Determines whether the passed value is of type Float64Array.

Kind: global function
Returns: boolean - true if the value is a Float64Array; otherwise, false.

Param Type Description
value unknown The value to be checked.

isBigInt64Array(value) ⇒ boolean

Determines whether the passed value is of type BigInt64Array.

Kind: global function
Returns: boolean - true if the value is a BigInt64Array; otherwise, false.

Param Type Description
value unknown The value to be checked.

isBigUint64Array(value) ⇒ boolean

Determines whether the passed value is of type BigUint64Array.

Kind: global function
Returns: boolean - true if the value is a BigUint64Array; otherwise, false.

Param Type Description
value unknown The value to be checked.

isArrayBufferView(value) ⇒ boolean

Determines whether the passed value is an ArrayBufferView, which is a helper type representing any of the following JavaScript TypedArray types:

Kind: global function
Returns: boolean - true if the value is an ArrayBufferView; otherwise, false.

Param Type Description
value unknown The value to be checked.

isTypedArray(value) ⇒ boolean

Determines if value is one of the TypedArray element types:

Kind: global function
Returns: boolean - true if the value is one of the typed arrays; otherwise, false.

Param Type Description
value unknown The value to be checked.

isMap(value) ⇒ boolean

Determines whether the passed value is of type Map.

Kind: global function
Returns: boolean - true if the value is a Map; otherwise, false.

Param Type Description
value unknown The value to be checked.

isMapIterator(value) ⇒ boolean

Determines whether the passed value is of type Map Iterator.

Kind: global function
Returns: boolean - true if the value is a Map Iterator; otherwise, false.

Param Type Description
value unknown The value to be checked.

isSet(value) ⇒ boolean

Determines whether the passed value is of type Set.

Kind: global function
Returns: boolean - true if the value is a Set; otherwise, false.

Param Type Description
value unknown The value to be checked.

isSetIterator(value) ⇒ boolean

Determines whether the passed value is of type Set Iterator.

Kind: global function
Returns: boolean - true if the value is a Set Iterator; otherwise, false.

Param Type Description
value unknown The value to be checked.

isWeakMap(value) ⇒ boolean

Determines whether the passed value is of type WeakMap.

Kind: global function
Returns: boolean - true if the value is a WeakMap; otherwise, false.

Param Type Description
value unknown The value to be checked.

isWeakSet(value) ⇒ boolean

Determines whether the passed value is of type WeakSet.

Kind: global function
Returns: boolean - true if the value is a WeakSet; otherwise, false.

Param Type Description
value unknown The value to be checked.

isArrayBuffer(value) ⇒ boolean

Determines whether the passed value is of type ArrayBuffer.

Kind: global function
Returns: boolean - true if the value is an ArrayBuffer; otherwise, false.

Param Type Description
value unknown The value to be checked.

isSharedArrayBuffer(value) ⇒ boolean

Determines whether the passed value is of type SharedArrayBuffer.

Kind: global function
Returns: boolean - true if the value is a SharedArrayBuffer; otherwise, false.

Param Type Description
value unknown The value to be checked.

isAnyArrayBuffer(value) ⇒ boolean

Determines whether the passed value is one of either ArrayBuffer or SharedArrayBuffer.

Kind: global function
Returns: boolean - true if the value is one of the array buffers; otherwise, false.

Param Type Description
value unknown The value to be checked.

isDataView(value) ⇒ boolean

Determines whether the passed value is of type DataView.

Kind: global function
Returns: boolean - true if the value is a DataView; otherwise, false.

Param Type Description
value unknown The value to be checked.

isPromise(value) ⇒ boolean

Determines whether the passed value is of type Promise.

Kind: global function
Returns: boolean - true if the value is a Promise; otherwise, false.

Param Type Description
value unknown The value to be checked.

isGeneratorObject(value) ⇒ boolean

Determines whether the passed value is actually a Generator object.

Kind: global function
Returns: boolean - true if the value is a Generator; otherwise, false.

Param Type Description
value unknown The value to be checked.

isGeneratorFunction(value) ⇒ boolean

Determines whether the passed value is of type GeneratorFunction.

Kind: global function
Returns: boolean - true if the value is a GeneratorFunction; otherwise, false.

Param Type Description
value unknown The value to be checked.

isAsyncFunction(value) ⇒ boolean

Determines whether the passed value is of type AsyncFunction.

Kind: global function
Returns: boolean - true if the value is an AsyncFunction; otherwise, false.

Param Type Description
value unknown The value to be checked.

isArgumentsObject(value) ⇒ boolean

Determines whether the passed value is actually an arguments object.

Kind: global function
Returns: boolean - true if the value is an arguments object; otherwise, false.

Param Type Description
value unknown The value to be checked.

isBoxedPrimitive(value) ⇒ boolean

Determines whether the passed value is a primitive wrapped by its object equivalent (a.k.a. "boxed"). Except for null and undefined, all primitive values have object equivalents that wrap around the primitive values:

Kind: global function
Returns: boolean - true if the value is one of the boxed primitives; otherwise, false.
See: https://developer.mozilla.org/en-US/docs/Glossary/Primitive#primitive_wrapper_objects_in_javascript

Param Type Description
value unknown The value to be checked.

isModuleNamespaceObject(value) ⇒ boolean

Determines whether the passed value is a Module namespace object.

Kind: global function
Returns: boolean - true if the value is a Module; otherwise, false.

Param Type Description
value unknown The value to be checked.

isPrimitive(value) ⇒ boolean

Determines whether the passed value is of a primitive data type.

Kind: global function
Returns: boolean - true if the value is a primitive; otherwise, false.

Param Type Description
value unknown The value to be checked.





Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. If for whatever reason you spot something to fix but cannot patch it yourself, please open an issue.


License

This project is licensed under either of

at your option.

The SPDX license identifier for this project is MIT OR Apache-2.0.





Show Your Support


If you like the project (or want to bookmark it) —
— give it a star ⭐️ — it will greatly encourage us.



The OpenINF logo

openinf-util-types's People

Contributors

deepsource-autofix[bot] avatar deepsourcebot avatar dependabot[bot] avatar dereknongeneric avatar renovate-bot avatar renovate[bot] avatar semgrep-bot avatar snyk-bot avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

openinf-util-types's Issues

[feature request] add new `isNullish` predicate function

Checks whether something is null or undefined.

Would be useful for OpenINF/openinf-util-object#133. We can have it out in the next minor…

Can this be achieved solely using Nullish coalescing? Maybe in the TS, but now wondering what ES year we are searching for compatibility with since this is a relatively new language feature.

Refs: https://devblogs.microsoft.com/typescript/announcing-typescript-4-8/#improved-intersection-reduction-union-compatibility-and-narrowing

/cc @septs @ignoreintuition

[feature request] prevent including unnecessary files in the deployed package

We should consider adding the "files" stanza to the package.json to create an explicit allowlist and prevent deploying any unnecessary files to the npm registry as part of our package. This would be preferable to using a .npmignore file, which we have been doing so far but is expected to quickly become unmanageable as more files are added.

[bug] set of control abastraction objects is incomplete

We are currently missing a couple of control abstraction object predicates from this library. This was in part due to there not being any documentation associated with them on MDN at the time when we published our initial round of package versions. Since then, along with a few of the good folks over at that project, I've gone ahead and wrote them up and we've gotten the missing pages added to the official JavaScript documentation.

Control abstractions can help to structure code, especially async code (without using deeply nested callbacks, for example).

[feature request] DeepScan to use ESLint over built-in rules

DeepScan has been configured to check for ESLint config instead of using its default rules. This means that it will be ready for us once ESLint is good to go here.

You've analyzed the project with ESLint, but the ESLint analysis failed by the ESLint error.

After checking the details of error and configuring ESLint correctly, please reanalyze this project.

ESLint couldn't find a configuration file. To set up a configuration file for this project, please run:

eslint --init

[testing] code coverage reporting & test data artifact uploading

[…] only the Cobertura XML format is supported by DeepSource

https://deepsource.io/docs/analyzer/test-coverage/#javascript

Currently, our tests in this repo are written using tape, yet we are instructed to use Jest to generate the coverage reports… As long as the output is in the expected Cobertura XML format, i think we should be alright, but was unable to find an option for that output using tape nor were there any suitable companion modules altho tap-nyc would seem to be what we are looking for if it would output XML. 😕

We could also use node-tap instead of tape and use its --coverage-report=cobertura flag. I was hoping not to do much refactoring to get this working correctly, but if that is not the case, I have no objection to moving to a more elegant solution if necessary. We seem to have outgrown both tape and tap, but I am also not a huge fan of Jest…

Refs: https://node-tap.org/docs/coverage/#uploading-coverage-to-other-services

Hacktoberfest checklist: prepare project for contributions by following best practices

  • Add the “hacktoberfest” topic to your repository to opt-in to Hacktoberfest and indicate you’re looking for contributions.

  • Apply the “hacktoberfest” label to issues you want contributors to help within your GitHub or GitLab project.

  • Add a CONTRIBUTING.md file with contribution guidelines to your repository.

  • Choose issues that have a well-defined scope and are self-contained.

  • Adopt a code of conduct to create a greater sense of inclusion and community for contributors.

  • Be ready to review pull/merge requests, accepting those that are valid by merging them, leaving an overall approving review, or by adding the “hacktoberfest-accepted” label.

  • Reject any spammy requests you receive by labeling them as “spam”, and any other invalid contributions by closing them or labeling them as “invalid”.

Refs: https://hacktoberfest.com/participation/#maintainers

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/codeql-analysis.yml
  • actions/checkout v3
  • github/codeql-action v2
  • github/codeql-action v2
  • github/codeql-action v2
.github/workflows/semgrep.yml
  • actions/checkout v3
  • ubuntu 20.04
npm
package.json
  • @types/jsdom 21.1.1
  • @types/node 20.x.x
  • jsdom 22.1.0
  • typescript 5.1.3
  • pnpm 8.6.3
nvm
.nvmrc
  • node 20

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.