{"id":28248662,"url":"https://github.com/lexriver/data-types","last_synced_at":"2026-02-18T00:03:15.671Z","repository":{"id":57126865,"uuid":"297113878","full_name":"LexRiver/data-types","owner":"LexRiver","description":null,"archived":false,"fork":false,"pushed_at":"2024-12-22T11:26:04.000Z","size":69,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-02T05:29:10.444Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LexRiver.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null}},"created_at":"2020-09-20T16:11:43.000Z","updated_at":"2024-12-22T11:26:07.000Z","dependencies_parsed_at":"2024-12-09T18:31:20.383Z","dependency_job_id":"2dcd8f62-396a-4ed2-88cd-35a97dba2157","html_url":"https://github.com/LexRiver/data-types","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/LexRiver/data-types","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LexRiver%2Fdata-types","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LexRiver%2Fdata-types/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LexRiver%2Fdata-types/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LexRiver%2Fdata-types/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LexRiver","download_url":"https://codeload.github.com/LexRiver/data-types/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LexRiver%2Fdata-types/sbom","scorecard":{"id":83877,"data":{"date":"2025-08-11","repo":{"name":"github.com/LexRiver/data-types","commit":"8d107d094d43e64dff2dee0bf03d50c55a00c046"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":1.3,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":0,"reason":"Found 0/21 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":0,"reason":"license file not detected","details":["Warn: project does not have a license file"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":0,"reason":"11 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-67mh-4wv8-2f99","Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55","Warn: Project is vulnerable to: GHSA-vg6x-rcgg-rjx6","Warn: Project is vulnerable to: GHSA-x574-m823-4x7w","Warn: Project is vulnerable to: GHSA-4r4m-qw57-chr8","Warn: Project is vulnerable to: GHSA-xcj6-pq6g-qj4x","Warn: Project is vulnerable to: GHSA-356w-63v5-8wf4","Warn: Project is vulnerable to: GHSA-859w-5945-r5v3","Warn: Project is vulnerable to: GHSA-9crc-q9x8-hgqq"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-15T06:30:31.549Z","repository_id":57126865,"created_at":"2025-08-15T06:30:31.549Z","updated_at":"2025-08-15T06:30:31.549Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279009508,"owners_count":26084609,"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":"2025-10-11T02:00:06.511Z","response_time":55,"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":[],"created_at":"2025-05-19T12:16:43.950Z","updated_at":"2026-02-18T00:03:15.663Z","avatar_url":"https://github.com/LexRiver.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DataTypes\n\nPackage for checking type of a variable\n\n## Install\n\n```\nnpm install @lexriver/data-types\n```\n\n## Import\n```typescript\nimport {DataTypes} from '@lexriver/data-types'\n```\n\n\n## Usage\n\n\n### DataTypes.isFunction(x:any):boolean\n\nCheck if variable is a function\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n### DataTypes.isClass(x:any):boolean\n\nCheck if variable is a class\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n### DataTypes.isClassInstance(classInstance:any, className:any):boolean\n\nCheck if variable is instance of a class, internally the same as ```classInstance instanceof className```\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n### DataTypes.isDate(date: any): boolean\n\nCheck if variable is instance of ```Date```\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n### DataTypes.isObject(o: any): boolean \n\nCheck if variable is object\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n### DataTypes.isObjectWithKeys(o:any): boolean \n\nCheck if variable is object with keys\n\n```typescript\nDataTypes.isObjectWithKeys({a:'a'}) // true\nDataTypes.isObjectWithKeys({}) // false\nDataTypes.isObjectWithKeys('some string') // false\n```\n\n### DataTypes.isString(x: any): boolean\n\nCheck if variable is a string\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n### DataTypes.isNumber(x: any): boolean\n\nCheck if variable is a number\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n### DataTypes.isNullOrUndefined(x: any): boolean \n\nCheck if variable is null or undefined\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n### DataTypes.isBoolean(x: any): boolean \n\nCheck if variable is a boolean\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n### DataTypes.isArray(x: any): boolean\n\nCheck if variable is array\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n### DataTypes.isPrimitive(x: any): boolean\n\nCheck if variable is ```undefined``` or ```null``` or ```boolean``` or ```string``` or ```symbol```\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n### DataTypes.isEqual(x: any, y: any): boolean\n\nCheck if two variables are the same\n\n```typescript\nDataTypes.isEqual(1, 1) // true\n```\n\n```typescript\nDataTypes.isEqual(1, '1') // false\n```\n\n```typescript\nDataTypes.isEqual('a', 'a') // true\n```\n\n```typescript\nDataTypes.isEqual('a', '1') // false\n```\n\n```typescript\nDataTypes.isEqual(1.11, 1.11) // true\n```\n\n```typescript\nDataTypes.isEqual(new Date('2019-11-12'), new Date('2019-11-12')) // true\nDataTypes.isEqual(new Date('2019-11-12'), new Date('2019-11-13')) // false\n```\n\n```typescript\nconst x = new Date()\nconst y = x\nDataTypes.isEqual(x, y) // true\n```\n\n```typescript\nDataTypes.isEqual(\n    [1,'1',new Date('2019-11-12')],\n    [1,'1',new Date('2019-11-12')]\n) //true\n```\n\n\n\n```typescript\nDataTypes.isEqual(\n    [1,'1',new Date('2019-11-12'), 1],\n    [1,'1',new Date('2019-11-12')]\n) //false\n```\n\n```typescript\nDataTypes.isEqual(\n    [1,'1',new Date('2019-11-12')],\n    [1,'1',new Date('2019-11-12')]\n) //true\n```\n\n```typescript\nDataTypes.isEqual(\n    {a:'aa', b:'bb'},\n    {b: 'bb', a: 'aa'}\n) //true\n```\n\n```typescript\nDataTypes.isEqual(\n    {a:'aa', b:'bb'},\n    {a: 'aa', b:1}\n) //false\n```\n\n```typescript\n    const x = {\n        a:'aa', \n        b:'bb', \n        c: new Date('2019-11-12'), \n        d: [\n            1,\n            2,\n            '3tt', \n            new Date('2019-11-13'), \n            {\n                a: 'aa', \n                b: {\n                    bb:'bb', \n                    dd:'dd'\n                }\n            }\n        ],\n        e: {\n            a:'aaa', \n            b: {\n                bb:'bb',\n                dd: new Date('2019-11-13'),\n                ee: 123\n            }\n        }\n    }\n    const y = {\n        a:'aa', \n        b:'bb', \n        c: new Date('2019-11-12'), \n        d: [\n            1,\n            2,\n            '3tt', \n            new Date('2019-11-13'), \n            {\n                a: 'aa', \n                b: {\n                    bb:'bb', \n                    dd:'dd'\n                }\n            }\n        ],\n        e: {\n            a:'aaa', \n            b: {\n                bb:'bb',\n                dd: new Date('2019-11-13'),\n                ee: 123\n            }\n        }\n    }\n    DataTypes.isEqual(x,y) // true\n```\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n### DataTypes.isObjectContainsObject(p:{bigObject:Object, smallObject:Object, ignoreCaseInStringValues?:boolean, ignoreEmptySmallObject?:boolean}):boolean\n\nCheck if object contains another object\n\n__Parameters__\n* `bigObject:Object` - big object to check \n* `smallObject:Object` - small object\n* `ignoreCaseInStringValues?:boolean` - ignore case for strings when compare\n* `ignoreEmptySmallObject?:boolean` - if true the function returns false if small object is empty\n\n__Examples__\n\n```typescript\nDataTypes.isObjectContainsObject({\n    bigObject: {a:'a', b:true, c:3, d:false}, \n    smallObject: {a:'a', b:true, c:3}\n}) // true\n```\n\n```typescript\nDataTypes.isObjectContainsObject({\n    bigObject: {a:'a', b:{b1:'b1', b2:'b2'}, c:'c', d:new Date(2019,12,10)}, \n    smallObject: {a:'a', b:{b1:'b1'}, d:new Date(2019,12,10)}\n}) // true\n```\n\n```typescript\nDataTypes.isObjectContainsObject({\n    bigObject: {a:'a', b:{b1:'b1', b2:'b2'}, c:'c'}, \n    smallObject: {}\n}) // true\n\nDataTypes.isObjectContainsObject({\n    bigObject: {a:'a', b:{b1:'b1', b2:'b2'}, c:'c'}, \n    smallObject: {},\n    ignoreEmptySmallObject: true\n}) // false\n```\n\n```typescript\nDataTypes.isObjectContainsObject({ \n    bigObject: {a:'aaa', b:'b', d:new Date(2019,10,11)}, \n    smallObject: {a: 'AAA'}, \n    ignoreCaseInStringValues: true\n}) //true\n\nDataTypes.isObjectContainsObject({ \n    bigObject: {a:'aaa', b:'b', d:new Date(2019,10,11)}, \n    smallObject: {a: 'AAA'}, \n    ignoreCaseInStringValues: false\n}) //false\n```\n\n```typescript\nDataTypes.isObjectContainsObject({\n    bigObject: {date:new Date(2019,10,11)},\n    smallObject: {date:new Date(2019,10,10)}\n}) // false\n\nDataTypes.isObjectContainsObject({\n    bigObject: {date:new Date(2019,10,11)},\n    smallObject: {date:new Date(2019,10,11)}\n}) // true\n\n```\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n### DataTypes.filterObjectByKeys(o: any, keysToCopy: (key: string) =\u003e boolean, recursive?: boolean): object \n\nReturns a new object only with keys specified by predicate function\n\n__Parameters__\n* `o: any` - object to filter\n* `keysToCopy: (key: string) =\u003e boolean` - function to check each property for object\n* `recursive?: boolean` - if true, then perform a deep clone with filter\n\n\n__Example__\n```typescript\n    const date = new Date()\n    const input = {\n        a: 'a',\n        b: 'b',\n        _c: '_c',\n        _d: 'd',\n        e: {\n            e1: 'e1',\n            _e2: '_e2'\n        },\n        f: [\n            { f1: 'f1' },\n            { _f2: 'f2' }\n        ],\n        g: date,\n        _h: date,\n        i: 34,\n        _j: 45\n    }\n    const output = DataTypes.filterObjectByKeys(input, k =\u003e k[0] !== '_', true)\n/*\n    output = {\n        a: 'a',\n        b: 'b',\n        e: {\n            e1: 'e1',\n        },\n        f: [\n            { f1: 'f1' },\n            {}\n        ],\n        g: date,\n        i: 34\n    }\n*/    \n```\n\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n### DataTypes.isValueExistsInEnum(value:any, EnumType:any): boolean\n\nCheck if value exists in enum\n\n```typescript\nenum EnumForTest{\n    First = 'first',\n    Second = 'second'\n}\n\nDataTypes.isValueExistsInEnum(EnumForTest.First, EnumForTest) // true\nDataTypes.isValueExistsInEnum('first', EnumForTest) // true\nDataTypes.isValueExistsInEnum('First', EnumForTest) // false\n\nenum EnumForTestNumber{\n    First, // =0\n    Second // =1\n}\n\nDataTypes.isValueExistsInEnum(1, EnumForTestNumber) // true\nDataTypes.isValueExistsInEnum(100, EnumForTestNumber) // false\nDataTypes.isValueExistsInEnum(undefined, EnumForTestNumber) // false\n```\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n\n### DataTypes.hasProperty(obj: T, key: string): boolean\n\nType-safe check if object has property\n\n```typescript\ntype TypeA = {a:string}\ntype TypeB = {b:string}\n\nfunction func(param1:TypeA|TypeB){\n    if('c' in param1){ // no compilation error\n        //...\n    }    \n\n    if(DataTypes.hasProperty(param1, 'c')){ // compilation error \n        //...\n    }\n}\n```\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n### DataTypes.hasDefinedProperty(obj: T, key: K): boolean\n\nType-safe check if object has property and the property value is not `undefined`. This function performs type narrowing and returns `true` if the property exists and is not `undefined`. Note that `null` values will return `true`.\n\n__Parameters__\n* `obj: T` - object to check\n* `key: K` - property key to check (must be a valid key of the union type)\n\n__Returns__\n* `boolean` - `true` if property exists and is not `undefined`, `false` otherwise\n\n__Examples__\n\n```typescript\ntype TypeA = {a: string, b?: number}\ntype TypeB = {c: string}\n\nconst obj: TypeA | TypeB = {a: 'test', b: 42}\n\nif (DataTypes.hasDefinedProperty(obj, 'a')) {\n    // TypeScript knows obj has property 'a' here\n    console.log(obj.a) // OK\n}\n\n```\n\n```typescript\nconst obj = {a: 'test', b: undefined, c: null}\n\nDataTypes.hasDefinedProperty(obj, 'a') // true\nDataTypes.hasDefinedProperty(obj, 'b') // false (undefined)\nDataTypes.hasDefinedProperty(obj, 'c') // true (null is not undefined)\n```\n\n```typescript\nconst obj = {a: 0, b: '', c: false}\n\nDataTypes.hasDefinedProperty(obj, 'a') // true (0 is defined)\nDataTypes.hasDefinedProperty(obj, 'b') // true (empty string is defined)\nDataTypes.hasDefinedProperty(obj, 'c') // true (false is defined)\n```\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n### DataTypes.hasDefinedPropertyAndValue(obj: T, key: K): boolean\n\nType-safe check if object has property and the property value is not `undefined` and not `null`. This is stricter than `hasDefinedProperty` as it also excludes `null` values.\n\n__Parameters__\n* `obj: T` - object to check\n* `key: K` - property key to check (must be a valid key of the union type)\n\n__Returns__\n* `boolean` - `true` if property exists and is neither `undefined` nor `null`, `false` otherwise\n\n__Examples__\n\n```typescript\ntype TypeA = {a: string, b?: number | null}\ntype TypeB = {c: string}\n\nconst obj: TypeA | TypeB = {a: 'test', b: 42}\n\nif (DataTypes.hasDefinedPropertyAndValue(obj, 'a')) {\n    // TypeScript knows obj has property 'a' with a value here\n    console.log(obj.a) // OK\n}\n```\n\n```typescript\nconst obj = {a: 'test', b: undefined, c: null}\n\nDataTypes.hasDefinedPropertyAndValue(obj, 'a') // true\nDataTypes.hasDefinedPropertyAndValue(obj, 'b') // false (undefined)\nDataTypes.hasDefinedPropertyAndValue(obj, 'c') // false (null)\n```\n\n```typescript\nconst obj = {a: 0, b: '', c: false}\n\nDataTypes.hasDefinedPropertyAndValue(obj, 'a') // true (0 is a value)\nDataTypes.hasDefinedPropertyAndValue(obj, 'b') // true (empty string is a value)\nDataTypes.hasDefinedPropertyAndValue(obj, 'c') // true (false is a value)\n```\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n### type AnyJsonValue\n\nRepresents any json value\n\n```typescript\nexport type AnyJsonValue =\n    | string\n    | number\n    | boolean\n    | null\n    | Date\n    | { readonly [K in string]: AnyJsonValue }\n    | Array\u003cAnyJsonValue\u003e\n    | undefined\n```\n\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n### DataTypes.isValidJsonObject(json: any):json is AnyJsonValue\n\nCheck if parameter is valid json object\n\n```typescript\n    const x = {\n        a: 'a',\n        b: 'b',\n        c: {\n            c1:'c1',\n            c2: 23234,\n            c3: new Date()\n        },\n        d:[\n            'd1', 'd2', 'd3'\n        ]\n    }\n    DataTypes.isValidJsonObject(x) // true\n```\n\n```typescript\n    class MyClass{\n        constructor(public a:string){\n        }\n    }\n\n    const x = new MyClass('x')\n\n    DataTypes.isValidJsonObject({a:x}) // false\n```\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n### DataTypes.toJson(o:any)\n\nConvert any object to valid json object via JSON.parse(JSON.stringify(o))\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n### type JsonType\\\u003cT\\\u003e\n\nRepresents JSON type to use as parameter for function\n\n__Example__\n```typescript\nfunction expectingJsonType\u003cT\u003e(x:JsonType\u003cT\u003e){\n    // here we can be sure that parameter is valid json object\n    return JSON.stringify(json) // or save to database, etc\n}\n\ntype Person = {\n    name:string\n}\ntype NonJsonType = {\n    fn: ()=\u003evoid\n}\n\nconst person:Person = {\n    name: 'John'\n}\n\nexpectingJsonType(person) // ok\n\nconst nonJson:NonJsonType = {\n    fn: ()=\u003e{}\n}\n\nexpectingJsonType(nonJson) // compilation error\n\n```\n\n### type JsonCompatible\\\u003cT\\\u003e\n\nType `JsonCompatible` is a type that can be safely converted to JSON. This type sometimes works better than `JsonType\u003cT\u003e`, for example with interfaces.\n\n```typescript\n\n    function expectingJsonCompatible\u003cT extends JsonCompatible\u003cT\u003e\u003e(data: T){\n        console.log(JSON.stringify(data))\n    }\n\n    interface User {\n        name:string\n    }\n    let user:User = {name:'a'}\n    expectingJsonCompatible(user)\n    expectingJsonType(user) // compile error (!)\n\n    interface UserNonJson {\n        name:string\n        fn:()=\u003evoid\n    }\n    let userNonJson:UserNonJson = {name:'a', fn:()=\u003e{}}\n    expectingJsonCompatible(userNonJson) // compile error\n    expectingJsonType(userNonJson) // compile error\n\n\n```\n\n### type PartiallyPartial\u003cT, K extends keyof T\u003e\n\nMake selected fields optional while keeping all other fields unchanged.\n\n```typescript\ntype User = {\n    id: string\n    email: string\n    password: string\n}\n\ntype UserWithOptionalEmailAndPassword = PartiallyPartial\u003cUser, 'email' | 'password'\u003e\n/*\n    Equivalent to:\n    {\n        id: string;              // unchanged (still required)\n        email?: string | undefined;\n        password?: string | undefined;\n    }\n*/\n```\n\n__Use cases__\n* Making a subset of fields optional in update payloads while keeping identifiers required.\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n### type SomeOptional\u003cT, K extends keyof T\u003e\n\nAlias for `PartiallyPartial\u003cT, K\u003e`. Make selected fields optional while keeping the rest of the object unchanged.\n\n```typescript\ntype User = {\n    id: string\n    email: string\n    username: string\n}\n\ntype UserWithSomeOptional = SomeOptional\u003cUser, 'email' | 'username'\u003e\n/*\n    Equivalent to:\n    {\n        id: string;              // unchanged (still required)\n        email?: string | undefined;\n        username?: string | undefined;\n    }\n*/\n```\n\n__Use cases__\n* Optionalizing only the fields you pass in (e.g., partial updates, patch payloads).\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n### type PartialExcept\u003cT, K extends keyof T\u003e\n\nMake all fields optional except a specified subset which remain required.\n\n```typescript\ntype User = {\n    id: string\n    email?: string\n    username?: string\n}\n\ntype Payload = PartialExcept\u003cUser, 'id'\u003e\n/*\n    Equivalent to:\n    {\n        id: string;              // required\n        email?: string | undefined;\n        username?: string | undefined;\n    }\n*/\n```\n\n__Use cases__\n* Defining payloads where an identifier must be present but other fields are optional.\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n### type SomeRequired\u003cT, K extends keyof T\u003e\n\nAlias for `PartialExcept\u003cT, K\u003e`. Make all fields optional except the specified keys, which are required.\n\n```typescript\ntype User = {\n    id: string\n    email?: string\n    username?: string\n}\n\ntype Payload2 = SomeRequired\u003cUser, 'id' | 'email'\u003e\n/*\n    Equivalent to:\n    {\n        id: string;              // required\n        email: string;           // required\n        username?: string | undefined;\n    }\n*/\n```\n\n__Use cases__\n* Ensuring certain fields are present while relaxing the rest.\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n### type AtLeastOne\u003cT, K extends keyof T\u003e\n\nRequire that at least one of the specified keys is present. Useful for filters or input where multiple alternative identifiers are allowed.\n\n```typescript\ntype User = {\n    id: string\n    email: string\n    username: string\n}\n\ntype UserLookup = AtLeastOne\u003cUser, 'id' | 'email' | 'username'\u003e\n\nfunction findUser(query: UserLookup){\n    // query must contain at least one of: id, email, username\n}\n\nfindUser({ id: '123' }) // OK\nfindUser({ email: 'a@b.com' }) // OK\nfindUser({}) // compile error\n```\n\n__Notes__\n* Other non-listed fields are optional in the resulting type, but at least one of `K` must be present.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flexriver%2Fdata-types","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flexriver%2Fdata-types","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flexriver%2Fdata-types/lists"}