{"id":21217378,"url":"https://github.com/paulmolluzzo/simmer","last_synced_at":"2025-03-15T00:42:36.883Z","repository":{"id":140515887,"uuid":"121406750","full_name":"paulmolluzzo/simmer","owner":"paulmolluzzo","description":"Put something in, reduce it down, and use the output","archived":false,"fork":false,"pushed_at":"2018-03-02T17:49:21.000Z","size":103,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-21T16:45:44.399Z","etag":null,"topics":["currying","javascript","reducer","utility"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/paulmolluzzo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2018-02-13T16:31:58.000Z","updated_at":"2018-07-17T14:57:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"1ee3cc0b-d045-4532-9619-401b31c0c0a4","html_url":"https://github.com/paulmolluzzo/simmer","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/paulmolluzzo%2Fsimmer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulmolluzzo%2Fsimmer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulmolluzzo%2Fsimmer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulmolluzzo%2Fsimmer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/paulmolluzzo","download_url":"https://codeload.github.com/paulmolluzzo/simmer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243667967,"owners_count":20328036,"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":["currying","javascript","reducer","utility"],"created_at":"2024-11-20T21:58:10.281Z","updated_at":"2025-03-15T00:42:36.854Z","avatar_url":"https://github.com/paulmolluzzo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# simmer 🍳 [![Build Status](https://travis-ci.org/paulmolluzzo/simmer.svg?branch=master)](https://travis-ci.org/paulmolluzzo/simmer)\n\n\u003e Put something in, reduce it down, and use the output\n\n## Install\n\n```\n$ npm install --save simmer\n```\n\n## Usage\n\n```js\nconst simmer = require('simmer')\nconst addExclamation = i =\u003e i + '!'\n\nsimmer([i =\u003e `Hello ${i}`, addExclamation], 'World') // 'Hello World!'\n```\n\n`simmer` provides a single utility function that accepts a function or array of functions and an input to pass to the function or first function in the array.\n\nIf a single function is provided, `simmer` returns a Promise of the function with the input as the argument.\n\nIf an array of functions is provided then `simmer` recursively executes each function in the array, passing the initial input or the result of the preceeding function as the argument.\n\n## Why Use This?\n\n`simmmer` is just a utility, but it provides opportunity to write interesting code with small building blocks.\n\n### Validate and format objects\n\nWant to accept some data, mutate that data, then validate that it fits a shape/schema? `simmer` makes it easy to create a list of functions and pass in data that will pass through the functions in order.\n\n```js\nconst input = {\n  firstName: 'Paul',\n  lastName: 'Molluzzo',\n  title: 'JavaScript Developer',\n  twitter: 'paulmolluzzo'\n}\n\nconst validateInput = input =\u003e {\n  if (!input.firstName || !input.lastName) {\n    throw new Error('Expected an object with a first and last name')\n  }\n\n  return input\n}\n\nconst createName = input =\u003e {\n  input.fullName = [input.firstName, input.lastName].join(' ')\n  return input\n}\n\nconst linkifyTwitter = input =\u003e {\n  input.twitter = `https://twitter.com/${input.twitter}`\n  return input\n}\n\nconst removeTitle = input =\u003e {\n  delete input.title\n  return input\n}\n\nconst validateOutput = input =\u003e {\n  if (input.title) {\n    throw new Error('Titles should be removed!')\n  }\n\n  return input\n}\n\nsimmer([validateInput, createName, linkifyTwitter, removeTitle, validateOutput], input)\n  .then(r =\u003e {\n    console.log(r) // {\"fullName\": \"Paul Molluzzo\", firstName: \"Paul\", lastName: \"Molluzzo\", \"twitter\": \"https://twitter.com/paulmolluzzo\"}\n  })\n```\n\n### Create a Curried Function\n\nUsing the same example above, it's possible to create a curried version of the same functionality by calling `simmer` with no `input`.\n\n```js\nconst curriedExample = simmer([validateInput, createName, linkifyTwitter, removeTitle, validateOutput])\n\n// delicious!\ncurriedExample({\n  firstName: 'Paul',\n  lastName: 'Molluzzo',\n  title: 'JavaScript Developer',\n  twitter: 'paulmolluzzo'\n})\n```\n\n## Acknowledgements\n\nThis work is heavily inspired by [DataPoint](https://github.com/ViacomInc/data-point/), in particular the `ListReducer`, `FunctionReducer`, and enlightening discussions with [Acatl Pacheco](https://github.com/acatl) and [Matthew Armstrong](https://github.com/raingerber). 🙌🙌🙌\n\n## License\n\nMIT © [Paul Molluzzo](https://paul.molluzzo.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaulmolluzzo%2Fsimmer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpaulmolluzzo%2Fsimmer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaulmolluzzo%2Fsimmer/lists"}