{"id":16908537,"url":"https://github.com/gilbarbara/is-lite","last_synced_at":"2025-03-17T07:30:48.124Z","repository":{"id":30276837,"uuid":"124466231","full_name":"gilbarbara/is-lite","owner":"gilbarbara","description":"Type check tool","archived":false,"fork":false,"pushed_at":"2024-01-02T15:22:16.000Z","size":2120,"stargazers_count":18,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-15T03:48:11.960Z","etag":null,"topics":["lite","type-check","type-test"],"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/gilbarbara.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":"2018-03-09T00:47:20.000Z","updated_at":"2024-11-03T06:52:56.000Z","dependencies_parsed_at":"2024-06-18T15:33:12.534Z","dependency_job_id":"592d7c02-1a0d-42d2-ae6a-41667e787bb9","html_url":"https://github.com/gilbarbara/is-lite","commit_stats":{"total_commits":79,"total_committers":1,"mean_commits":79.0,"dds":0.0,"last_synced_commit":"62cc4dc06f757120498462e0c81fe49a9569ba49"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gilbarbara%2Fis-lite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gilbarbara%2Fis-lite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gilbarbara%2Fis-lite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gilbarbara%2Fis-lite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gilbarbara","download_url":"https://codeload.github.com/gilbarbara/is-lite/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243848082,"owners_count":20357489,"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":["lite","type-check","type-test"],"created_at":"2024-10-13T18:51:49.867Z","updated_at":"2025-03-17T07:30:47.785Z","avatar_url":"https://github.com/gilbarbara.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# is-lite\n\n[![NPM version](https://badge.fury.io/js/is-lite.svg)](https://www.npmjs.com/package/is-lite) [![CI](https://github.com/gilbarbara/is-lite/actions/workflows/main.yml/badge.svg)](https://github.com/gilbarbara/is-lite/actions/workflows/main.yml) [![is-lite](https://badgen.net/bundlephobia/minzip/is-lite?label=size)](https://bundlephobia.com/result?p=is-lite) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=gilbarbara_is-lite\u0026metric=alert_status)](https://sonarcloud.io/summary/new_code?id=gilbarbara_is-lite) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=gilbarbara_is-lite\u0026metric=coverage)](https://sonarcloud.io/summary/new_code?id=gilbarbara_is-lite)\n\n\u003e Lightweight type check tool.\n\nTypescript ready with [type guards](http://www.typescriptlang.org/docs/handbook/advanced-types.html#type-guards-and-differentiating-types) to infer the correct type inside conditionals.\n\n## Setup\n\n```bash\nnpm install is-lite\n```\n\n## Usage\n\n```ts\nimport is from 'is-lite';\n\nis('value'); // string\nis.string('value'); // true\n```\n\nYou can also import any checker individually since 1.0\n\n```ts\nimport { isString } from 'is-lite/exports';\n\nisString('value'); // true\n```\n\n## API\n\n**is(value)**  \nReturns the type of the `value`.\n\nPrimitives are lowercase: `bigint`, `boolean`, `null`, `number`, `string`, `symbol`, `undefined`.\nThe rest are camelcase: `Array`, `Function`, `GeneratorFunction`, `Object`, ...\n\n**is.array(value)**\n\n**is.arrayOf(target: any[], predicate: (value: unknown) =\u003e boolean)**  \nCheck if all items in an array are of the same type.\n\n```ts\nis.arrayOf(['a', 'b'], is.string); // true\nis.arrayOf([123, 456], is.nnumber); // true\n\nis.arrayOf(['a', 1], is.string); // false\n```\n\n**is.asyncFunction(value)**  \nCheck if the `value` is an `async` function that can be called with `await`.\n\n```ts\nis.asyncFunction(async () =\u003e {}); // true\nis.asyncFunction(() =\u003e {}); // false\n```\n\n**is.asyncGeneratorFunction(value)**\n\n**is.bigint(value)**\n\n**is.boolean(value)**\n\n**is.date(value)**\n\n**is.defined(value)**  \nCheck if the `value` is anything but `undefined`.\n\n**is.domElement(value)**  \nCheck if the `value` is a DOM Element.\n\n**is.empty(value)**  \nReturns `true` if:\n\n- the value is a `string`, and the `length` is 0\n- the value is an `Object` and `Object.keys(value).length` is 0\n- the value is an `Array`, and the `length` is 0\n- the value is a `Map`, and the `size` is 0\n- the value is a `Set`, and the `size` is 0\n\n**is.error(value)**\n\n**is.function(value)**\n\n**is.generator(value)**  \nCheck for an object that has its own .next() and .throw() methods and has a function definition for `Symbol.iterator`\n\n**is.generatorFunction(value)**\n\n**is.instanceOf(value, class)**  \nCheck if the `value` is a direct instance of the `class`.\n\n```ts\nclass APIError extends Error {}\n\nconst error = new APIError('Fail');\n\nis.instanceOf(error, APIError); // true\nis.instanceOf(error, Error); // false\n```\n\n**is.iterable(value)**\n\n**is.map(value)**\n\n**is.nan(value)**\n\n**is.null(value)**\n\n**is.nullOrUndefined(value)**\n\n**is.number(value)**  \nNote: `is.number(NaN)` returns `false`\n\n**is.numericString(value)**  \nCheck for a string that represents a number.\n\n```ts\nis.numericString('42'); // true\nis.numericString('-5'); // true\nis.numericString('Inifinity'); // true\nis.numericString('NaN'); // true\n```\n\n**is.plainFunction(value)**  \nCheck if the `value` is a function (it doesn't include async and generator functions)\n\n**is.primitive(value)**\n\n**is.object(value)**  \nRemember that functions and arrays are objects too.\n\n**is.oneOf(target: any[], value: any)**  \nCheck if the `value` exists in the `target`\n\n```ts\nconst colors = ['red', 'green', 'blue'];\n\nis.oneOf(colors, 'green'); // true\nis.oneOf(colors, 'brown'); // false\n```\n\n**is.plainObject(value)**  \nCheck if the object is created by either `{}`, `new Object()` or `Object.create(null)`.\n\n**is.promise(value)**\n\n**is.propertyOf(target: object, key: string, predicate?: (value: unknown) =\u003e boolean)**  \nCheck if the `key` exists in the `target`. If you pass a `predicate` function, it will check the value's type.\n\n```ts\nconst map = { items: [1], isLogged: false, retries: 0 };\n\nis.propertyOf(map, 'retries'); // true\nis.propertyOf(map, 'auth'); // false\n\nis.propertyOf(map, 'retries', is.number); // true\nis.propertyOf(map, 'items', is.array); // true\nis.propertyOf(map, 'isLogged', is.string); // false\n```\n\n**is.regexp(value)**\n\n**is.set(value)**\n\n**is.string(value)**\n\n**is.symbol(value)**\n\n**is.undefined(value)**\n\n**is.weakMap(value)**\n\n**is.weakSet(value)**\n\n## Contributing\n\nContributions, issues, and feature requests are welcome!  \nFeel free to check the [issues page](https://github.com/gilbarbara/is-lite/issues).\n\n## Show your support\n\nGive a ⭐️ if this project helped you!\n\n## License\n\nCopyright © 2019 [Gil Barbara \u003cgilbarbara@gmail.com\u003e](https://github.com/gilbarbara).  \nThis project is [MIT](https://github.com/gilbarbara/is-lite/blob/main/LICENSE) licensed.\n\n## FAQ\n\n[@sindresorhus/is](https://github.com/sindresorhus/is) is fantastic, but I needed something even smaller (and simpler). This package covers the basics and is just 1k minified+gzipped.\n\nIf you need to support legacy browsers, the **Number.isNaN** polyfill is required.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgilbarbara%2Fis-lite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgilbarbara%2Fis-lite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgilbarbara%2Fis-lite/lists"}