Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ember-array-computed-macros

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ember-array-computed-macros - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

1

addon/index.js

@@ -13,2 +13,3 @@ import Ember from 'ember';

export var sort = Ember.computed.sort;
export var sum = Ember.computed.sum;

@@ -15,0 +16,0 @@ export var maxBy = function(listProperty, valueProperty) {

2

package.json
{
"name": "ember-array-computed-macros",
"version": "1.0.1",
"version": "1.0.2",
"description": "The default blueprint for ember-cli addons.",

@@ -5,0 +5,0 @@ "directories": {

# ember-array-computed-macros
[![npm version](https://badge.fury.io/js/ember-array-computed-macros.svg)](http://badge.fury.io/js/ember-array-computed-macros) [![Build Status](https://travis-ci.org/martndemus/ember-array-computed-macros.svg?branch=master)](https://travis-ci.org/martndemus/ember-array-computed-macros)
## Usage
## Macros
### Map
This addon is supplemental to the already existing array computed macros existing in Ember.js
#### `maxBy(listProperty, valueProperty)`
Takes all values of `valueProperty` from `listProperty` and then picks the maximum value from that.
Example:
```js
import Ember from 'ember';
import { map } from 'ember-array-computed-macros';
var ContactList = Ember.Component.extend({
highestAge: maxBy('people', 'age')
});
export default Ember.Component.extend({
names: ['Tom', 'Yehuda'],
upperCasedNames: map('names', (name) => name.toUpperCase())
});
const myContactList = ContactList.create({
people: [
{ first: 'Tom', last: 'Dale', age: 21 },
{ first: 'Yehuda', last: 'Katz', age: 42 }
]
}).
myContactList.get('highestAge') // returns 42
```
### Map By
### `minBy(listPropery, valueProperty)`
See `maxBy`, except it takes the minimum value instead of the maximum.
### `orderBy(listProperty, ...sortProperties)`
Takes a `listProperty` and returns that list sorted by the `sortProperties`.
Append `:desc` to the sort property to sort in reverse order for that property.
```js

@@ -26,41 +43,56 @@ import Ember from 'ember';

names: [
{ first: 'Tom', last: 'Dale' },
{ first: 'Yehuda', last: 'Katz' }
{ first: 'Tom', last: 'Dale', age: 21 },
{ first: 'Yehuda', last: 'Katz', age: 42 }
],
firstNames: mapBy('names', 'first')
oderedNames: orderBy('names', 'last', 'first'. 'age:desc')
});
```
### Order By
### `sumBy(listProperty, valueProperty)`
Takes all values of `valueProperty` from `listProperty` and then sums those values.
Example:
```js
import Ember from 'ember';
import { map } from 'ember-array-computed-macros';
var ContactList = Ember.Component.extend({
collectiveAge: sumBy('people', 'age')
});
export default Ember.Component.extend({
names: [
const myContactList = ContactList.create({
people: [
{ first: 'Tom', last: 'Dale', age: 21 },
{ first: 'Yehuda', last: 'Katz', age: 42 }
],
oderedNames: orderBy('names', 'last', 'first'. 'age:desc')
});
]
}).
myContactList.get('collectiveAge') // returns 53
```
### Other
### `reverse(listProperty)`
Reverses the array at `listProperty` with `Array.prototype.reverse`.
### `everyBy(listPropery, valueProperty)`
Takes all values of `valueProperty` from `listProperty` and then checks if all of those values are truthy.
### `anyBy(listProperty, valueProperty)`
Takes all values of `valueProperty` from `listProperty` and then checks if any of those values are truthy.
### From Ember.js
The addon re-exports all array computed macros from Ember.js for convenience.
* map
* mapBy
* filter
* filterBy
* everyBy
* anyBy
* min
* minBy
* max
* maxBy
* reverse
* sum
* sort
## Use with decorators
## Decorators
```js

@@ -67,0 +99,0 @@ import Ember from 'ember';

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc