{"id":25774487,"url":"https://github.com/nicolaeiotu/typelike","last_synced_at":"2026-01-28T12:34:16.700Z","repository":{"id":57383591,"uuid":"315034444","full_name":"NicolaeIotu/typelike","owner":"NicolaeIotu","description":"Javascript deep type checking by comparison","archived":false,"fork":false,"pushed_at":"2024-12-05T14:16:59.000Z","size":816,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-05T05:48:42.330Z","etag":null,"topics":["checking","checks","compare","comparison","deep","match","typelike","types","verify"],"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/NicolaeIotu.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2020-11-22T12:40:09.000Z","updated_at":"2024-12-05T14:17:00.000Z","dependencies_parsed_at":"2023-02-06T10:30:54.266Z","dependency_job_id":null,"html_url":"https://github.com/NicolaeIotu/typelike","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NicolaeIotu%2Ftypelike","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NicolaeIotu%2Ftypelike/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NicolaeIotu%2Ftypelike/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NicolaeIotu%2Ftypelike/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NicolaeIotu","download_url":"https://codeload.github.com/NicolaeIotu/typelike/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240983701,"owners_count":19888741,"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":["checking","checks","compare","comparison","deep","match","typelike","types","verify"],"created_at":"2025-02-27T05:30:07.749Z","updated_at":"2026-01-28T12:34:16.636Z","avatar_url":"https://github.com/NicolaeIotu.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Actions Status](https://github.com/NicolaeIotu/typelike/workflows/CI/badge.svg)\n![Actions Status](https://github.com/NicolaeIotu/typelike/workflows/Coverage/badge.svg)\n\n# typelike\n\nWith **typelike** you can reliably determine if an object resembles other template object(s) used as reference.\u003cbr\u003e\nThe comparison is done using the keys and the type of data where applicable.\n\n* [Examples](#examples)\n* [How to compare with typelike](#how-to-compare-with-typelike)\n* [Using multiple templates with typelike](#using-multiple-templates-with-typelike)\n* [typelike Settings](#typelike-settings)\n* [Others](#others)\n\n## Examples\n**Example 1:**\n```\nimport { typelike } from 'typelike'\n\nconst testObject = {\n  lvl1: { lvl2: [1, 2, 3], sm: 'type ... like' },\n  arr: [[1, 'xyz'], 'abcdef']\n}\n\nconst templateObject = {\n  lvl1: { lvl2: [3, 4, 212], sm: '' },\n  arr: [[44, ''], '']\n}\n\nconsole.log(typelike(testObject, templateObject)) // true\n```\n**Example 2:**\n```\nimport { typelike } from 'typelike'\n\nfunction contentGenerator () {\n  // ...\n  return {\n    lvl1: {\n      lvl2: {\n        lvl3: {\n          lvl4: {\n            item1: [1, 2, 3],\n            item2: true\n          }\n        }\n      }\n    },\n    arr: [[1, 'xyz'], 'abcdef'],\n    basic: 'test'\n  }\n}\n\nconst testObject = contentGenerator()\n\nconst templateObject = {\n  lvl1: {\n    lvl2: {\n      lvl3: {\n        lvl4: {\n          item1: [44, 66, 88],\n          item2: false\n        }\n      }\n    }\n  },\n  arr: [[45, 'sample'], String('string')],\n  basic: 'test'\n}\n\nconsole.log(typelike(testObject, templateObject)) // true\n```\n\n## How to compare with typelike\n**typelike** iterates as deeply as possible any arrays, objects, maps and sets, while taking into account \n[typelike Settings](#typelike-settings).\nFor type checking **typelike** uses \u003ca href=\"https://github.com/NicolaeIotu/xtypeof\" title=\"xtypeof\" target=\"_blank\"\u003e**xtypeof**\u003c/a\u003e \nwhich is included as part of the application.\n\nIn order to pass **typelike** tests the following logic applies:\n* for **arrays, objects and maps** tests pass if:\n  - keys are identical for both subject object and template object and ...\n  - the type of data corresponding to a key is identical for both subject object and template object.\n  - if the data corresponding to a key is iterable as understood by **typelike** (array, object, map, set) the checks\n    continue at the next deeper level\n* for **sets** tests pass if:\n  - the type of data corresponding to an entry is identical for both subject set and template set.\n  - if the data corresponding to an entry is iterable as understood by **typelike** (array, object, map, set) the checks \n    continue at the next deeper level\n* for any other type tests pass if:\n  - the type of subject data is identical for both subject object and template object\n\n## Using multiple templates with typelike\nMultiple templates can be used with every call to `typelike`. If the subject object (which should be the first\n parameter specified) matches any of them then `typelike` will return true.\n **Example:**\n```\nimport { typelike } from 'typelike'\n\nconst testObject = {\n  lvl1: { lvl2: [1, 2, 3], sm: 'type ... like' },\n  arr: [[1, 'xyz'], 'abcdef']\n}\n\nconst template1 = {\n  lvl1: {\n    lvl2: {\n      lvl3: {\n        lvl4: {\n          item1: [1, 2, 3],\n          item2: true\n        }\n      }\n    }\n  },\n  arr: [[1, 'xyz'], 'abcdef'],\n  basic: 'test'\n}\nconst template2 = {\n  lvl1: { sm: 'type ... like' },\n  arr: [[1], 'abcdef']\n}\nconst template3 = {\n  lvl1: { lvl2: [3, 4, 212], sm: '' },\n  arr: [[44, ''], '']\n}\n\nconsole.log(typelike(testObject, template1, template2)) // false\nconsole.log(typelike(testObject, template1, template2, template3)) // true\n```\n\n## typelike Settings\n**typelike** behavior can be changed with a couple of settings. In order to run with altered the settings, a special\n function `typelikeCustom` is exported. The settings are valid for a single call to `typelikeCustom`. Subsequent\n  calls to `typelike` will use the default settings as listed below.\n  \n`typelikeCustom` behaves in the same way as `typelike`, but expects that the last parameter passed to be a special\n setting object which takes the following default format/values:\n```\n{\n  maxDepth: 0,\n  properties: {\n    allowMissing: false,\n    allowNull: false\n  }\n}\n```\n* **maxDepth** indicates the maximum depth allowed for iterations. Defaults to `0` (unlimited depth levels)\n* **properties.allowMissing** takes a boolean value and indicates that the keys/properties are mandatory (`false`), or \n  not mandatory and can miss from arrays, objects, maps and sets (`true`). Defaults to `false` (all keys/properties are \n  mandatory)\n* **properties.allowNull** takes a boolean value and indicates that **null** value keys/properties of a target object,\n  match **any** corresponding types in the template object(s) (`true`). Defaults to `false` which means that **null** \n  value keys/properties of a target object match corresponding **null** value keys/properties of template object(s).\n\n**Example:**\n```\nimport { typelikeCustom } from 'typelike'\n\nconst testObject = {\n  lvl1: { sm: 'type ... like' },\n  arr: [[1], 'abcdef']\n}\n\nconst templateObject = {\n  lvl1: { lvl2: [3, 4, 212], sm: '' },\n  arr: [[44, ''], '']\n}\n\nconst settings = {\n  maxDepth: 3,\n  properties: {\n    allowMissing: true\n  }\n}\n\nconsole.log(typelikeCustom(testObject, templateObject, settings)) // true\n```\n\n## Others\n\n**typelike** is \u0026copy; Copyright 2020-2024 Nicolae Iotu, nicolae.g.iotu@gmail.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicolaeiotu%2Ftypelike","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnicolaeiotu%2Ftypelike","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicolaeiotu%2Ftypelike/lists"}