{"id":13806112,"url":"https://github.com/poteto/ember-macaroni","last_synced_at":"2025-05-13T21:32:19.204Z","repository":{"id":57224020,"uuid":"43317919","full_name":"poteto/ember-macaroni","owner":"poteto","description":"Keep your app code DRY and copypasta free with computed property macaronis (macros)","archived":true,"fork":false,"pushed_at":"2018-06-11T21:08:16.000Z","size":94,"stargazers_count":99,"open_issues_count":8,"forks_count":13,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-10-12T13:54:52.988Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/poteto.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}},"created_at":"2015-09-28T18:08:05.000Z","updated_at":"2023-01-27T23:54:15.000Z","dependencies_parsed_at":"2022-08-30T02:40:32.404Z","dependency_job_id":null,"html_url":"https://github.com/poteto/ember-macaroni","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poteto%2Fember-macaroni","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poteto%2Fember-macaroni/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poteto%2Fember-macaroni/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poteto%2Fember-macaroni/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/poteto","download_url":"https://codeload.github.com/poteto/ember-macaroni/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225260373,"owners_count":17446086,"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-08-04T01:01:07.981Z","updated_at":"2024-11-18T22:31:18.077Z","avatar_url":"https://github.com/poteto.png","language":"JavaScript","readme":"\u003cimg src=\"http://i.imgur.com/XV4VFJl.jpg\" title=\"Macaroni\" align=\"right\" width=\"33%\"\u003e\n\n# ember-macaroni\n\n[![npm version](https://badge.fury.io/js/ember-macaroni.svg)](http://badge.fury.io/js/ember-macaroni) [![Build Status](https://travis-ci.org/poteto/ember-macaroni.svg?branch=master)](https://travis-ci.org/poteto/ember-macaroni) [![Ember Observer Score](http://emberobserver.com/badges/ember-macaroni.svg)](http://emberobserver.com/addons/ember-macaroni)\n\nKeep your app code DRY and copypasta free with computed property \u003cstrong\u003emac\u003c/strong\u003ea\u003cstrong\u003ero\u003c/strong\u003eni\u003cstrong\u003es\u003c/strong\u003e (macros) for Ember.js 1.13.x and greater. \n\n## Why\nComputed property macros (CPM) are great for DRYing up your code, and Ember.js ships with a [few handy computed macros](http://emberjs.com/api/classes/Ember.computed.html). This addon adds a few more functional-style macros, and can be thought of as the \"lodash equivalent\" of Ember CPM libraries.\n\nChaining is not supported... yet.\n\n## Usage\nFirst, import the macro(s) you need, or the whole thing:\n\n```js\nimport { findFromCollectionByKey } from 'ember-macaroni'; // imports a named macro\nimport macros from 'ember-macaroni'; // imports all the things\nconst { findFromCollectionByValue } = macros; // destructuring\n\nexport default Ember.Component.extend({\n  items: null,\n  selectedId: null,\n  selectedItem: findFromCollectionByKey('items', 'id', 'selectedId'),\n  hansel: findFromCollectionByValue('items', 'name', 'Hansel'),\n\n  init() {\n    this.items = [\n      { id: 1, name: 'Derek Zoolander' },\n      { id: 2, name: 'Hansel' },\n      { id: 3, name: 'Mugatu' }\n    ];\n  },\n\n  actions: {\n    selectPerson(id) {\n      Ember.set(this, 'selectedId', id);\n    }\n  }\n});\n```\n\n## Available macros\n\n* [Collection](#collection)\n  - [findFromCollectionByKey](#findfromcollectionbykey)\n  - [findFromCollectionByValue](#findfromcollectionbyvalue)\n  - [rejectFromCollectionByKey](#rejectfromcollectionbykey)\n  - [rejectFromCollectionByValue](#rejectfromcollectionbyvalue)\n  - [filterFromCollectionByKey](#filterfromcollectionbykey)\n  - [filterFromCollectionByContains](#filterfromcollectionbycontains)\n  - [collectionWithoutKey](#collectionwithoutkey)\n  - [reduceCollectionByKey](#reducecollectionbykey)\n* [Truth](#truth)\n  - [isEqualByKeys](#isequalbykeys)\n  - [ifThenElseWithKeys](#ifthenelsewithkeys)\n  - [ifThenElseWithValues](#ifthenelsewithvalues)\n  - [gte](#gte)\n  - [gt](#gt)\n  - [lte](#lte)\n  - [lt](#lt)\n* [General](#general)\n  - [getPropertiesByKeys](#getpropertiesbykeys)\n  - [joinWith](#joinwith)\n\n---\n\n### Collection\n\n#### `findFromCollectionByKey`\n\nReturns the first item with a property matching the passed value from a dependent key.\n\n- `@param {String} collectionKey` The key name for the collection\n- `@param {String} propName` The key name for the property to find by\n- `@param {String} valueKey` The key name that returns the value to find\n\n```js \nEmber.Object.extend({\n  items: [{ id: 1, name: 'foo' }, { id: 2, name: 'bar' }],\n  selectedId: 1,\n  selectedItem: findFromCollectionByKey('items', 'id', 'selectedId') // { id: 1, name: 'foo' }\n});\n```\n\n**[⬆ back to top](#available-macros)**\n\n#### `findFromCollectionByValue`\n\nReturns the first item with a property matching the passed value.\n\n- `@param {String} collectionKey` The key name for the collection\n- `@param {String} propName` The key name for the property to find by\n- `@param {*} value` The value to match`\n\n```js \nEmber.Object.extend({\n  items: [{ id: 1, name: 'foo' }, { id: 2, name: 'bar' }],\n  selectedItem: findFromCollectionByValue('items', 'id', 1) // { id: 1, name: 'foo' }\n});\n```\n\n**[⬆ back to top](#available-macros)**\n\n#### `rejectFromCollectionByKey`\n\nReturns an array with the items that do not match the passed value from a dependent key.\n\n- `@param {String} collectionKey` The key name for the collection\n- `@param {String} propName` The key name for the property to reject by\n- `@param {String} valueKey` The key name that returns the value to reject\n\n```js\nEmber.Object.extend({\n  items: [{ id: 1, name: 'foo' }, { id: 2, name: 'bar' }],\n  selectedId: 2,\n  selectedItem: rejectFromCollectionByKey('items', 'id', 'selectedId') // [{ id: 1, name: 'foo' }]\n});\n```\n\n**[⬆ back to top](#available-macros)**\n\n#### `rejectFromCollectionByValue`\n\nReturns an array with the items that do not match the passed value.\n\n- `@param {String} collectionKey` The key name for the collection\n- `@param {String} propName` The key name for the property to reject by\n- `@param {*} value` The value to reject\n\n```js\nEmber.Object.extend({\n  items: [{ id: 1, name: 'foo' }, { id: 2, name: 'bar' }],\n  selectedItem: rejectFromCollectionByValue('items', 'id', 2) // [{ id: 1, name: 'foo' }]\n});\n```\n\n**[⬆ back to top](#available-macros)**\n\n#### `filterFromCollectionByKey`\n\nReturns an array with just the items with the matched property.\n\n- `@param {String} collectionKey` The key name for the collection\n- `@param {String} propName` The key name for the property to filter by\n- `@param {String} valueKey` The key name that returns the value to filter\n\n```js\nEmber.Object.extend({\n  items: [{ id: 1, name: 'foo' }, { id: 2, name: 'bar' }],\n  selectedId: 1,\n  selectedItem: filterFromCollectionByKey('items', 'id', 'selectedId') // [{ id: 1, name: 'foo' }]\n});\n```\n\n**[⬆ back to top](#available-macros)**\n\n#### `filterFromCollectionByContains`\n\nReturns an array with just the items that are contained in another array.\n\n- `@param {String} collectionKey` The key name for the collection\n- `@param {String} propName` The key name for the property to filter by\n- `@param {Array} values` The array of values to filter\n\n```js\nEmber.Object.extend({\n  items: [{ id: 1, name: 'foo' }, { id: 2, name: 'bar' }],\n  selectedId: 1,\n  selectedItem: filterFromCollectionByContains('items', 'id', [1]) // [{ id: 1, name: 'foo' }]\n});\n```\n\n**[⬆ back to top](#available-macros)**\n\n#### `collectionWithoutKey`\n\nReturns an array without an item by dependent key.\n\n- `@param {String} collectionKey` The key name for the collection\n- `@param {String} propName` The key name for the property to exclude\n\n```js\nEmber.Object.extend({\n  items: [1, 2, 3],\n  selectedItem: 1,\n  remainingItems: collectionWithoutKey('items', 'selectedItem') // [2, 3]\n});\n```\n\n**[⬆ back to top](#available-macros)**\n\n#### `reduceCollectionByKey`\n\nCombines the values of the enumerator into a single value, using a dependent key.\n\n- `@param {String} collectionKey` The key name for the collection\n- `@param {String} dependentKey` The key name for the property to reduce\n- `@param {*} startValue` The initial value\n\n```js\nEmber.Object.extend({\n  items: [{ name: 'foo', age: 2 }, { name: 'bar', age: 5 }],\n  selectedItem: reduceCollectionByKey('items', 'age', 0) // 7\n});\n```\n\n**[⬆ back to top](#available-macros)**\n\n---\n\n### Truth\n\n#### `isEqualByKeys`\n\nStrict equality using dependent keys.\n\n- `@param {String} firstKey` The key name for the first property\n- `@param {String} secondKey` The key name for the second property\n\n```js\nEmber.Object.extend({\n  employeeId: 1\n  selectedId: 1,\n  isSelected: isEqualByKeys('employeeId', 'selectedId') // true\n});\n```\n\n**[⬆ back to top](#available-macros)**\n\n#### `ifThenElseWithKeys`\n\nTernary conditional with dependent keys.\n\n- `@param {String} conditionalKey` The key name for the conditional property\n- `@param {String} trueKey` The key name for the property to return when the conditional is true\n- `@param {String} falseKey` The key name for the property to return when the conditional is false\n\n```js\nEmber.Object.extend({\n  isSelected: true,\n  selectedText: 'Is Enabled',\n  deselectedText: 'Is Disabled',\n  displayText: ifThenElseWithKeys('isSelected', 'selectedText', 'deselectedText') // 'Is Enabled'\n});\n```\n\n**[⬆ back to top](#available-macros)**\n\n#### `ifThenElseWithValues`\n\nTernary conditional.\n\n- `@param {String} conditionalKey` The key name for the conditional property\n- `@param {String} trueValue` The value to return when the conditional is true\n- `@param {String} falseValue` The value to return when the conditional is false\n\n```js\nEmber.Object.extend({\n  isSelected: true,\n  displayText: ifThenElseWithValues('isSelected', 'Is Enabled', 'Is Disabled') // 'Is Enabled'\n});\n```\n\n**[⬆ back to top](#available-macros)**\n\n#### `gte`\n\nGreater than or equal to comparison between two dependent keys.\n\n- `@param {String} lhsKey` The key name for the left hand side of the operator\n- `@param {String} rhsKey` The key name for the right hand side of the operator\n\n```js\nEmber.Object.extend({\n  first: 5,\n  second: 2,\n  isFirstGreaterThanOrEqualToSecond: gte('first', 'second') // true\n});\n```\n\n**[⬆ back to top](#available-macros)**\n\n#### `gt`\n\nGreater than comparison between two dependent keys.\n\n- `@param {String} lhsKey` The key name for the left hand side of the operator\n- `@param {String} rhsKey` The key name for the right hand side of the operator\n\n```js\nEmber.Object.extend({\n  first: 5,\n  second: 2,\n  isFirstGreaterThanSecond: gt('first', 'second') // true\n});\n```\n\n**[⬆ back to top](#available-macros)**\n\n#### `lte`\n\nLesser than or equal to comparison between two dependent keys.\n\n- `@param {String} lhsKey` The key name for the left hand side of the operator\n- `@param {String} rhsKey` The key name for the right hand side of the operator\n\n```js\nEmber.Object.extend({\n  first: 5,\n  second: 2,\n  isFirstLesserThanOrEqualToSecond: lte('first', 'second') // false\n});\n```\n\n**[⬆ back to top](#available-macros)**\n\n#### `lt`\n\nLesser than comparison between two dependent keys.\n\n- `@param {String} lhsKey` The key name for the left hand side of the operator\n- `@param {String} rhsKey` The key name for the right hand side of the operator\n\n```js\nEmber.Object.extend({\n  first: 5,\n  second: 2,\n  isFirstLessThanSecond: lt('first', 'second') // false\n});\n```\n\n**[⬆ back to top](#available-macros)**\n\n---\n\n### General\n\n#### `getPropertiesByKeys`\n\nReturns a POJO containing all the key-values that match the dependent keys.\n\n- `@param {...rest} dependentKeys` Argument list of dependent keys\n\n```js\nEmber.Object.extend({\n  age: 5,\n  name: 'foo',\n  props: getPropertiesByKeys('age', 'name') // { age: 5, name: 'foo' }\n});\n```\n\n**[⬆ back to top](#available-macros)**\n\n#### `joinWith`\n\nReturns a string of values joined together with a separator.\n\n- `@param {String} seperator` Separator to join values with\n- `@param {...rest} dependentKeys` Argument list of dependent keys\n\n```js\nEmber.Object.extend({\n  firstName: 'Derek',\n  lastName: 'Zoolander',\n  fullName: joinWith(' ', 'firstName', 'lastName') // 'Derek Zoolander'\n});\n```\n\n**[⬆ back to top](#available-macros)**\n\n## Installation\n\n* `git clone` this repository\n* `npm install`\n* `bower install`\n\n## Running\n\n* `ember server`\n* Visit your app at http://localhost:4200.\n\n## Running Tests\n\n* `ember test`\n* `ember test --server`\n\n## Building\n\n* `ember build`\n\nFor more information on using ember-cli, visit [http://www.ember-cli.com/](http://www.ember-cli.com/).\n","funding_links":[],"categories":["Packages"],"sub_categories":["Data manipulation \u0026 Computed"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoteto%2Fember-macaroni","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpoteto%2Fember-macaroni","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoteto%2Fember-macaroni/lists"}