Giter Club home page Giter Club logo

typechecker's Introduction

TypeChecker

Status of the GitHub Workflow: bevry NPM version NPM downloads
GitHub Sponsors donate button ThanksDev donate button Patreon donate button Liberapay donate button Buy Me A Coffee donate button Open Collective donate button crypto donate button PayPal donate button
Discord server badge Twitch community badge

Utilities to get and check variable types (isString, isPlainObject, isRegExp, etc)

Why?

Why should I use this instead of say instanceof?

Under certain circumstances instanceof may not return the correct results. This occurs with node's vm module especially, and circumstances where an object's prototype has been dereferenced from the original. As such, for basic == and === checks (like a === null), you're fine not using this, but for checks when you would have done instanceof (like err instanceof Error), you should try to use this instead. Plus things like isPlainObject are darn useful!

Usage

Complete API Documentation.

Install

  • Install: npm install --save typechecker
  • Import: import * as pkg from ('typechecker')
  • Require: const pkg = require('typechecker')
import * as pkg from 'https://unpkg.com/typechecker@^9.4.0/edition-deno/index.ts'
<script type="module">
    import * as pkg from '//cdn.skypack.dev/typechecker@^9.4.0'
</script>
<script type="module">
    import * as pkg from '//unpkg.com/typechecker@^9.4.0'
</script>
<script type="module">
    import * as pkg from '//dev.jspm.io/[email protected]'
</script>

This package is published with the following editions:

  • typechecker aliases typechecker/index.cjs which uses the Editions Autoloader to automatically select the correct edition for the consumer's environment
  • typechecker/source/index.ts is TypeScript source code with Import for modules
  • typechecker/edition-browsers/index.js is TypeScript compiled against ES2022 for web browsers with Import for modules
  • typechecker/edition-es2022/index.js is TypeScript compiled against ES2022 for Node.js 6 || 8 || 10 || 12 || 14 || 16 || 18 || 20 || 21 with Require for modules
  • typechecker/edition-es5/index.js is TypeScript compiled against ES5 for Node.js 4 || 6 || 8 || 10 || 12 || 14 || 16 || 18 || 20 || 21 with Require for modules
  • typechecker/edition-es2022-esm/index.js is TypeScript compiled against ES2022 for Node.js 12 || 14 || 16 || 18 || 20 || 21 with Import for modules
  • typechecker/edition-types/index.d.ts is TypeScript compiled Types with Import for modules
  • typechecker/edition-deno/index.ts is TypeScript source code made to be compatible with Deno

History

Discover the release history by heading on over to the HISTORY.md file.

Backers

Code

Discover how to contribute via the CONTRIBUTING.md file.

Authors

Maintainers

Contributors

Finances

GitHub Sponsors donate button ThanksDev donate button Patreon donate button Liberapay donate button Buy Me A Coffee donate button Open Collective donate button crypto donate button PayPal donate button

Sponsors

  • Andrew Nesbitt — Software engineer and researcher
  • Balsa — We're Balsa, and we're building tools for builders.
  • Codecov — Empower developers with tools to improve code quality and testing.
  • Poonacha Medappa
  • Rob Morris
  • Sentry — Real-time crash reporting for your web apps, mobile apps, and games.
  • Syntax — Syntax Podcast

Donors

License

Unless stated otherwise all works are:

and licensed under:

typechecker's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

typechecker's Issues

IE11 compatibility problem

As usual, typechecker will be used as a dependecies. And typechecker doesn't transfer the index.ts to es5, such as line 254 has the keyword "const".

If webpack has a setting which has "exclude: /node_modules/", the output js won't work well in IE11.

Add docs to npmignore

I had a bit of a surprise when I installed a module that uses typechecker and my deploy suddenly got a fair bit bigger. Turned out it was the fonts in docs/assets/fonts. Secondary things like docs shouldn’t really be included in a module, so maybe this should be added to the npmignore. Would save 672 KB out of a module that weighs 728 KB in total.

Strange log "export function getObjectType" from source/index.js:17

Hi every time I start my script I get this strange log:

/node_modules/typechecker/source/index.js:17

export function getObjectType (value /* :mixed */) /* :string */ {
^^^^^^

"title": "TypeChecker",
"version": "4.3.0"

Using:

nodejs -v
v0.10.37

uname -a
Linux prog01 3.13.0-86-generic #130-Ubuntu SMP Mon Apr 18 18:27:15 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

Thanks

typeChecker.isPlainObject() return non boolean value

Hey there, i found the following problem:

typeChecker.isPlainObject(null) returns null instead a boolean

also

typeChecker.isPlainObject('') returns the string instead a boolean.

I would expect true or false and not the value which i passed to the funcion.

Greets Joan

adding a custom type, typeMap is frozen

Little help please, I'd like to do this.

mytypechecker.js

let tc = require('typechecker')

// add custom types
tc.isBuffer = function isBuffer(obj) {
  return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
}

// add map entries for custom types
tc.typeMap.buffer = tc.isBuffer

module.exports = tc

that might work but can't try it because the typeMap object is frozen.

Not sure why this was done (save fools from themselves?)

So how can I add my custom types to the library so I can use getTypes without having to pass it an additional map every time

i.e. don't want to do this every time.
expect(u.getType(Buffer.from('this is a test'), { buffer: u.isBuffer })).to.equal('buffer')

if typeMap needs to be frozen why bother to export it? How about not and providing a registration function to register additional custom types for use with getType?

Thx.

Your .dependabot/config.yml contained invalid details

Dependabot encountered the following error when parsing your .dependabot/config.yml:

The property '#/update_configs/0/automerged_updates/0/match/update_type' value "security" did not match one of the following values: all, security:patch, semver:patch, semver:minor, in_range

Please update the config file to conform with Dependabot's specification using our docs and online validator.

Breaking change after version 2.0.1 with Node v0.6

Recently I'm getting Travis built errors on an existing node module testing on Node v0.6.19.
This module is using Watchr, which is using type checker ~2.0.1 as a dependency.

It seems you introduced a breaking change somewhere after 2.0.1, but only marked it as a patch (by only updating the last number of the version.)

I recommend going back and change the version to 2.1.x and rollback the breaking change after 2.0.1.

> [email protected] preinstall /home/briemens/Development/Crafity/modules/crafity-filesystem/node_modules/watchr/node_modules/typechecker
> node ./cyclic.js


/home/briemens/Development/Crafity/modules/crafity-filesystem/node_modules/watchr/node_modules/typechecker/cyclic.js:1
'fs').existsSync
      ^
TypeError: Object #<Object> has no method 'existsSync'
    at Object.<anonymous> (/home/briemens/Development/Crafity/modules/crafity-filesystem/node_modules/watchr/node_modules/typechecker/cyclic.js:1:82)
    at Module._compile (module.js:446:26)
    at Object..js (module.js:464:10)
    at Module.load (module.js:353:31)
    at Function._load (module.js:311:12)
    at Array.0 (module.js:484:10)
    at EventEmitter._tickCallback (node.js:190:38)

npm ERR! [email protected] preinstall: `node ./cyclic.js`
npm ERR! `sh "-c" "node ./cyclic.js"` failed with 1
npm ERR!
npm ERR! Failed at the [email protected] preinstall script.
npm ERR! This is most likely a problem with the typechecker package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node ./cyclic.js
npm ERR! You can get their info via:
npm ERR!     npm owner ls typechecker
npm ERR! There is likely additional logging output above.
npm ERR!
npm ERR! System Linux 3.8.0-27-generic
npm ERR! command "node" "/home/briemens/.nvm/v0.6.19/bin/npm" "install" "[email protected]"
npm ERR! cwd /home/briemens/Development/Crafity/modules/crafity-filesystem/node_modules/watchr
npm ERR! node -v v0.6.19
npm ERR! npm -v 1.1.24
npm ERR! code ELIFECYCLE
npm ERR! message [email protected] preinstall: `node ./cyclic.js`
npm ERR! message `sh "-c" "node ./cyclic.js"` failed with 1
npm ERR! errno {}
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /home/briemens/Development/Crafity/modules/crafity-filesystem/node_modules/watchr/npm-debug.log
npm not ok
npm not ok

Cheers!

Usage within angular6

Hi,
actually the library is what I'm looking for. Could you provide an example how I could integrate your .js within angular6 ? the methods works somehow, but I get the following error message on page load

index.js:308 Uncaught ReferenceError: module is not defined
    at index.js:308

This is what I have done so far:

I add in angular.json

"scripts" : [
   "node_modules/typechecker/edition-browsers/index.js"
]

than I add in my typings.d.ts the entry

declare module 'typechecker';

within my component I use:

var tc = require("typechecker");

let test1 = tc.isEmptyObject({});

Is this the correct approach or is there a better way to add your library within angular and of course to avoid any javascript errors ?

Thx and Best Regards

broke between 4.7 and 4.11, no default export

I know folks are removing their default exports but that is really a breaking change that should be removed at the major version change. Besides it's pretty easy to support named and default at the same time. I do it in all my esm modules

Looks like this all happened at 4.10 with move to ts

had to change this so

import * as typechecker from 'typechecker'

had to stop my work and update this dependency everwhere my code was deployed and recently installed/updated :-(

SyntaxError: The requested module 'file:///mnt/AllData/hacking/active-dev-repos/uci/lib/uci-utils/type/node_modules/typechecker/index.js' does not provide an export named 'default'

Your .dependabot/config.yml contained invalid details

Dependabot encountered the following error when parsing your .dependabot/config.yml:

The property '#/update_configs/0/automerged_updates/0/match/update_type' value "security" did not match one of the following values: all, security:patch, semver:patch, semver:minor, in_range

Please update the config file to conform with Dependabot's specification using our docs and online validator.

add isSymbol

function isSymbol (x) {
    return typeof x === 'symbol'
        || typeof x === 'object' && Object.prototype.toString.call (x) === '[object Symbol]';
}

Add YUIDocs

With this, we could also make each function a local global, and then export them all in a squashed object at the end.

Generator Functions

I don't think your implementation of isFunction, considers generator functions. I think you should probably do a test for (typeof x==='function') first, instead of only looking at the to string output and looking for regular and async function types.
Unless of course, this is intentional... in which case I would recommend adding that intention to the documentation.
Regardless, you may want to consider adding an isGenerator test. =)

async functions not recognized as functions by isFunction

if you declare an async function isFunction does not return true

const funcs = {
    regular: ()=>{}, 
    async: async ()=>{}
}
isFunction(funcs.regular)   // true
isFunction(funcs.async)  //false

btw I use latest node which supports async/await (since about 8.5 I think)

Pre-installations exits with non-zero status in 2.0.8

Hello there!

I have a Node.js application with a lot of dependencies, and it seems that one of them is using this module: [email protected]. The problem is when I do npm i --production it fails on typecheker's pre-install script. Here's the output:

$ npm i --production
npm WARN deprecated [email protected]: graceful-fs v3.0.0 and before will fail on node releases >= v7.0. Please update to graceful-fs@^4.0.0 as soon as possible. Use 'npm ls graceful-fs' to find it in the tree.
npm WARN deprecated [email protected]: lodash@<3.0.0 is no longer maintained. Upgrade to lodash@^4.0.0.
npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated [email protected]: graceful-fs v3.0.0 and before will fail on node releases >= v7.0. Please update to graceful-fs@^4.0.0 as soon as possible. Use 'npm ls graceful-fs' to find it in the tree.
npm WARN deprecated [email protected]: DEPRECATED. See readme: https://github.com/gruntjs/grunt-lib-contrib
npm WARN deprecated [email protected]: lodash@<3.0.0 is no longer maintained. Upgrade to lodash@^4.0.0.
npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated [email protected]: cross-spawn no longer requires a build toolchain, use it instead!
npm WARN deprecated [email protected]: 'native-or-bluebird' is deprecated. Please use 'any-promise' instead.

> [email protected] preinstall /tmp/testdrive-1.11.15-1468538515188/node_modules/.staging/typechecker-e85842ba
> node ./cyclic.js

And here's the dependency tree:

$ npm ls typechecker
[email protected] /home/sfomin/projects/testdrive
└─┬ [email protected]
  └─┬ [email protected]
    └─┬ [email protected]
      └─┬ [email protected]
        ├─┬ [email protected]
        │ └── [email protected] 
        ├─┬ [email protected]
        │ └── [email protected] 
        ├─┬ [email protected]
        │ └─┬ [email protected]
        │   └── [email protected] 
        └── [email protected]

It also looks, like the problem is not occurring every time, in some rare moments it works, I don't know why.

Please advise, any help will be highly appreciated. Thank you!

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.