{"id":20240415,"url":"https://github.com/ariarzer/type","last_synced_at":"2026-06-01T06:32:21.975Z","repository":{"id":128473680,"uuid":"130608212","full_name":"ariarzer/type","owner":"ariarzer","description":"Tiny library for determining the type. Can detect custom types.","archived":false,"fork":false,"pushed_at":"2020-04-29T15:48:05.000Z","size":17,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-03T15:13:54.918Z","etag":null,"topics":["type","typeof"],"latest_commit_sha":null,"homepage":"","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/ariarzer.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-04-22T21:14:34.000Z","updated_at":"2022-08-07T14:24:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"d1a0111c-9156-43dc-9e0c-1277ab7f0f78","html_url":"https://github.com/ariarzer/type","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/ariarzer/type","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ariarzer%2Ftype","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ariarzer%2Ftype/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ariarzer%2Ftype/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ariarzer%2Ftype/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ariarzer","download_url":"https://codeload.github.com/ariarzer/type/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ariarzer%2Ftype/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33763649,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-01T02:00:06.963Z","response_time":115,"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":["type","typeof"],"created_at":"2024-11-14T08:46:16.717Z","updated_at":"2026-06-01T06:32:21.892Z","avatar_url":"https://github.com/ariarzer.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Type\n\n[![Build status](https://travis-ci.org/ariarzer/type.svg?branch=master)](https://travis-ci.org/ariarzer/type)\n[![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/ariarzer/type/blob/master/LICENSE)\n![Maintenance intention for this crate](https://img.shields.io/badge/maintenance-actively--developed-brightgreen.svg)\n[![GitHub package version](https://img.shields.io/github/package-json/v/ariarzer/type.svg)](https://github.com/ariarzer/type)\n\nTiny library for __determining the type__.\n \nCorrectly handles arrays and `null` and can detection different objects for the name of the constructor.\n\nEverything works out of the box.\n\n__Size__: 133 B.\n\n### Install\n\n```sh\nnpm i ariarzer/type\n```\n \n### Usage\n\n```js\nconst type = require('type');\n\ntype([]); //=\u003e 'array'\ntype(new Date()); //=\u003e 'object'\n```\n\nAlso you can use the second argument `true` to detection objects.\nIn this case the constructor name is returned in lowercase.\n\n```js\ntype(new Date(), true); //=\u003e 'date'\ntype(new myObject(), true); //=\u003e 'myobject'\n```\n\n### Configuration\n\n#### Modes:\n\n* **Normal**: works like almost `typeof`, but it is correct to handle `null` and arrays.\n\n* **All**: distinguishes types of objects, returns the name of the object constructor in lowercase.\n\nExamples: \n\n|                 | normal       | all          |\n|:----------------|:-------------|:-------------|\n|`undefined`      |`'undefined'` |`'undefined'` |\n|`null`           |`'null'`      |`'null'`      |\n|`[]`             |`'array'`     |`'array'`     |\n|`Symbol()`       |`'symbol'`    |`'symbol'`    | \n|`new WeakSet()`  |`'object'`    |`'weakset'`   | \n|`new Date()`     |`'object'`    |`'date'`      | \n|`new MyObject()` |`'object'`    |`'myobject'`  |\n|`document.createElement('div')` |`'object'`    |`'htmldivelement'` |\n\n```js\nconst config = {\n  mode: 'all', // string: 'all' || 'normal' (default: 'normal')\n}\n```\n\nExample of using modes:\n ```js\nconst type = require('type');\n\nconst myType = type.create({mode: 'all'});\nmyType(new myObject()); //=\u003e 'myobject'\n\n// But, you can run that... \ntype(new myObject(), true); //=\u003e 'myobject';\n// ...and get a similar result. \n```\n\n#### Custom types:\n\nIf you want to detect s custom type, for example, the days of the week, you can do this with use a config.\n\n```js\n// write a config..\nconst week =  ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];\n\nconst customTypes = week.map((item, index) =\u003e {\n  return {\n    name: item,\n    is: function (arg) {\n      return type(arg, true) === 'date' \u0026\u0026 arg.getDay() === index;\n    },\n  };\n});\n\n// ...create a custom function...\nconst daysDetector = type.create(customTypes);\n\n// ..and use it\ndaysDetector(new Date(2019, 4, 25)) //=\u003e 'saturday'  (May 25 2019) \ndaysDetector(new Date(2019, 4, 26)) //=\u003e 'sunday'    (May 26 2019) \ndaysDetector(new myObject()) //=\u003e 'object'\n``` \n\nYou can use modes and custom types together.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fariarzer%2Ftype","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fariarzer%2Ftype","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fariarzer%2Ftype/lists"}