@pro-functional/objects
Advanced tools
| export declare const makeEnumResolver: <T extends string>(record: Record<string, T>, fallback: T) => (value: string) => T; |
@@ -1,2 +0,2 @@ | ||
| "use strict";var s=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var u=(n,o)=>{for(var t in o)s(n,t,{get:o[t],enumerable:!0})},w=(n,o,t,i)=>{if(o&&typeof o=="object"||typeof o=="function")for(let e of k(o))!p.call(n,e)&&e!==t&&s(n,e,{get:()=>o[e],enumerable:!(i=c(o,e))||i.enumerable});return n};var x=n=>w(s({},"__esModule",{value:!0}),n);var j={};u(j,{isObject:()=>r,isObjectWithProps:()=>b});module.exports=x(j);var r=n=>typeof n=="object"&&!!n,b=(n,...o)=>r(n)&&o.every(t=>t in n); | ||
| "use strict";var s=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var u=(n,e)=>{for(var t in e)s(n,t,{get:e[t],enumerable:!0})},x=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of p(e))!g.call(n,o)&&o!==t&&s(n,o,{get:()=>e[o],enumerable:!(r=c(e,o))||r.enumerable});return n};var k=n=>x(s({},"__esModule",{value:!0}),n);var a={};u(a,{isObject:()=>i,isObjectWithProps:()=>w,makeEnumResolver:()=>v});module.exports=k(a);var v=(n,e)=>t=>new Map(Object.values(n).map(o=>[o.toString(),o])).get(t)||e;var i=n=>typeof n=="object"&&!!n,w=(n,...e)=>i(n)&&e.every(t=>t in n); | ||
| //# sourceMappingURL=index.js.map |
| { | ||
| "version": 3, | ||
| "sources": ["../../src/index.ts", "../../src/objects.ts"], | ||
| "sourcesContent": ["export * from './objects'\n", "export const isObject = (value?: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && !!value\n\nexport const isObjectWithProps = <K extends string>(\n value?: unknown,\n ...props: K[]\n): value is { [k in K]: unknown } =>\n isObject(value) && props.every((prop) => prop in value)\n"], | ||
| "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,cAAAE,EAAA,sBAAAC,IAAA,eAAAC,EAAAJ,GCAO,IAAMK,EAAYC,GACrB,OAAOA,GAAU,UAAY,CAAC,CAACA,EAEtBC,EAAoB,CAC7BD,KACGE,IAEHH,EAASC,CAAK,GAAKE,EAAM,MAAOC,GAASA,KAAQH,CAAK", | ||
| "names": ["index_exports", "__export", "isObject", "isObjectWithProps", "__toCommonJS", "isObject", "value", "isObjectWithProps", "props", "prop"] | ||
| "sources": ["../../src/index.ts", "../../src/enum.ts", "../../src/objects.ts"], | ||
| "sourcesContent": ["export * from './enum'\nexport * from './objects'\n", "export const makeEnumResolver =\n <T extends string>(record: Record<string, T>, fallback: T) =>\n (value: string) => {\n const resolver = new Map(\n Object.values(record).map((item) => [item.toString(), item])\n )\n\n return resolver.get(value) || fallback\n }\n", "export const isObject = (value?: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && !!value\n\nexport const isObjectWithProps = <K extends string>(\n value?: unknown,\n ...props: K[]\n): value is { [k in K]: unknown } =>\n isObject(value) && props.every((prop) => prop in value)\n"], | ||
| "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,cAAAE,EAAA,sBAAAC,EAAA,qBAAAC,IAAA,eAAAC,EAAAL,GCAO,IAAMM,EACT,CAAmBC,EAA2BC,IAC7CC,GACoB,IAAI,IACjB,OAAO,OAAOF,CAAM,EAAE,IAAKG,GAAS,CAACA,EAAK,SAAS,EAAGA,CAAI,CAAC,CAC/D,EAEgB,IAAID,CAAK,GAAKD,ECP/B,IAAMG,EAAYC,GACrB,OAAOA,GAAU,UAAY,CAAC,CAACA,EAEtBC,EAAoB,CAC7BD,KACGE,IAEHH,EAASC,CAAK,GAAKE,EAAM,MAAOC,GAASA,KAAQH,CAAK", | ||
| "names": ["index_exports", "__export", "isObject", "isObjectWithProps", "makeEnumResolver", "__toCommonJS", "makeEnumResolver", "record", "fallback", "value", "item", "isObject", "value", "isObjectWithProps", "props", "prop"] | ||
| } |
@@ -1,2 +0,2 @@ | ||
| var e=n=>typeof n=="object"&&!!n,s=(n,...o)=>e(n)&&o.every(t=>t in n);export{e as isObject,s as isObjectWithProps}; | ||
| var i=(n,e)=>t=>new Map(Object.values(n).map(o=>[o.toString(),o])).get(t)||e;var r=n=>typeof n=="object"&&!!n,p=(n,...e)=>r(n)&&e.every(t=>t in n);export{r as isObject,p as isObjectWithProps,i as makeEnumResolver}; | ||
| //# sourceMappingURL=index.js.map |
| { | ||
| "version": 3, | ||
| "sources": ["../../src/objects.ts"], | ||
| "sourcesContent": ["export const isObject = (value?: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && !!value\n\nexport const isObjectWithProps = <K extends string>(\n value?: unknown,\n ...props: K[]\n): value is { [k in K]: unknown } =>\n isObject(value) && props.every((prop) => prop in value)\n"], | ||
| "mappings": "AAAO,IAAMA,EAAYC,GACrB,OAAOA,GAAU,UAAY,CAAC,CAACA,EAEtBC,EAAoB,CAC7BD,KACGE,IAEHH,EAASC,CAAK,GAAKE,EAAM,MAAOC,GAASA,KAAQH,CAAK", | ||
| "names": ["isObject", "value", "isObjectWithProps", "props", "prop"] | ||
| "sources": ["../../src/enum.ts", "../../src/objects.ts"], | ||
| "sourcesContent": ["export const makeEnumResolver =\n <T extends string>(record: Record<string, T>, fallback: T) =>\n (value: string) => {\n const resolver = new Map(\n Object.values(record).map((item) => [item.toString(), item])\n )\n\n return resolver.get(value) || fallback\n }\n", "export const isObject = (value?: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && !!value\n\nexport const isObjectWithProps = <K extends string>(\n value?: unknown,\n ...props: K[]\n): value is { [k in K]: unknown } =>\n isObject(value) && props.every((prop) => prop in value)\n"], | ||
| "mappings": "AAAO,IAAMA,EACT,CAAmBC,EAA2BC,IAC7CC,GACoB,IAAI,IACjB,OAAO,OAAOF,CAAM,EAAE,IAAKG,GAAS,CAACA,EAAK,SAAS,EAAGA,CAAI,CAAC,CAC/D,EAEgB,IAAID,CAAK,GAAKD,ECP/B,IAAMG,EAAYC,GACrB,OAAOA,GAAU,UAAY,CAAC,CAACA,EAEtBC,EAAoB,CAC7BD,KACGE,IAEHH,EAASC,CAAK,GAAKE,EAAM,MAAOC,GAASA,KAAQH,CAAK", | ||
| "names": ["makeEnumResolver", "record", "fallback", "value", "item", "isObject", "value", "isObjectWithProps", "props", "prop"] | ||
| } |
@@ -0,1 +1,2 @@ | ||
| export * from './enum'; | ||
| export * from './objects'; |
+2
-2
| { | ||
| "$schema": "https://json.schemastore.org/package.json", | ||
| "name": "@pro-functional/objects", | ||
| "version": "0.3.5", | ||
| "version": "0.4.0", | ||
| "author": { | ||
@@ -55,3 +55,3 @@ "name": "Harish Prakash", | ||
| }, | ||
| "gitHead": "b6093582b99704b595679f08c63b01b8e51c4965" | ||
| "gitHead": "a471cf3027cf1107ca7636d4f4032beb7e680057" | ||
| } |
+77
-1
@@ -1,1 +0,77 @@ | ||
| # Objects | ||
| # Objects | ||
| ## Installation | ||
| ```sh | ||
| yarn add --exact @pro-functional/objects | ||
| ``` | ||
| ## Tools | ||
| **isObject** A type checker to evaluate the given value as an | ||
| `NonNullable<object>` | ||
| ```ts | ||
| isObject(null) | ||
| // false | ||
| isObject(undefined) | ||
| // false | ||
| isObject(5) | ||
| // false | ||
| isObject('random value') | ||
| // false | ||
| isObject({}) | ||
| // true | ||
| ``` | ||
| **isObjectWithProps** A type checker that verifies the provided value to be an | ||
| object with the provided property keys | ||
| ```ts | ||
| isObjectWithProps(null, 'name', 'id') | ||
| // false | ||
| isObjectWithProps(undefined, 'name', 'id') | ||
| // false | ||
| isObjectWithProps(5, 'name', 'id') | ||
| // false | ||
| isObjectWithProps('random value', 'name', 'id') | ||
| // false | ||
| isObjectWithProps({}, 'name', 'id') | ||
| // false | ||
| isObjectWithProps({ name: 'bob' }, 'name', 'id') | ||
| // false | ||
| isObjectWithProps({ name: 'bob', id: '007', uid: 'ga98as7fuhk' }, 'name', 'id') | ||
| // true | ||
| ``` | ||
| **makeEnumResolver** Create a resolver for an Enum allowing you to map a text | ||
| back to the enum. The fallback allows a guaranteed response. | ||
| ```ts | ||
| enum Colors { | ||
| Green = 'green', | ||
| Blue = 'blue', | ||
| Invalid = 'invalid', | ||
| } | ||
| const resolveColor = makeEnumResolver(Colors, Colors.Invalid) | ||
| resolveColor('green') | ||
| // Colors.Green | ||
| resolveColor('blue') | ||
| // Colors.Blue | ||
| resolveColor('purple') | ||
| // Colors.Invalid | ||
| ``` |
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
8079
50.78%10
11.11%11
22.22%78
7700%0
-100%