{"id":21082306,"url":"https://github.com/olsonpm/madonna-function","last_synced_at":"2025-03-14T04:43:15.902Z","repository":{"id":80606409,"uuid":"60228914","full_name":"olsonpm/madonna-function","owner":"olsonpm","description":null,"archived":false,"fork":false,"pushed_at":"2016-08-01T18:10:55.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-20T23:46:02.343Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/olsonpm.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}},"created_at":"2016-06-02T03:14:26.000Z","updated_at":"2016-06-02T03:15:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"bc43bd75-9003-4166-a456-b48f4d8d11ca","html_url":"https://github.com/olsonpm/madonna-function","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olsonpm%2Fmadonna-function","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olsonpm%2Fmadonna-function/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olsonpm%2Fmadonna-function/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olsonpm%2Fmadonna-function/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/olsonpm","download_url":"https://codeload.github.com/olsonpm/madonna-function/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243526853,"owners_count":20305112,"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":[],"created_at":"2024-11-19T20:13:37.664Z","updated_at":"2025-03-14T04:43:15.894Z","avatar_url":"https://github.com/olsonpm.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Madonna Function\nCreates a function that validates its arguments via\n[madonna-fp](https://github.com/olsonpm/madonna-fp), passing them to another\nfunction.  You can optionally configure mapper functions to modify the arguments\nafter validation.  I created this because I often want to call a function and\nknow for certain the arguments are valid.  The optional mapper is for\nconvenience since I also often need arguments to come in as raw json and passed\nthrough a class or constructor.  The mapping functionality is provided by\n[madonna-map](https://github.com/olsonpm/madonna-fp).\n\n**Tested against**\n - node 0.10.0 for the (default) es5 version\n - node 6.0.0 for es6 @ `require('madonna-function/es6')`\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n## Table of Contents\n\n - [Examples](#examples)\n - [API](#api)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n## Examples\n```js\nconst createMadonnaFn = require('madonna-function').create\n  , printArgs = console.dir.bind(console);\n\n// creates a function requiring the argument 'name' and prints it\nlet mfn = createMadonnaFn({\n  marg: { name: ['require', 'isLadenString'] }\n  , fn: printArgs\n});\n\nmfn({ name: 'matt' });\n// prints\n// { name: 'matt' }\n\n\n// lets do the same but map name to all uppercase letters\nlet mfn = createMadonnaFn({\n  marg: { name: ['require', 'isLadenString'] }\n  , fn: printArgs\n  , argMap: { name: fp.toUpper }\n});\n\nmfn({ name: 'matt' });\n// prints\n// { name: 'MATT' }\n\n\n// madonna-fp validation errors will be thrown if you pass invalid arguments\nmfn({ name: 1 });\n// throws the error\n// Invalid Input: The following arguments didn't pass their criterion\n// invalid arguments and values: {\n//   \"name\": 1\n// }\n// failed criterion per argument: {\n//   \"name\": {\n//     \"flags\": [\n//       \"isLadenString\"\n//     ]\n//   }\n// }\n```\n\n## API\n`require('madonna-function').create`\n - Takes the following arguments\n   - **marg**: `require` `isLadenPlainObject`\n     - marg stands for 'madonna-fp argument'.  It is passed to madonna-fp which\n       is used to validate the arguments in calls to the returned function.\n   - **fn**: `require` `fp.isFunction`\n     - The function called with the validated, and possibly mapped arguments\n   - **argMap**: `isLadenPlainObject`\n     - An object with keys present in **marg** to functions whose input\n       will be the validated value, and output will be passed to **fn**.\n       Examples above should clarify any confusion.\n - Returns a function that validates its input against **marg**.  Any properties\n   in **argMap** will pass through their mappers.  All validated and mapped\n   values will be passed into **fn**.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Folsonpm%2Fmadonna-function","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Folsonpm%2Fmadonna-function","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Folsonpm%2Fmadonna-function/lists"}