Skip to content

utility function to define what single argument function requires from argument type

License

Notifications You must be signed in to change notification settings

whiteand/func-spy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

func-spy

Exports function spy(fn, arg). Which returns { result: fn(arg), metadata: <Metadata>}

Metadata contains definition of all parts of arg which was used in fn during calculatino of fn(arg).

Example

import { spy, typeToStringTypes, iterate } from 'func-spy';

const { result, metadata } = spy(state => state?.users?.[0]?.name, {
  users: [{ name: 'andrew' }],
});

console.log(result); // 'andrew'
iterate(node => {
  console.log(node.path, typeToStringTypes(node.type).join('|'));
}, metadata);
// [] object
// ['users'] array
// ['users', '0'] object
// ['users', '0', 'name'] string

About

utility function to define what single argument function requires from argument type

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published