{"id":18396710,"url":"https://github.com/igorskyflyer/npm-common-types","last_synced_at":"2026-01-06T07:47:30.386Z","repository":{"id":249328865,"uuid":"831214888","full_name":"igorskyflyer/npm-common-types","owner":"igorskyflyer","description":"🔦 Provides frequently used types for your TypeScript projects. 🦄","archived":false,"fork":false,"pushed_at":"2025-08-28T20:55:47.000Z","size":135,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-29T01:27:36.212Z","etag":null,"topics":["back-end","common","generic","igorskyflyer","interface","javascript","js","node","promise","shared","trim","ts","types","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@igorskyflyer/common-types","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/igorskyflyer.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":"SUPPORT.md","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"ko_fi":"igorskyflyer"}},"created_at":"2024-07-20T00:12:31.000Z","updated_at":"2025-08-28T20:56:23.000Z","dependencies_parsed_at":"2024-07-24T16:47:30.561Z","dependency_job_id":"8c94b8c6-53dc-4c07-ab3a-ee246d4b7220","html_url":"https://github.com/igorskyflyer/npm-common-types","commit_stats":null,"previous_names":["igorskyflyer/npm-common-types"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/igorskyflyer/npm-common-types","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorskyflyer%2Fnpm-common-types","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorskyflyer%2Fnpm-common-types/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorskyflyer%2Fnpm-common-types/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorskyflyer%2Fnpm-common-types/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/igorskyflyer","download_url":"https://codeload.github.com/igorskyflyer/npm-common-types/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorskyflyer%2Fnpm-common-types/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28223435,"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","status":"online","status_checked_at":"2026-01-06T02:00:07.049Z","response_time":56,"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":["back-end","common","generic","igorskyflyer","interface","javascript","js","node","promise","shared","trim","ts","types","typescript"],"created_at":"2024-11-06T02:14:38.372Z","updated_at":"2026-01-06T07:47:30.380Z","avatar_url":"https://github.com/igorskyflyer.png","language":"TypeScript","funding_links":["https://ko-fi.com/igorskyflyer"],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/igorskyflyer/npm-common-types/main/media/common-types.png\" alt=\"Icon of Common Types\" width=\"256\" height=\"256\"\u003e\n  \u003ch1\u003eCommon Types\u003c/h1\u003e\n\u003c/div\u003e\n\n\u003cbr\u003e\n\n\u003ch4 align=\"center\"\u003e\n  🔦 Provides frequently used types for your TypeScript projects. 🦄\n\u003c/h4\u003e\n\n\u003cbr\u003e\n\u003cbr\u003e\n\n## 📃 Table of Contents\n\n- [Features](#-features)\n- [API](#-api)\n  - [KeysOf\\\u003cType\u003e](#keysoftype)\n  - [TypeOfValues\\\u003cType\u003e](#typeofvaluestype)\n  - [MethodsOf\\\u003cType\u003e](#methodsoftype)\n  - [PropertiesOf\\\u003cType\u003e](#propertiesoftype)\n  - [DeepPartial\\\u003cType\u003e](#deeppartialtype)\n  - [Promisable\\\u003cType\u003e](#promisabletype)\n  - [EnumKeys\\\u003cType, KeyType\u003e](#enumkeystype-keytype)\n  - [Func\u003cArgs, FnReturn\u003e](#funcargs-fnreturn)\n  - [Callback\u003cArgs, FnReturn\u003e](#callbackargs-fnreturn)\n  - [TrimLeft\\\u003cInput\u003e](#trimleftinput)\n  - [TrimRight\\\u003cInput\u003e](#trimrightinput)\n  - [Trim\\\u003cInput\u003e](#triminput)\n  - [IsGeneric\\\u003cType\u003e](#isgenerictype)\n  - [MethodSignature\\\u003cType, Method\u003e](#methodsignaturetype-method)\n  - [Override\\\u003cType, Changes\u003e](#overridetype-changes)\n  - [HasOverlap\\\u003cFirstType, SecondType\u003e](#hasoverlapfirsttype-secondtype)\n  - [Extend\\\u003cType, Changes\u003e](#extendtype-changes)\n  - [MethodName\\\u003cType, Method\u003e](#methodnametype-method)\n- [Usage](#-usage)\n- [API](#-api)\n- [Examples](#️-examples)\n- [Changelog](#-changelog)\n- [Support](#-support)\n- [License](#-license)\n- [Related](#-related)\n- [Author](#-author)\n\n\u003cbr\u003e\n\u003cbr\u003e\n\n## 🤖 Features\n\n- 🗝 Get all keys of a type with `KeysOf`\n- 📦 Extract all value types from top-level properties via `TypeOfValues`\n- 🔍 Identify only method keys using `MethodsOf`\n- 🧾 Identify only property keys using `PropertiesOf`\n- 🌿 Make every property (nested too) optional with `DeepPartial`\n- ⏳ Accept sync or async values using `Promisable`\n- 🎯 Find keys whose values match a specific type via `EnumKeys`\n- 🛠 Define generic function signatures with `Func` or `Callback`\n- ✂ Remove leading/trailing whitespace in string types with `TrimLeft`, `TrimRight`, `Trim`\n- ❓ Detect generic types using `IsGeneric`\n- 📜 Get a method’s exact signature with `MethodSignature`\n- 📝 Override existing keys with new types via `Override`\n- 🚫 Prevent extending with overlapping keys using `Extend`\n- 🔑 Validate a method exists and return its name with `MethodName`\n\n\u003cbr\u003e\n\u003cbr\u003e\n\n## 🕵🏼 Usage\n\nInstall it by executing any of the following, depending on your preferred package manager:\n\n```bash\npnpm add @igorskyflyer/common-types\n```\n\n```bash\nyarn add @igorskyflyer/common-types\n```\n\n```bash\nnpm i @igorskyflyer/common-types\n```\n\n\u003cbr\u003e\n\u003cbr\u003e\n\n## 🤹🏼 API\n\n### `KeysOf\u003cType\u003e`\n\nExtracts all keys from the type `Type`.\n\n\u003cbr\u003e\n\n\u003e 💡 **TIP**\n\u003e\n\u003e **CAN** be used with generics as well.\n\u003e\n\n\u003cbr\u003e\n\n`example.ts`\n```ts\ntype ArrayKeys = KeysOf\u003cArray\u003cstring\u003e\u003e // 'at' | 'concat' | 'copyWithin', etc.\n```\n\n---\n\n### `TypeOfValues\u003cType\u003e`\n\nExtracts all value types of the type `Type`. Works with top-level properties only.\n\n\u003cbr\u003e\n\n`IPerson.ts`\n```ts\ninterface IPerson {\n  firstName: string\n  lastName: string\n  zip: number\n  isMember: boolean\n}\n```\n\n\u003cbr\u003e\n\n`example.ts`\n```ts\ntype ValueTypes = TypeOfValues\u003cIPerson\u003e // string | number | boolean\n```\n\n---\n\n### `MethodsOf\u003cType\u003e`\n\nExtracts all methods from the type `Type`.\n\n\u003cbr\u003e\n\n\u003e 🛑 **CAUTION**\n\u003e\n\u003e Can **NOT** be used with generics.\n\u003e\n\n\u003cbr\u003e\n\n`example.ts`\n```ts\ntype NumberMethods = MethodsOf\u003cNumber\u003e // 'toString' | 'toFixed' | 'toExponential' | 'toPrecision' | 'valueOf' | 'toLocaleString'\n```\n\n---\n\n### `PropertiesOf\u003cType\u003e`\n\nExtracts all properties from the type `Type`.\n\n\u003cbr\u003e\n\n\u003e 🛑 **CAUTION**\n\u003e\n\u003e Can **NOT** be used with generics.\n\u003e\n\n\u003cbr\u003e\n\n`example.ts`\n```ts\ntype StringProperties = PropertiesOf\u003cString\u003e // 'length'\n```\n\n---\n\n### `DeepPartial\u003cType\u003e`\n\nConstructs a type with all top-level and nested properties of the type `Type` set to optional.\n\n\u003cbr\u003e\n\n\u003e 💡 **TIP**\n\u003e\n\u003e See also TypeScript's built-in utility type [`Partial\u003cType\u003e`](https://www.typescriptlang.org/docs/handbook/utility-types.html#partialtype) ![An external link](https://raw.githubusercontent.com/igorskyflyer/igorskyflyer/main/assets/external.svg).\n\u003e\n\n\u003cbr\u003e\n\n`IPerson.ts`\n```ts\ninterface IPerson {\n  name: string\n  address: {\n    city: string\n    zip: number\n  }\n}\n```\n\n\u003cbr\u003e\n\n`example.ts`\n```ts\ntype PersonOptional = DeepPartial\u003cIPerson\u003e\n\n/**\n * PersonOptional:\n *  {\n *    name?: string\n *    address?: {\n *      city?: string\n *      zip?: number\n *    }\n *  }\n */\n```\n\n---\n\n### `Promisable\u003cType\u003e`\n\nProvides a convenient way to allow flexibility in handling values that could either be immediate or asynchronously resolved.\n\n\u003cbr\u003e\n\n`example.ts`\n```ts\nconst immediateValue: number = 42\nconst promiseValue: Promisable\u003cnumber\u003e = Promise.resolve(42)\n\nasync function handleValue(value: Promisable\u003cnumber\u003e) {\n  const result = await processValue(value)\n  console.log(result) // Will log the number 42, whether value was a direct number or a Promise resolving to 42\n}\n\nhandleValue(immediateValue)\nhandleValue(promiseValue)\n```\n\n---\n\n### `EnumKeys\u003cType, KeyType\u003e`\n\nExtracts all keys from the `Type` that are of the type `KeyType`.\n\n\u003cbr\u003e\n\n`IConfig`\n```ts\ninterface IConfig {\n  apiUrl: string\n  timeout: number\n  isEnabled: boolean\n  retryAttempts: number\n}\n```\n\n\u003cbr\u003e\n\n`example.ts`\n```ts\ntype ConfigNumbers = EnumKeys\u003cIConfig, number\u003e // 'timeout' | 'retryAttempts'\n```\n\n---\n\n### `Func\u003cArgs, FnReturn\u003e`\n\nConstructs a generic `Function`-*like* type with the arguments of type `Args` and the return value of type `FnReturn`.\n\n\u003cbr\u003e\n\n`example.ts`\n```ts\nfunction process(items: number[], callback: Func\u003cnumber, boolean\u003e): boolean {\n  // shortened for brevity\n  // do NOT access your Array immediately :)\n  for (let i = 0; i \u003c items.length; i++) {\n    if (callback(items[i])) {\n      return true\n    }\n  }\n\n  return false\n}\n\nprocess([1, 1, 8, 1], (item) =\u003e {\n  if (item % 2 === 0) {\n    return true\n  }\n\n  return false\n}) // returns true\n```\n\n---\n\n### `Callback\u003cArgs, FnReturn\u003e`\n\nAlias of [`Func\u003cArgs, FnReturn\u003e`](#funcargs-fnreturn).\n\n---\n\n### `TrimLeft\u003cInput\u003e`\n\nRecursively removes all leading whitespace from the `String` type `Input`.\n\n\u003cbr\u003e\n\n`example.ts`\n```ts\ntype Id = '    ID'\ntype ProperId = TrimLeft\u003cId\u003e\n\nconst id: ProperId = '   ID' // ERROR: does NOT accept leading whitespace\n```\n---\n\n### `TrimRight\u003cInput\u003e`\n\nRecursively removes all trailing whitespace from the `String` type `Input`.\n\n\u003cbr\u003e\n\n`example.ts`\n```ts\ntype Id = 'ID     '\ntype ProperId = TrimRight\u003cId\u003e\n\nconst id: ProperId = 'ID    ' // ERROR: does NOT accept leading whitespace\n```\n---\n\n### `Trim\u003cInput\u003e`\n\nRecursively removes all leading and trailing whitespace from the `String` type `Input`.\n\n\u003cbr\u003e\n\n`example.ts`\n```ts\ntype Id = '    ID     '\ntype ProperId = Trim\u003cId\u003e\n\nconst id: ProperId = '   ID    ' // ERROR: does NOT accept leading nor trailing whitespace\n```\n\n\u003cbr\u003e\n\n\u003e 💡 **TIP**\n\u003e\n\u003e A very cool usage of the [`Trim\u003cInput\u003e`](#triminput) type is implemented in the [`magic-querySelector`](https://github.com/igorskyflyer/npm-magic-queryselector) project.\n\u003e\n\n---\n\n### `IsGeneric\u003cType\u003e`\n\nReturns a Boolean whether the type `Type` is a generic.\n\n\u003cbr\u003e\n\n`example.ts`\n```ts\ntype ArrayIsGeneric = IsGeneric\u003cArray\u003cstring\u003e\u003e // true\ntype NumberIsGeneric = IsGeneric\u003cnumber\u003e // false\n```\n---\n\n### `MethodSignature\u003cType, Method\u003e`\n\nGets the method signature `Method` of the type `Type`.\n\n\u003cbr\u003e\n\n`example.ts`\n```ts\ntype NumberToFixedMethod = MethodSignature\u003cNumber, 'toFixed'\u003e // expects (fractionDigits?: number) =\u003e string\n```\n\n---\n\n### `Override\u003cType, Changes\u003e`\n\nOverrides the type `Type` with the new type of `Changes`.\n\n\u003cbr\u003e\n\n`IPerson`\n```ts\ninterface IPerson {\n  name: string\n  children: boolean\n}\n```\n\n\u003cbr\u003e\n\n`example.ts`\n```ts\nconst person: IPerson = {\n  name:'John Doe',\n  children: true\n}\n\ntype NewPerson = Override\u003cIPerson, { children: number }\u003e //only accepts existing keys\n\nconst newPerson: NewPerson = {\n  name:'John Doe',\n  children: 2\n}\n```\n\n---\n\n### `HasOverlap\u003cFirstType, SecondType\u003e`\n\nChecks whether the types `FirstType` and `SecondType` overlap, i.e. have the same keys.\n\n\u003cbr\u003e\n\n\u003e ⚠️ **WARNING**\n\u003e\n\u003e It only checks the key names, **NOT** their **TYPES**!\n\u003e\n\n\u003cbr\u003e\n\n`IPerson`\n```ts\ninterface IPerson {\n  name: string\n  children: boolean\n}\n```\n\n\u003cbr\u003e\n\n`example.ts`\n```ts\ntype PersonOverlap = HasOverlap\u003c\n  IPerson,\n  {\n    name: string\n    children: boolean\n  }\n\u003e // returns true\n```\n---\n\n### `Extend\u003cType, Changes\u003e`\n\nExtends the type `Type` with the new type of `Changes` with only non-existent keys in type `Type`.\n\n\u003cbr\u003e\n\n`IPerson`\n```ts\ninterface IPerson {\n  name: string\n  children: number\n}\n```\n\n\u003cbr\u003e\n\n`example.ts`\n```ts\ntype NewPerson = Extend\u003cIPerson, { name: string }\u003e //only accepts non-existing keys\n// will return `never` here\nconst newPerson: NewPerson = {\n  name: 'John Doe',\n  children: 2\n} // will error\n\ntype NewestPerson = Extend\u003cIPerson, { profession: string }\u003e //only accepts non-existing keys\nconst newestPerson: NewestPerson = {\n  name: 'John Doe',\n  children: 2,\n  profession: 'Developer'\n} // will NOT error\n```\n\n---\n\n### `MethodName\u003cType, Method\u003e`\n\nChecks for the existence of the method `Method` in the type of `Type` and returns it if found.\n\n\u003cbr\u003e\n\n`example.ts`\n```ts\ntype NumberToFixedMethod = MethodName\u003cNumber, 'toFixed'\u003e // toFixed\n```\n\n---\n\n## 🗒️ Examples\n\n`utils.ts`\n```ts\nimport type { Callback } from '@igorskyflyer/common-types'\n\nfunction process(\n  items: number[],\n  callback: Callback\u003cnumber, boolean\u003e\n): boolean {\n  // shortened for brevity\n  // do NOT access your Array immediately :)\n  for (let i = 0; i \u003c items.length; i++) {\n    if (callback(items[i])) {\n      return true\n    }\n  }\n\n  return false\n}\n\nconst result = process([1, 1, 8, 1], (item) =\u003e {\n  if (item % 2 === 0) {\n    return true\n  }\n\n  return false\n}) // returns true\n\nconsole.log(result)\n\n```\n\n\u003cbr\u003e\n\u003cbr\u003e\n\n## 📝 Changelog\n\n📑 The changelog is available here, [CHANGELOG.md](https://github.com/igorskyflyer/npm-common-types/blob/main/CHANGELOG.md).\n\n\u003cbr\u003e\n\u003cbr\u003e\n\n## 🪪 License\n\nLicensed under the MIT license which is available here, [MIT license](https://github.com/igorskyflyer/npm-common-types/blob/main/LICENSE).\n\n\u003cbr\u003e\n\u003cbr\u003e\n\n## 💖 Support\n\n\u003cdiv align=\"center\"\u003e\n  I work hard for every project, including this one and your support means a lot to me!\n  \u003cbr\u003e\n  Consider buying me a coffee. ☕\n  \u003cbr\u003e\n  \u003cbr\u003e\n  \u003ca href=\"https://ko-fi.com/igorskyflyer\" target=\"_blank\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/igorskyflyer/igorskyflyer/main/assets/ko-fi.png\" alt=\"Donate to igorskyflyer\" width=\"180\" height=\"46\"\u003e\u003c/a\u003e\n  \u003cbr\u003e\n  \u003cbr\u003e\n  \u003cem\u003eThank you for supporting my efforts!\u003c/em\u003e 🙏😊\n\u003c/div\u003e\n\n\u003cbr\u003e\n\u003cbr\u003e\n\n## 🧬 Related\n\n[@igorskyflyer/windev](https://www.npmjs.com/package/@igorskyflyer/windev)\n\n\u003e _🍃 Provides ways of checking whether a path is a legacy Windows device. 💾_\n\n\u003cbr\u003e\n\n[@igorskyflyer/magic-queryselector](https://www.npmjs.com/package/@igorskyflyer/magic-queryselector)\n\n\u003e _🪄 A TypeScript-types patch for querySelector/querySelectorAll, make them return types you expect them to! 🔮_\n\n\u003cbr\u003e\n\n[@igorskyflyer/jmap](https://www.npmjs.com/package/@igorskyflyer/jmap)\n\n\u003e _🕶️ Reads a JSON file into a Map. 🌻_\n\n\u003cbr\u003e\n\n[@igorskyflyer/clone](https://www.npmjs.com/package/@igorskyflyer/clone)\n\n\u003e _🧬 A lightweight JavaScript utility allowing deep copy-by-value of nested objects, arrays and arrays of objects. 🪁_\n\n\u003cbr\u003e\n\n[@igorskyflyer/extendable-string](https://www.npmjs.com/package/@igorskyflyer/extendable-string)\n\n\u003e _🦀 ExtendableString allows you to create strings on steroids that have custom transformations applied to them, unlike common, plain strings.. 🪀_\n\n\u003cbr\u003e\n\u003cbr\u003e\n\u003cbr\u003e\n\n## 👨🏻‍💻 Author\nCreated by **Igor Dimitrijević** ([*@igorskyflyer*](https://github.com/igorskyflyer/)).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figorskyflyer%2Fnpm-common-types","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Figorskyflyer%2Fnpm-common-types","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figorskyflyer%2Fnpm-common-types/lists"}