{"id":22788894,"url":"https://github.com/rjoydip/is_type","last_synced_at":"2026-04-29T10:34:03.449Z","repository":{"id":114445693,"uuid":"559306099","full_name":"rjoydip/is_type","owner":"rjoydip","description":"Type check values","archived":false,"fork":false,"pushed_at":"2022-10-29T17:46:48.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-31T14:10:35.065Z","etag":null,"topics":["deno","is-type","value-type-check"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/rjoydip.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-29T17:46:40.000Z","updated_at":"2023-03-17T13:23:55.000Z","dependencies_parsed_at":"2023-06-08T04:00:21.782Z","dependency_job_id":null,"html_url":"https://github.com/rjoydip/is_type","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rjoydip/is_type","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rjoydip%2Fis_type","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rjoydip%2Fis_type/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rjoydip%2Fis_type/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rjoydip%2Fis_type/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rjoydip","download_url":"https://codeload.github.com/rjoydip/is_type/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rjoydip%2Fis_type/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32421956,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T06:29:02.080Z","status":"ssl_error","status_checked_at":"2026-04-29T06:29:00.631Z","response_time":110,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["deno","is-type","value-type-check"],"created_at":"2024-12-12T01:38:04.080Z","updated_at":"2026-04-29T10:34:03.432Z","avatar_url":"https://github.com/rjoydip.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# is_type ![ci](https://github.com/rjoydip/is_type/workflows/ci/badge.svg)\n\n\u003e Type check values\n\nFor example, `is.string('🦄') //=\u003e true`\n\n## Highlights\n\n- Written in TypeScript\n- [Extensive use of type guards](#type-guards)\n- [Supports type assertions](#type-assertions)\n- [Aware of generic type parameters](#generic-type-parameters) (use with caution)\n\n## Usage\n\n```ts\nimport is from \"deno.land/x/is_type/mod.ts\";\n\nis('🦄');\n//=\u003e 'string'\n\nis(new Map());\n//=\u003e 'Map'\n\nis.number(6);\n//=\u003e true\n```\n\n[Assertions](#type-assertions) perform the same type checks, but throw an error if the type does not match.\n\n```ts\nimport {assert} from \"deno.land/x/is_type/mod.ts\";\n\nassert.string(2);\n//=\u003e Error: Expected value which is `string`, received value of type `number`.\n```\n\nAnd with TypeScript:\n\n```ts\nimport {assert} from \"deno.land/x/is_type/mod.ts\";\n\nassert.string(foo);\n// `foo` is now typed as a `string`.\n```\n\n## API\n\n### is(value)\n\nReturns the type of `value`.\n\nPrimitives are lowercase and object types are camelcase.\n\nExample:\n\n- `'undefined'`\n- `'null'`\n- `'string'`\n- `'symbol'`\n- `'Array'`\n- `'Function'`\n- `'Object'`\n\nNote: It will throw an error if you try to feed it object-wrapped primitives, as that's a bad practice. For example `new String('foo')`.\n\n### is.{method}\n\nAll the below methods accept a value and returns a boolean for whether the value is of the desired type.\n\n#### Primitives\n\n##### .undefined(value)\n\n##### .null(value)\n\n##### .string(value)\n\n##### .number(value)\n\nNote: `is.number(NaN)` returns `false`. This intentionally deviates from `typeof` behavior to increase user-friendliness of `is` type checks.\n\n##### .boolean(value)\n\n##### .symbol(value)\n\n##### .bigint(value)\n\n#### Built-in types\n\n##### .array(value)\n\n##### .function(value)\n\n##### .buffer(value) [`not yet support`]\n\n##### .object(value)\n\nKeep in mind that [functions are objects too](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions).\n\n##### .numericString(value)\n\nReturns `true` for a string that represents a number satisfying `is.number`, for example, `'42'` and `'-8.3'`.\n\nNote: `'NaN'` returns `false`, but `'Infinity'` and `'-Infinity'` return `true`.\n\n##### .regExp(value)\n\n##### .date(value)\n\n##### .error(value)\n\n##### .nativePromise(value)\n\n##### .promise(value)\n\nReturns `true` for any object with a `.then()` and `.catch()` method. Prefer this one over `.nativePromise()` as you usually want to allow userland promise implementations too.\n\n##### .generator(value)\n\nReturns `true` for any object that implements its own `.next()` and `.throw()` methods and has a function definition for `Symbol.iterator`.\n\n##### .generatorFunction(value)\n\n##### .asyncFunction(value)\n\nReturns `true` for any `async` function that can be called with the `await` operator.\n\n```ts\nis.asyncFunction(async () =\u003e {});\n//=\u003e true\n\nis.asyncFunction(() =\u003e {});\n//=\u003e false\n```\n\n##### .asyncGenerator(value)\n\n```ts\nis.asyncGenerator(\n (async function * () {\n  yield 4;\n })()\n);\n//=\u003e true\n\nis.asyncGenerator(\n (function * () {\n  yield 4;\n })()\n);\n//=\u003e false\n```\n\n##### .asyncGeneratorFunction(value)\n\n```ts\nis.asyncGeneratorFunction(async function * () {\n yield 4;\n});\n//=\u003e true\n\nis.asyncGeneratorFunction(function * () {\n yield 4;\n});\n//=\u003e false\n```\n\n##### .boundFunction(value)\n\nReturns `true` for any `bound` function.\n\n```ts\nis.boundFunction(() =\u003e {});\n//=\u003e true\n\nis.boundFunction(function () {}.bind(null));\n//=\u003e true\n\nis.boundFunction(function () {});\n//=\u003e false\n```\n\n##### .map(value)\n\n##### .set(value)\n\n##### .weakMap(value)\n\n##### .weakSet(value)\n\n#### Typed arrays\n\n##### .int8Array(value)\n\n##### .uint8Array(value)\n\n##### .uint8ClampedArray(value)\n\n##### .int16Array(value)\n\n##### .uint16Array(value)\n\n##### .int32Array(value)\n\n##### .uint32Array(value)\n\n##### .float32Array(value)\n\n##### .float64Array(value)\n\n##### .bigInt64Array(value)\n\n##### .bigUint64Array(value)\n\n#### Structured data\n\n##### .arrayBuffer(value)\n\n##### .sharedArrayBuffer(value)\n\n##### .dataView(value)\n\n#### Emptiness\n\n##### .emptyString(value)\n\nReturns `true` if the value is a `string` and the `.length` is 0.\n\n##### .nonEmptyString(value)\n\nReturns `true` if the value is a `string` and the `.length` is more than 0.\n\n##### .emptyStringOrWhitespace(value)\n\nReturns `true` if `is.emptyString(value)` or if it's a `string` that is all whitespace.\n\n##### .emptyArray(value)\n\nReturns `true` if the value is an `Array` and the `.length` is 0.\n\n##### .nonEmptyArray(value)\n\nReturns `true` if the value is an `Array` and the `.length` is more than 0.\n\n##### .emptyObject(value)\n\nReturns `true` if the value is an `Object` and `Object.keys(value).length` is 0.\n\nPlease note that `Object.keys` returns only own enumerable properties. Hence something like this can happen:\n\n```ts\nconst object1 = {};\n\nObject.defineProperty(object1, 'property1', {\n value: 42,\n writable: true,\n enumerable: false,\n configurable: true\n});\n\nis.emptyObject(object1);\n//=\u003e true\n```\n\n##### .nonEmptyObject(value)\n\nReturns `true` if the value is an `Object` and `Object.keys(value).length` is more than 0.\n\n##### .emptySet(value)\n\nReturns `true` if the value is a `Set` and the `.size` is 0.\n\n##### .nonEmptySet(Value)\n\nReturns `true` if the value is a `Set` and the `.size` is more than 0.\n\n##### .emptyMap(value)\n\nReturns `true` if the value is a `Map` and the `.size` is 0.\n\n##### .nonEmptyMap(value)\n\nReturns `true` if the value is a `Map` and the `.size` is more than 0.\n\n#### Miscellaneous\n\n##### .directInstanceOf(value, class)\n\nReturns `true` if `value` is a direct instance of `class`.\n\n```ts\nis.directInstanceOf(new Error(), Error);\n//=\u003e true\n\nclass UnicornError extends Error {}\n\nis.directInstanceOf(new UnicornError(), Error);\n//=\u003e false\n```\n\n##### .urlInstance(value)\n\nReturns `true` if `value` is an instance of the [`URL` class](https://developer.mozilla.org/en-US/docs/Web/API/URL).\n\n```ts\nconst url = new URL('https://example.com');\n\nis.urlInstance(url);\n//=\u003e true\n```\n\n##### .urlString(value)\n\nReturns `true` if `value` is a URL string.\n\nNote: this only does basic checking using the [`URL` class](https://developer.mozilla.org/en-US/docs/Web/API/URL) constructor.\n\n```ts\nconst url = 'https://example.com';\n\nis.urlString(url);\n//=\u003e true\n\nis.urlString(new URL(url));\n//=\u003e false\n```\n\n##### .truthy(value)\n\nReturns `true` for all values that evaluate to true in a boolean context:\n\n```ts\nis.truthy('🦄');\n//=\u003e true\n\nis.truthy(undefined);\n//=\u003e false\n```\n\n##### .falsy(value)\n\nReturns `true` if `value` is one of: `false`, `0`, `''`, `null`, `undefined`, `NaN`.\n\n##### .nan(value)\n\n##### .nullOrUndefined(value)\n\n##### .primitive(value)\n\nJavaScript primitives are as follows: `null`, `undefined`, `string`, `number`, `boolean`, `symbol`.\n\n##### .integer(value)\n\n##### .safeInteger(value)\n\nReturns `true` if `value` is a [safe integer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger).\n\n##### .plainObject(value)\n\nAn object is plain if it's created by either `{}`, `new Object()`, or `Object.create(null)`.\n\n##### .iterable(value)\n\n##### .asyncIterable(value)\n\n##### .class(value)\n\nReturns `true` for instances created by a class.\n\n##### .typedArray(value)\n\n##### .arrayLike(value)\n\nA `value` is array-like if it is not a function and has a `value.length` that is a safe integer greater than or equal to 0.\n\n```ts\nis.arrayLike(document.forms);\n//=\u003e true\n\nfunction foo() {\n is.arrayLike(arguments);\n //=\u003e true\n}\nfoo();\n```\n\n##### .inRange(value, range)\n\nCheck if `value` (number) is in the given `range`. The range is an array of two values, lower bound and upper bound, in no specific order.\n\n```ts\nis.inRange(3, [0, 5]);\nis.inRange(3, [5, 0]);\nis.inRange(0, [-2, 2]);\n```\n\n##### .inRange(value, upperBound)\n\nCheck if `value` (number) is in the range of `0` to `upperBound`.\n\n```ts\nis.inRange(3, 10);\n```\n\n##### .infinite(value)\n\nCheck if `value` is `Infinity` or `-Infinity`.\n\n##### .evenInteger(value)\n\nReturns `true` if `value` is an even integer.\n\n##### .oddInteger(value)\n\nReturns `true` if `value` is an odd integer.\n\n##### .any(predicate | predicate[], ...values)\n\nUsing a single `predicate` argument, returns `true` if **any** of the input `values` returns true in the `predicate`:\n\n```ts\nis.any(is.string, {}, true, '🦄');\n//=\u003e true\n\nis.any(is.boolean, 'unicorns', [], new Map());\n//=\u003e false\n```\n\nUsing an array of `predicate[]`, returns `true` if **any** of the input `values` returns true for **any** of the `predicates` provided in an array:\n\n```ts\nis.any([is.string, is.number], {}, true, '🦄');\n//=\u003e true\n\nis.any([is.boolean, is.number], 'unicorns', [], new Map());\n//=\u003e false\n```\n\n##### .all(predicate, ...values)\n\nReturns `true` if **all** of the input `values` returns true in the `predicate`:\n\n```ts\nis.all(is.object, {}, new Map(), new Set());\n//=\u003e true\n\nis.all(is.string, '🦄', [], 'unicorns');\n//=\u003e false\n```\n\n## Type guards\n\nWhen using `is` together with TypeScript, [type guards](http://www.typescriptlang.org/docs/handbook/advanced-types.html#type-guards-and-differentiating-types) are being used extensively to infer the correct type inside if-else statements.\n\n```ts\nimport is from \"deno.land/x/is_type/mod.ts\";\n\nconst padLeft = (value: string, padding: string | number) =\u003e {\n if (is.number(padding)) {\n  // `padding` is typed as `number`\n  return Array(padding + 1).join(' ') + value;\n }\n\n if (is.string(padding)) {\n  // `padding` is typed as `string`\n  return padding + value;\n }\n\n throw new TypeError(`Expected 'padding' to be of type 'string' or 'number', got '${is(padding)}'.`);\n}\n\npadLeft('🦄', 3);\n//=\u003e '   🦄'\n\npadLeft('🦄', '🌈');\n//=\u003e '🌈🦄'\n```\n\n## Type assertions\n\nThe type guards are also available as [type assertions](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions), which throw an error for unexpected types. It is a convenient one-line version of the often repetitive \"if-not-expected-type-throw\" pattern.\n\n```ts\nimport {assert} from \"deno.land/x/is_type/mod.ts\";\n\nconst handleMovieRatingApiResponse = (response: unknown) =\u003e {\n assert.plainObject(response);\n // `response` is now typed as a plain `object` with `unknown` properties.\n\n assert.number(response.rating);\n // `response.rating` is now typed as a `number`.\n\n assert.string(response.title);\n // `response.title` is now typed as a `string`.\n\n return `${response.title} (${response.rating * 10})`;\n};\n\nhandleMovieRatingApiResponse({rating: 0.87, title: 'The Matrix'});\n//=\u003e 'The Matrix (8.7)'\n\n// This throws an error.\nhandleMovieRatingApiResponse({rating: '🦄'});\n```\n\n## Generic type parameters\n\nThe type guards and type assertions are aware of [generic type parameters](https://www.typescriptlang.org/docs/handbook/generics.html), such as `Promise\u003cT\u003e` and `Map\u003cKey, Value\u003e`. The default is `unknown` for most cases, since `is` cannot check them at runtime. If the generic type is known at compile-time, either implicitly (inferred) or explicitly (provided), `is` propagates the type so it can be used later.\n\nUse generic type parameters with caution. They are only checked by the TypeScript compiler, and not checked by `is` at runtime. This can lead to unexpected behavior, where the generic type is _assumed_ at compile-time, but actually is something completely different at runtime. It is best to use `unknown` (default) and type-check the value of the generic type parameter at runtime with `is` or `assert`.\n\n```ts\nimport {assert} from \"deno.land/x/is_type/mod.ts\";\n\nasync function badNumberAssumption(input: unknown) {\n // Bad assumption about the generic type parameter fools the compile-time type system.\n assert.promise\u003cnumber\u003e(input);\n // `input` is a `Promise` but only assumed to be `Promise\u003cnumber\u003e`.\n\n const resolved = await input;\n // `resolved` is typed as `number` but was not actually checked at runtime.\n\n // Multiplication will return NaN if the input promise did not actually contain a number.\n return 2 * resolved;\n}\n\nasync function goodNumberAssertion(input: unknown) {\n assert.promise(input);\n // `input` is typed as `Promise\u003cunknown\u003e`\n\n const resolved = await input;\n // `resolved` is typed as `unknown`\n\n assert.number(resolved);\n // `resolved` is typed as `number`\n\n // Uses runtime checks so only numbers will reach the multiplication.\n return 2 * resolved;\n}\n\nbadNumberAssumption(Promise.resolve('An unexpected string'));\n//=\u003e NaN\n\n// This correctly throws an error because of the unexpected string value.\ngoodNumberAssertion(Promise.resolve('An unexpected string'));\n```\n\n## Inspired\n\nInspired by [is](https://github.com/sindresorhus/is) - Type check values for node.js\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frjoydip%2Fis_type","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frjoydip%2Fis_type","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frjoydip%2Fis_type/lists"}