{"id":21905776,"url":"https://github.com/deno911/dis","last_synced_at":"2026-05-11T02:13:07.070Z","repository":{"id":57747106,"uuid":"522099930","full_name":"deno911/dis","owner":"deno911","description":"Typechecking with ease.","archived":false,"fork":false,"pushed_at":"2023-06-18T00:16:45.000Z","size":143,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-12T22:56:10.743Z","etag":null,"topics":["assertions","deno","deno-module","denoland","is","javascript","type-assertion","type-guards","type-safety","typecheck","typeguards","typeof","typescript","utilities"],"latest_commit_sha":null,"homepage":"https://deno.land/x/dis","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/deno911.png","metadata":{"funding":{"ko_fi":"nberlette"},"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}},"created_at":"2022-08-07T02:38:58.000Z","updated_at":"2024-05-02T04:41:29.000Z","dependencies_parsed_at":"2023-01-28T06:15:33.455Z","dependency_job_id":null,"html_url":"https://github.com/deno911/dis","commit_stats":null,"previous_names":["nberlette/dis"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/deno911/dis","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deno911%2Fdis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deno911%2Fdis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deno911%2Fdis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deno911%2Fdis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deno911","download_url":"https://codeload.github.com/deno911/dis/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deno911%2Fdis/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32528105,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-02T01:12:54.858Z","status":"online","status_checked_at":"2026-05-02T02:00:05.923Z","response_time":132,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["assertions","deno","deno-module","denoland","is","javascript","type-assertion","type-guards","type-safety","typecheck","typeguards","typeof","typescript","utilities"],"created_at":"2024-11-28T16:37:16.171Z","updated_at":"2026-05-02T08:31:26.234Z","avatar_url":"https://github.com/deno911.png","language":"TypeScript","funding_links":["https://ko-fi.com/nberlette"],"categories":[],"sub_categories":[],"readme":"\u003ch1\u003e🦕 dis\u003c/h1\u003e\n\n[![](https://migo.deno.dev/width=1280;height=640;pxRatio=1;bgColor=10141a;icon=deno;iconColor=papayawhip;titleColor=white;subtitleColor=white;iconY=80;iconX=950;titleFontSize=120;titleX=175;titleY=450;subtitleX=420;subtitleY=550;subtitleFontSize=48;titleTextAnchor=left;subtitleTextAnchor=left/dis/https://deno.land/x/dis.png)](https://deno.land/x/dis)\n\nOriginally by [**Sindre Sorhus**](https://github.com/sindresorhus/is) for Node,\nported by [**Nicholas Berlette**](https://github.com/nberlette) for Deno.\n\n---\n\n## Usage\n\n```ts\nimport * as is from \"https://deno.land/x/dis@0.2.0/mod.ts\";\n```\n\n### Type Checking\n\n```ts\nis(\"🦕\");\n// 'string'\n\nis(new Map());\n// 'Map'\n\nis.number(6);\n// true\n```\n\n### Assertions\n\n[Assertions](#type-assertions) perform the same type checks, but throw an error\nif the type does not match.\n\n```ts\nimport { assert } from \"https://deno.land/x/dis@0.2.0/mod.ts\";\n\nassert.string(2);\n// =\u003e Error: Expected value which is `string`, received value of type `number`.\n```\n\n### Assertions with TypeScript\n\n```ts\nimport { assert } from \"https://deno.land/x/dis@0.2.0/mod.ts\";\n\nassert.string(foo);\n// `foo` is now typed as a `string`.\n```\n\n## Highlights\n\n- Written in TypeScript, for Deno and Deno Deploy\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\n  caution)\n- Actively maintained\n\n---\n\n# API\n\n## is(value)\n\nAttempts to ascertain the type of the value it receives. Accepts only one\nargument.\n\n```ts\nis(\"🦕\");\n// 'string'\n\nis(new Map());\n// 'Map'\n```\n\n\u003e **Returns**: the type of `value`.\n\n## `is.{method}`\n\nAll the below methods accept a value and returns a boolean for whether the value\nis of the desired type.\n\n```ts\nis.number(6);\n// true\n\nis.undefined(true);\n// false\n```\n\n---\n\n## Primitives\n\n\u003e **Note**: Primitives are **lowercase** and object types are **camelCase**.\n\n\u003cdetails\u003e\u003csummary\u003e\u003cstrong\u003eExamples of Primitives\u003c/strong\u003e\u003c/summary\u003e\n\n---\n\n- `'undefined'`\n- `'null'`\n- `'string'`\n- `'symbol'`\n- `'Array'`\n- `'Function'`\n- `'Object'`\n\n\u003e **Note**: It will throw an error if you try to feed it object-wrapped\n\u003e primitives, as that's a bad practice (e.g. `new String('foo')`)\n\n\u003c/details\u003e\n\n\u003cdetails open\u003e\u003csummary\u003e\u003cstrong\u003eAPI Methods\u003c/strong\u003e\u003c/summary\u003e\n\n---\n\n### undefined\n\n```ts\nis.undefined(value);\n```\n\n### null\n\n```ts\nis.null(value);\n```\n\n\u003e **Note**: TypeScript users must use `.null_()` because of a TypeScript naming\n\u003e limitation.\n\n### string\n\n```ts\nis.string(value);\n```\n\n### number\n\n```ts\nis.number(value);\n```\n\n\u003e **Note:** `is.number(NaN)` returns `false`. This intentionally deviates from\n\u003e `typeof` behavior to increase user-friendliness of `is` type checks.\n\n### boolean\n\n```ts\nis.boolean(value);\n```\n\n### symbol\n\n```ts\nis.symbol(value);\n```\n\n### bigint\n\n```ts\nis.bigint(value);\n```\n\n\u003c/details\u003e\n\n---\n\n## Builtins\n\n\u003cdetails open\u003e\u003csummary\u003e\u003cstrong\u003eAPI Methods\u003c/strong\u003e\u003c/summary\u003e\n\n---\n\n### array\n\n```ts\nis.array(value, assertion?)\n```\n\n\u003e **Returns**: true if `value` is an array and all of its items match the\n\u003e assertion (if provided).\n\n#### Examples\n\n```ts\nis.array(value); // Validate `value` is an array.\nis.array(value, is.number); // Validate `value` is an array and all of its items are numbers.\n```\n\n### function\n\n```ts\nis.function(value);\n```\n\n\u003e **Note**: TypeScript users must use `.function_()` because of a TypeScript\n\u003e naming limitation.\n\n### buffer\n\n```ts\nis.buffer(value);\n```\n\n### blob\n\n```ts\nis.blob(value);\n```\n\n### object\n\n```ts\nis.object(value);\n```\n\n\u003e **Important**: Keep in mind that\n\u003e [functions are objects too](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions).\n\n### numericString\n\n```ts\nis.numericString(value);\n```\n\n\u003e **Returns**: `true` for a string that represents a number satisfying\n\u003e `is.number`, for example, `'42'` and `'-8.3'`.\n\n\u003e **Important**: `'NaN'` returns `false`, but `'Infinity'` and `'-Infinity'`\n\u003e return `true`.\n\n### regExp\n\n```ts\nis.regExp(value);\n```\n\n### date\n\n```ts\nis.date(value);\n```\n\n### error\n\n```ts\nis.error(value);\n```\n\n### nativePromise\n\n```ts\nis.nativePromise(value);\n```\n\n### promise\n\n```ts\nis.promise(value);\n```\n\n\u003e **Returns**: `true` for any object with a `.then()` and `.catch()` method.\n\u003e Prefer this one over `.nativePromise()` as you usually want to allow userland\n\u003e promise implementations too.\n\n### generator\n\n```ts\nis.generator(value);\n```\n\n\u003e **Returns**: `true` for any object that implements its own `.next()` and\n\u003e `.throw()` methods and has a function definition for `Symbol.iterator`.\n\n### generatorFunction\n\n```ts\nis.generatorFunction(value);\n```\n\n### asyncFunction\n\n```ts\nis.asyncFunction(value);\n```\n\n\u003e **Returns**: `true` for any `async` function that can be called with the\n\u003e `await` operator.\n\n#### Examples\n\n```ts\nis.asyncFunction(async () =\u003e {});\n// true\n\nis.asyncFunction(() =\u003e {});\n// false\n```\n\n### asyncGenerator\n\n```ts\nis.asyncGenerator(value);\n```\n\n#### Examples\n\n```ts\nis.asyncGenerator(\n  (async function* () {\n    yield 4;\n  })(),\n);\n// true\n\nis.asyncGenerator(\n  (function* () {\n    yield 4;\n  })(),\n);\n// false\n```\n\n### asyncGeneratorFunction\n\n```ts\nis.asyncGeneratorFunction(value);\n```\n\n#### Examples\n\n```ts\nis.asyncGeneratorFunction(async function* () {\n  yield 4;\n});\n// true\n\nis.asyncGeneratorFunction(function* () {\n  yield 4;\n});\n// false\n```\n\n### boundFunction\n\n```ts\nis.boundFunction(value);\n```\n\n\u003e **Returns**: `true` for any `bound` function.\n\n```ts\nis.boundFunction(() =\u003e {});\n// true\n\nis.boundFunction(function () {}.bind(null));\n// true\n\nis.boundFunction(function () {});\n// false\n```\n\n### map\n\n```ts\nis.map(value);\n```\n\n### set\n\n```ts\nis.set(value);\n```\n\n### weakMap\n\n```ts\nis.weakMap(value);\n```\n\n### weakSet\n\n```ts\nis.weakSet(value);\n```\n\n### weakRef\n\n```ts\nis.weakRef(value);\n```\n\n\u003c/details\u003e\n\n---\n\n## TypedArrays\n\n\u003cdetails open\u003e\u003csummary\u003e\u003cstrong\u003eAPI Methods\u003c/strong\u003e\u003c/summary\u003e\n\n---\n\n### int8Array\n\n```ts\nis.int8Array(value);\n```\n\n### uint8Array\n\n```ts\nis.uint8Array(value);\n```\n\n### uint8ClampedArray\n\n```ts\nis.uint8ClampedArray(value);\n```\n\n### int16Array\n\n```ts\nis.int16Array(value);\n```\n\n### uint16Array\n\n```ts\nis.uint16Array(value);\n```\n\n### int32Array\n\n```ts\nis.int32Array(value);\n```\n\n### uint32Array\n\n```ts\nis.uint32Array(value);\n```\n\n### float32Array\n\n```ts\nis.float32Array(value);\n```\n\n### float64Array\n\n```ts\nis.float64Array(value);\n```\n\n### bigInt64Array\n\n```ts\nis.bigInt64Array(value);\n```\n\n### bigUint64Array\n\n```ts\nis.bigUint64Array(value);\n```\n\n\u003c/details\u003e\n\n---\n\n## Structured Data\n\n\u003cdetails open\u003e\u003csummary\u003e\u003cstrong\u003eAPI Methods\u003c/strong\u003e\u003c/summary\u003e\n\n---\n\n### arrayBuffer\n\n```ts\nis.arrayBuffer(value);\n```\n\n### sharedArrayBuffer\n\n```ts\nis.sharedArrayBuffer(value);\n```\n\n### dataView\n\n```ts\nis.dataView(value);\n```\n\n### enumCase\n\n```ts\nis.enumCase(value, enum)\n```\n\n\u003e **Note**: **TypeScript-only**. Returns `true` if `value` is a member of\n\u003e `enum`.\n\n```ts\nenum Direction {\n  Ascending = \"ascending\",\n  Descending = \"descending\",\n}\nis.enumCase(\"ascending\", Direction);\n// true\nis.enumCase(\"other\", Direction);\n// false\n```\n\n\u003c/details\u003e\n\n---\n\n## Emptiness\n\n\u003cdetails open\u003e\u003csummary\u003e\u003cstrong\u003eAPI Methods\u003c/strong\u003e\u003c/summary\u003e\n\n---\n\n### emptyString\n\n```ts\nis.emptyString(value);\n```\n\n\u003e **Returns**: `true` if the value is a `string` and the `.length` is 0.\n\n### emptyStringOrWhitespace\n\n```ts\nis.emptyStringOrWhitespace(value);\n```\n\n\u003e **Returns**: `true` if `is.emptyString(value)` or if it's a `string` that is\n\u003e all whitespace.\n\n### nonEmptyString\n\n```ts\nis.nonEmptyString(value);\n```\n\n\u003e **Returns**: `true` if the value is a `string` and the `.length` is more\n\u003e than 0.\n\n### nonEmptyStringAndNotWhitespace\n\n```ts\nis.nonEmptyStringAndNotWhitespace(value);\n```\n\n\u003e **Returns**: `true` if the value is a `string` that is not empty and not\n\u003e whitespace.\n\n```ts\nconst values = [\"property1\", \"\", null, \"property2\", \"    \", undefined];\nvalues.filter(is.nonEmptyStringAndNotWhitespace);\n// ['property1', 'property2']\n```\n\n### emptyArray\n\n```ts\nis.emptyArray(value);\n```\n\n\u003e **Returns**: `true` if the value is an `Array` and the `.length` is 0.\n\n### nonEmptyArray\n\n```ts\nis.nonEmptyArray(value);\n```\n\n\u003e **Returns**: `true` if the value is an `Array` and the `.length` is more\n\u003e than 0.\n\n### emptyObject\n\n```ts\nis.emptyObject(value);\n```\n\n\u003e **Returns**: `true` if the value is an `Object` and\n\u003e `Object.keys(value).length` is 0.\n\n\u003e **Note**: `Object.keys` returns only own enumerable properties. Hence\n\u003e something like this can happen:\n\n```ts\nconst object1 = {};\nObject.defineProperty(object1, \"property1\", {\n  value: 42,\n  writable: true,\n  enumerable: false,\n  configurable: true,\n});\nis.emptyObject(object1);\n// true\n```\n\n### nonEmptyObject\n\n```ts\nis.nonEmptyObject(value);\n```\n\n\u003e **Returns**: `true` if the value is an `Object` and\n\u003e `Object.keys(value).length` is more than 0.\n\n### emptySet\n\n```ts\nis.emptySet(value);\n```\n\n\u003e **Returns**: `true` if the value is a `Set` and the `.size` is 0.\n\n### nonEmptySet\n\n```ts\nis.nonEmptySet(Value);\n```\n\n\u003e **Returns**: `true` if the value is a `Set` and the `.size` is more than 0.\n\n### emptyMap\n\n```ts\nis.emptyMap(value);\n```\n\n\u003e **Returns**: `true` if the value is a `Map` and the `.size` is 0.\n\n### nonEmptyMap\n\n```ts\nis.nonEmptyMap(value);\n```\n\n\u003e **Returns**: `true` if the value is a `Map` and the `.size` is more than 0.\n\n\u003c/details\u003e\n\n---\n\n## Everything Else\n\n\u003cdetails open\u003e\u003csummary\u003e\u003cstrong\u003eAPI Methods\u003c/strong\u003e\u003c/summary\u003e\n\n---\n\n### directInstanceOf\n\n```ts\nis.directInstanceOf(value, class)\n```\n\n\u003e **Returns**: `true` if `value` is a direct instance of `class`.\n\n```ts\nis.directInstanceOf(new Error(), Error);\n// true\nclass UnicornError extends Error {}\nis.directInstanceOf(new UnicornError(), Error);\n// false\n```\n\n### urlInstance\n\n```ts\nis.urlInstance(value);\n```\n\n\u003e **Returns**: `true` if `value` is an instance of the\n\u003e [`URL` class](https://mdn.io/URL).\n\n```ts\nconst url = new URL(\"https://example.com\");\nis.urlInstance(url);\n// true\n```\n\n### urlString\n\n```ts\nis.urlString(value);\n```\n\n\u003e **Returns**: `true` if `value` is a URL string.\n\nNote: this only does basic checking using the [`URL` class](https://mdn.io/URL)\nconstructor.\n\n```ts\nconst url = \"https://example.com\";\nis.urlString(url);\n// true\nis.urlString(new URL(url));\n// false\n```\n\n### truthy\n\n```ts\nis.truthy(value);\n```\n\n\u003e **Returns**: `true` for all values that evaluate to true in a boolean context:\n\n```ts\nis.truthy(\"🦕\");\n// true\nis.truthy(undefined);\n// false\n```\n\n### falsy\n\n```ts\nis.falsy(value);\n```\n\n\u003e **Returns**: `true` if `value` is one of: `false`, `0`, `''`, `null`,\n\u003e `undefined`, `NaN`.\n\n### NaN\n\n```ts\nis.nan(value);\n```\n\n### nullOrUndefined\n\n```ts\nis.nullOrUndefined(value);\n```\n\n### primitive\n\n```ts\nis.primitive(value);\n```\n\nJavaScript primitives are as follows: `null`, `undefined`, `string`, `number`,\n`boolean`, `symbol`.\n\n### integer\n\n```ts\nis.integer(value);\n```\n\n### safeInteger\n\n```ts\nis.safeInteger(value);\n```\n\n\u003e **Returns**: `true` if `value` is a\n\u003e [safe integer](https://mdn.io/isSafeInteger).\n\n### plainObject\n\n```ts\nis.plainObject(value);\n```\n\nAn object is plain if it's created by either `{}`, `new Object()`, or\n`Object.create(null)`.\n\n### iterable\n\n```ts\nis.iterable(value);\n```\n\n### asyncIterable\n\n```ts\nis.asyncIterable(value);\n```\n\n### class\n\n```ts\nis.class(value);\n```\n\n\u003e **Returns**: `true` for instances created by a class.\n\n**Note:** TypeScript users must use `.class_()` because of a TypeScript naming\nlimitation.\n\n### typedArray\n\n```ts\nis.typedArray(value);\n```\n\n### arrayLike\n\n```ts\nis.arrayLike(value);\n```\n\nA `value` is array-like if it is not a function and has a `value.length` that is\na safe integer greater than or equal to 0.\n\n```ts\nis.arrayLike(document.forms);\n// true\n\nfunction foo() {\n  is.arrayLike(arguments);\n  // true\n}\nfoo();\n```\n\n### inRange\n\n```ts\nis.inRange(value, range);\n```\n\nCheck if `value` (number) is in the given `range`. The range is an array of two\nvalues, 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\n\n```ts\nis.inRange(value, upperBound);\n```\n\nCheck if `value` (number) is in the range of `0` to `upperBound`.\n\n```ts\nis.inRange(3, 10);\n```\n\n### domElement\n\n```ts\nis.domElement(value);\n```\n\n\u003e **Returns**: `true` if `value` is a DOM Element.\n\n### nodeStream\n\n```ts\nis.nodeStream(value);\n```\n\n\u003e **Returns**: `true` if `value` is a Node.js\n\u003e [stream](https://nodejs.org/api/stream.html).\n\n```ts\nimport fs from \"node:fs\";\nis.nodeStream(fs.createReadStream(\"unicorn.png\"));\n// true\n```\n\n### observable\n\n```ts\nis.observable(value);\n```\n\n\u003e **Returns**: `true` if `value` is an `Observable`.\n\n```ts\nimport { Observable } from \"rxjs\";\nis.observable(new Observable());\n// true\n```\n\n### infinite\n\n```ts\nis.infinite(value);\n```\n\nCheck if `value` is `Infinity` or `-Infinity`.\n\n### evenInteger\n\n```ts\nis.evenInteger(value);\n```\n\n\u003e **Returns**: `true` if `value` is an even integer.\n\n### oddInteger\n\n```ts\nis.oddInteger(value);\n```\n\n\u003e **Returns**: `true` if `value` is an odd integer.\n\n### propertyKey\n\n```ts\nis.propertyKey(value);\n```\n\n\u003e **Returns**: `true` if `value` can be used as an object property key (either\n\u003e `string`, `number`, or `symbol`).\n\n### formData\n\n```ts\nis.formData(value);\n```\n\n\u003e **Returns**: `true` if `value` is an instance of the\n\u003e [`FormData` class](https://developer.mozilla.org/en-US/docs/Web/API/FormData).\n\n```ts\nconst data = new FormData();\nis.formData(data);\n// true\n```\n\n### urlSearchParams\n\n```ts\nis.urlSearchParams(value);\n```\n\n\u003e **Returns**: `true` if `value` is an instance of the\n\u003e [`URLSearchParams` class](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams).\n\n```ts\nconst searchParams = new URLSearchParams();\nis.urlSearchParams(searchParams);\n// true\n```\n\n### any\n\n```ts\nis.any(predicate | predicate[], ...values)\n```\n\nUsing a single `predicate` argument, returns `true` if **any** of the input\n`values` returns true in the `predicate`:\n\n```ts\nis.any(is.string, {}, true, \"🦕\");\n// true\nis.any(is.boolean, \"denosaurs\", [], new Map());\n// false\n```\n\nUsing an array of `predicate[]`, returns `true` if **any** of the input `values`\nreturns true for **any** of the `predicates` provided in an array:\n\n```ts\nis.any([is.string, is.number], {}, true, \"🦕\");\n// true\nis.any([is.boolean, is.number], \"denosaurs\", [], new Map());\n// false\n```\n\n### all\n\n```ts\nis.all(predicate, ...values);\n```\n\n\u003e **Returns**: `true` if **all** of the input `values` returns true in the\n\u003e `predicate`:\n\n```ts\nis.all(is.object, {}, new Map(), new Set());\n// true\nis.all(is.string, \"🦕\", [], \"denosaurs\");\n// false\n```\n\n\u003c/details\u003e\n\n---\n\n## Type Guards\n\nWhen using `is` together with TypeScript,\n[type guards](http://www.typescriptlang.org/docs/handbook/advanced-types.html#type-guards-and-differentiating-types)\nare being used extensively to infer the correct type inside if-else statements.\n\n\u003cdetails open\u003e\u003csummary\u003e\u003cstrong\u003eExamples\u003c/strong\u003e\u003c/summary\u003e\n\n---\n\n```ts\nimport is from \"https://deno.land/x/dis@0.2.0/mod.ts\";\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(\n    `Expected 'padding' to be of type 'string' or 'number', got '${\n      is(padding)\n    }'.`,\n  );\n};\npadLeft(\"🦕\", 3);\n// '   🦕'\n\npadLeft(\"🦕\", \"🌈\");\n// '🌈🦕'\n```\n\n\u003c/details\u003e\n\n---\n\n## Type Assertions\n\nThe type guards are also available as\n[type assertions](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions),\nwhich throw an error for unexpected types. It is a convenient one-line version\nof the often repetitive `\"if-not-expected-type-throw\"` pattern.\n\n\u003cdetails open\u003e\u003csummary\u003e\u003cstrong\u003eExamples\u003c/strong\u003e\u003c/summary\u003e\n\n---\n\n```ts\nimport { assert } from \"https://deno.land/x/dis@0.2.0/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};\nhandleMovieRatingApiResponse({ rating: 0.87, title: \"The Matrix\" });\n// 'The Matrix (8.7)'\n\n// This throws an error.\nhandleMovieRatingApiResponse({ rating: \"🦕\" });\n```\n\n\u003c/details\u003e\n\n---\n\n## Generic type parameters\n\n\u003cdetails open\u003e\u003csummary\u003e\u003cstrong\u003eMore Information\u003c/strong\u003e\u003c/summary\u003e\n\n---\n\n---\n\nThe type guards and type assertions are aware of\n[generic type parameters](https://www.typescriptlang.org/docs/handbook/generics.html),\nsuch as `Promise\u003cT\u003e` and `Map\u003cKey, Value\u003e`. The default is `unknown` for most\ncases, since `is` cannot check them at runtime. If the generic type is known at\ncompile-time, either implicitly (inferred) or explicitly (provided), `is`\npropagates the type so it can be used later.\n\nUse generic type parameters with caution. They are only checked by the\nTypeScript compiler, and not checked by `is` at runtime. This can lead to\nunexpected behavior, where the generic type is _assumed_ at compile-time, but\nactually is something completely different at runtime. It is best to use\n`unknown` (default) and type-check the value of the generic type parameter at\nruntime with `is` or `assert`.\n\n\u003c/details\u003e\n\u003cdetails open\u003e\u003csummary\u003e\u003cstrong\u003eExamples\u003c/strong\u003e\u003c/summary\u003e\n\n---\n\n```ts\nimport { assert } from \"https://deno.land/x/dis@0.2.0/mod.ts\";\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  const resolved = await input;\n  // `resolved` is typed as `number` but was not actually checked at runtime.\n  // Multiplication will return NaN if the input promise did not actually contain a number.\n  return 2 * resolved;\n}\nasync function goodNumberAssertion(input: unknown) {\n  assert.promise(input);\n  // `input` is typed as `Promise\u003cunknown\u003e`\n  const resolved = await input;\n  // `resolved` is typed as `unknown`\n  assert.number(resolved);\n  // `resolved` is typed as `number`\n  // Uses runtime checks so only numbers will reach the multiplication.\n  return 2 * resolved;\n}\nbadNumberAssumption(Promise.resolve(\"An unexpected string\"));\n// NaN\n// This correctly throws an error because of the unexpected string value.\ngoodNumberAssertion(Promise.resolve(\"An unexpected string\"));\n```\n\n\u003c/details\u003e\n\n---\n\n## Frequently Asked Questions\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eWhy yet another type checking module?\u003c/strong\u003e\u003c/summary\u003e\n\n---\n\nThere are hundreds of type checking modules on npm, unfortunately, I couldn't\nfind any that fit my needs:\n\n- Includes both type methods and ability to get the type\n- Types of primitives returned as lowercase and object types as camelcase\n- Covers all built-ins\n- Unsurprising behavior\n- Well-maintained\n- Comprehensive test suite\n\nFor the ones I found, pick 3 of these.\n\nThe most common mistakes I noticed in these modules was using `instanceof` for\ntype checking, forgetting that functions are objects, and omitting `symbol` as a\nprimitive.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003e\u003cstrong\u003eWhy not just use `instanceof` instead of this package?\u003c/strong\u003e\u003c/summary\u003e\n\n---\n\n`instanceof` does not work correctly for all types and it does not work across\n[realms](https://stackoverflow.com/a/49832343/64949). Examples of realms are\niframes, windows, web workers, and the `vm` module in Node.js.\n\n\u003c/details\u003e\n\n---\n\n**MIT License**. Originally by\n[**Sindre Sorhus**](https://github.com/sindresorhus/is). Ported by\n[**Nicholas Berlette**](https://github.com/nberlette) for Deno.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeno911%2Fdis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeno911%2Fdis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeno911%2Fdis/lists"}