{"id":25526228,"url":"https://github.com/exbotanical/js-heuristics","last_synced_at":"2025-07-21T21:40:56.407Z","repository":{"id":57283247,"uuid":"350597205","full_name":"exbotanical/js-heuristics","owner":"exbotanical","description":"Useful heuristics, type checks, and validation helpers for JavaScript","archived":false,"fork":false,"pushed_at":"2021-10-21T08:21:46.000Z","size":2549,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-02-29T05:44:08.553Z","etag":null,"topics":["functional-programming","type-checking","utility-library","validation-library"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/js-heuristics","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/exbotanical.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-03-23T06:02:15.000Z","updated_at":"2021-10-21T08:21:49.000Z","dependencies_parsed_at":"2022-09-17T14:01:21.862Z","dependency_job_id":null,"html_url":"https://github.com/exbotanical/js-heuristics","commit_stats":null,"previous_names":["matthewzito/js-heuristics"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exbotanical%2Fjs-heuristics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exbotanical%2Fjs-heuristics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exbotanical%2Fjs-heuristics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exbotanical%2Fjs-heuristics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/exbotanical","download_url":"https://codeload.github.com/exbotanical/js-heuristics/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239735257,"owners_count":19688262,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["functional-programming","type-checking","utility-library","validation-library"],"created_at":"2025-02-19T21:17:01.752Z","updated_at":"2025-02-19T21:17:02.490Z","avatar_url":"https://github.com/exbotanical.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# heuristics\n\n**This package has been deprecated; use https://github.com/MatthewZito/heuristics - `npm install heuristics`**\n\n## Useful heuristics, type checks, and validation helpers for JavaScript\n\n[![Build Status](https://travis-ci.org/MatthewZito/heuristics.svg?branch=master)](https://travis-ci.org/MatthewZito/heuristics)\n[![Coverage Status](https://coveralls.io/repos/github/MatthewZito/heuristics/badge.svg)](https://coveralls.io/github/MatthewZito/heuristics)\n\n`js-heuristics` is a library of useful heuristics, type checks, and validation helpers for JavaScript. Instead of repeatedly checking types, evaluating whether or not an API response is null (or indeed an object, only entirely empty), you can depend on this tested, consistent library API to get the job done.\n\n![Exquisite GIF of Hagrid](docs/urawiz.gif \"the maintainer does not guarantee this will happen to you\")\n\n*using this lib*\n\n## Table of Contents\n\n- [Supported Environments](#builds)\n- [Installation + Usage](#usage)\n- [Documentation / API](#docs)\n  - [Type Checks](#typecheck)\n  - [Validators](#validate)\n  - [Contracts](#contract)\n  - [Iterators](#iter)\n\n## \u003ca name=\"builds\"\u003e\u003c/a\u003e Supported Environments\n\n`heuristics` currently supports UMD, CommonJS (node versions \u003e= 10), and ESM build-targets. Is your preferred build not supported? Open an issue!\n\n## \u003ca name=\"usage\"\u003e\u003c/a\u003e Installation + Usage\n\n```bash\nnpm install js-heuristics\n# OR\nyarn add js-heuristics\n```\n\nCommonjs:\n\n```js\nconst { isObject } = require('js-heuristics');\n\nconsole.log(isObject({})); // true\n```\n\nESM:\n\n```js\nimport { isObject } from 'js-heuristics';\n```\n\n## \u003ca name=\"docs\"\u003e\u003c/a\u003e Documentation / Core API\n\n### \u003ca name=\"typecheck\"\u003e\u003c/a\u003e Type Checks\n\n#### isFunction (arg: any): boolean\n\n*evaluate whether the provided argument is a function*\n\n**Example**\n\n```js\nimport { isFunction } from 'js-heuristics';\n\nvar fn = () =\u003e ({});\n\nvar t = isFunction(fn);\n\nconsole.log(t); // true\n```\n\n#### isGenerator (arg: any): boolean\n\n*evaluate whether the provided argument is a generator function*\n\n**Example**\n\n```js\nimport { isGenerator } from 'js-heuristics';\n\nvar gen = function* () { yield true; };\n\nvar t = isGenerator(gen);\n\nconsole.log(t); // true\n```\n\n#### isAsyncFunction (arg: any): boolean\n\n*evaluate whether the provided argument is an async function*\n\n**Example**\n\n```js\nimport { isAsyncFunction } from 'js-heuristics';\n\nvar fn = async function () { ... };\n\nvar t = isAsyncFunction(fn);\n\nconsole.log(t); // true\n```\n\n#### isAnonymousFunction (arg: any): boolean\n\n*evaluate whether the provided argument is an anonymous function*\n\n**Example**\n\n```js\nimport { isAnonymousFunction } from 'js-heuristics';\n\nvar fn = function () { ... };\n\nvar t = isAnonymousFunction(fn);\n\nconsole.log(t); // true\n```\n\n#### isRegularFunction (arg: any): boolean\n\n*evaluate whether the provided argument is a named, synchronous function*\n\n**Example**\n\n```js\nimport { isRegularFunction } from 'js-heuristics';\n\nvar fn = function name () { ... };\n\nvar t = isRegularFunction(fn);\n\nconsole.log(t); // true\n```\n\n#### isString (arg: any): boolean\n\n*evaluate whether the provided argument is a string*\n\n**Example**\n\n```js\nimport { isFunction } from 'js-heuristics';\n\nvar fn = () =\u003e ({});\n\nvar t = isFunction(fn);\n\nconsole.log(t); // true\n```\n\n#### isBoolean (arg: any) boolean\n\n*evaluate whether the provided argument is a Boolean*\n\n**Example**\n\n```js\nimport { isBoolean } from 'js-heuristics';\n\n...\nif (isBoolean(true)) // true\n```\n\n#### isError (arg: any): boolean\n\n*evaluate whether the provided argument is an Error object*\n\n**Example**\n\n```js\nimport { isError } from 'js-heuristics';\n\n...\nvar result = await fetchData();\n...\nif (isError(result)) this.error = true;\nelse this.data = result.data;\n```\n\n#### isObject (arg: any): boolean\n\n*evaluate whether the provided argument is an object*\n\n**Example**\n\n```js\nimport { isObject } from 'js-heuristics';\n\nconst r = corneliusCardewIsDaBeezKnees();\n\nif (isObject(r)) ...\n```\n\n#### isArray (arg: any): boolean\n\n*evaluate whether the provided argument is an array*\n\n**Example**\n\n```js\nimport { isArray } from 'js-heuristics';\n\nvar notAnArr = '';\n\nconsole.log(isArray(notAnArr)); // false\n```\n\n#### isNumber (arg: any): boolean\n\n*evaluate whether the provided argument is a number*\n**Note** Will return false for *NaN* and single element Arrays (see: `toString` gotchas)\n\n**Example**\n\n```js\nimport { isNumber } from 'js-heuristics';\n\nconsole.log(isNumber(9)); // true\n\nconsole.log(isNumber(NaN)); // false\n```\n\n#### isFloat (arg: any): boolean\n\n*evaluate whether the provided argument is a floating point number*\n\n**Example**\n\n```js\nimport { isFloat } from 'js-heuristics';\n\nconsole.log(isFloat(9.1)); // true\n\nconsole.log(isFloat(1)); // false\n```\n\n### \u003ca name=\"validate\"\u003e\u003c/a\u003e Validators\n\n#### not (arg: any): boolean\n\n*convert any expression or value to a negated boolean*\n\n**Example**\n\n```js\nimport { not } from 'js-heuristics';\n\nif (not(obj)) ...\n\nif (not(bool)) ...\n\nif (not(expr)) ...\n```\n\n#### notEmpty (arg: (string|array|object)): boolean\n\n*evaluate whether the provided argument is __not__ empty*\n**Note** Will return undefined for non array, object, or string arguments\n\n**Example**\n\n```js\nimport { notEmpty } from 'js-heuristics';\n\nif (notEmpty(obj)) ...\n```\n\n#### objNotEmpty (arg: any): boolean\n\n*evaluate whether the provided object is __not__ empty (no keys)*\n\n**Example**\n\n```js\nimport { objNotEmpty } from 'js-heuristics';\n\nif (objNotEmpty(obj)) ...\n```\n\n#### objNotEmptyDeep (arg: any): boolean\n\n*evaluate whether the provided object is __not__ empty, no matter how nested*\n\n**Note** Object's values are not null, NaN, or undefined\n\n**Example**\n\n```js\nimport { objNotEmptyDeep } from 'js-heuristics';\n\nvar o = {\n  a: {\n    b: {\n      c: {\n        d: 1\n      }\n    }\n  }\n}\n\nif (objNotEmptyDeep(o)) ... // true\n```\n\n#### notNullOrUndefined (arg: any): boolean\n\n*Explicitly determine if given value is __not__ null or undefined*\n\n**Example**\n\n```js\nimport { notNullOrUndefined } from 'js-heuristics';\n\nif (notNullOrUndefined(o)) ...\n```\n\n#### notInPrototype (target: object, prop: string): boolean\n\n*Determine if a property does __not__ exist on an object or its prototype chain*\n\n**Example**\n\n```js\nimport { notInPrototype } from 'js-heuristics';\n\nvar proto = { foo: 'foo' };\nvar obj = Object.create(proto);\n\nif (notInPrototype(obj, 'foo')) ... // false\n\nif (notInPrototype(obj, 'bar')) ... // true\n```\n\n### \u003ca name=\"contract\"\u003e\u003c/a\u003e Contracts\n\n#### contract (predicate: Function, message?: string): Function\n\n*Generate a predicate-bound contract; either returns true or throws a violation*\n\n**Example**\n\n```js\nimport { contract, isObject } from 'js-heuristics';\n\nconst mustBeObject = contract(isObject);\n\nvar o = {};\nvar a = [];\n\nif (mustBeObject(o)) ... // true\n\nif (mustBeObject(a)) ... // throws\n\n\nconst contractWithMessage = contract(isObject, 'Must be an object');\n\ntry {\n  contractWithMessage('str');\n} catch ({ message }) {\n  console.log(message); // 'Must be an object'\n}\n```\n\n#### testForEach (...predicates: Function[]): boolean\n\n*Generate a reducer that enforces all provided predicates on a given argument*\n\n**Example**\n\n```js\nimport { testForEach, isObject } from 'js-heuristics';\n\nfunction hasData () { ... }\n\nconst isApiData = testForEach(isObject, hasData);\n\nif (isApiData(response)) ...\n```\n\n\n### \u003ca name=\"iter\"\u003e\u003c/a\u003e Iterators\n\n#### range (start: (number|string), end: (number|string)): IterableIterator\u003cstring\u003e\n\n*Generate an iterable range*\n\n**Example**\n\n```js\nimport { range } from 'js-heuristics';\n\nconst enumValue = 10;\n\nconst enumChar = 'E';\n\nif (enumValue in range(1, 20)) ... // true\n\nif (enumValue in range(1, 5)) ... // false\n\nif (enumChar in range('A', 'z')) ... // true\n\nif (enumChar in range('a', 'd')) ... // false\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexbotanical%2Fjs-heuristics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexbotanical%2Fjs-heuristics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexbotanical%2Fjs-heuristics/lists"}