New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

shape-collection

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shape-collection - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

tests/test-data.js

12

bundle/script.js

@@ -343,8 +343,5 @@ /******/ (function(modules) { // webpackBootstrap

},
sortBy: function sortBy(_ref) {
var key = _ref.key,
_ref$type = _ref.type,
type = _ref$type === undefined ? 'string' : _ref$type,
_ref$direction = _ref.direction,
direction = _ref$direction === undefined ? 'asc' : _ref$direction;
sortBy: function sortBy(key) {
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'string';
var direction = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'asc';

@@ -362,2 +359,3 @@ shapeItems = _sortBy(shapeItems, key, type, direction);

}
return accumulator;
}, []);

@@ -369,5 +367,3 @@ return this;

window['shape'] = shape;
/***/ })
/******/ ]);

@@ -1,1 +0,1 @@

!function(n){function t(e){if(r[e])return r[e].exports;var o=r[e]={i:e,l:!1,exports:{}};return n[e].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var r={};t.m=n,t.c=r,t.d=function(n,r,e){t.o(n,r)||Object.defineProperty(n,r,{configurable:!1,enumerable:!0,get:e})},t.n=function(n){var r=n&&n.__esModule?function(){return n.default}:function(){return n};return t.d(r,"a",r),r},t.o=function(n,t){return Object.prototype.hasOwnProperty.call(n,t)},t.p="",t(t.s=0)}([function(n,t,r){n.exports=r(1)},function(n,t,r){"use strict";function e(n){if(Array.isArray(n)){for(var t=0,r=Array(n.length);t<n.length;t++)r[t]=n[t];return r}return Array.from(n)}Object.defineProperty(t,"__esModule",{value:!0});var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},u=function(n,t){Object.keys(n).forEach(function(r,e){return t(n[r],r,e)})},i=function(){var n=arguments[0],t=Object.assign(n,{}),r=[];return u(arguments,function(n,t,e){e>0&&r.push(n)}),r.forEach(function(n){Object.assign(t,n)}),t},c=function(n){return"object"===(void 0===n?"undefined":o(n))&&!a(n)&&!f(n)},f=function(n){return null===n},a=function(n){return Array.isArray(n)},s=function(n){return"string"==typeof n},l=function(n){return void 0===n},y=function(n,t){var r=t.split("."),e=r.length-1,o=0,u=!0,i=Object.assign({},n),a=void 0,s=void 0;if(r.length>0)for(;u;){if(s=i[r[o]],o===e){a=l(s)||f(s)?void 0:s;break}if(!c(s)){u=!1;break}i=s,o++}return a},p=function(n,t,r,e){return n.sort(function(n,o){var u=s(t)?y(n,t):"",i=s(t)?y(o,t):"";return l(u)||f(u)?"asc"===e?-1:1:l(i)||f(i)?"asc"===e?1:-1:"string"===r||"email"===r?u.toLowerCase()>i.toLowerCase()?"asc"===e?1:-1:u.toLowerCase()<i.toLowerCase()?"asc"===e?-1:1:0:"number"===r||"integer"===r||"float"===r?u>i?"asc"===e?1:-1:u<i?"asc"===e?-1:1:0:"date"===r?"asc"===e?new Date(u)-new Date(i):new Date(i)-new Date(u):"combo"===r?(u=t.map(function(t){return y(n,t)}).join(" "),i=t.map(function(n){return y(o,n)}).join(" "),l(u)||f(u)?"asc"===e?-1:1:l(i)||f(i)?"asc"===e?1:-1:u.toLowerCase()>i.toLowerCase()?"asc"===e?1:-1:u.toLowerCase()<i.toLowerCase()?"asc"===e?-1:1:0):void 0})},v=function(n,t){return n.reduce(function(n,r){var e=y(r,t);if(n.filter(function(n){return y(n,t)===e}).length>0)return n;var o=i({},r);return n.push(o),n},[])},d=function(n,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:2;return n.filter(function(e){var o=y(e,t),u=r-1;return n.filter(function(n){return y(n,t)===o}).length>u})},h=t.shape=function(n){var t=[].concat(e(n));return{fetch:function(){return t},fetchIndex:function(n){return t[n]},filterByUnique:function(n){return t=v(t,n),this},filterByDuplicate:function(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2;return t=d(t,n,r),this},filterByProp:function(n,r){return t=t.filter(function(t){return y(t,n)===r}),this},sortBy:function(n){var r=n.key,e=n.type,o=void 0===e?"string":e,u=n.direction;return t=p(t,r,o,void 0===u?"asc":u),this},reduceTo:function(n){return t=t.reduce(function(t,r){var o=y(r,n);return a(o)?[].concat(e(t),e(o)):l(o)||f(o)?void 0:[].concat(e(t),[o])},[]),this}}};window.shape=h}]);
!function(n){function t(e){if(r[e])return r[e].exports;var o=r[e]={i:e,l:!1,exports:{}};return n[e].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var r={};t.m=n,t.c=r,t.d=function(n,r,e){t.o(n,r)||Object.defineProperty(n,r,{configurable:!1,enumerable:!0,get:e})},t.n=function(n){var r=n&&n.__esModule?function(){return n.default}:function(){return n};return t.d(r,"a",r),r},t.o=function(n,t){return Object.prototype.hasOwnProperty.call(n,t)},t.p="",t(t.s=0)}([function(n,t,r){n.exports=r(1)},function(n,t,r){"use strict";function e(n){if(Array.isArray(n)){for(var t=0,r=Array(n.length);t<n.length;t++)r[t]=n[t];return r}return Array.from(n)}Object.defineProperty(t,"__esModule",{value:!0});var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},u=function(n,t){Object.keys(n).forEach(function(r,e){return t(n[r],r,e)})},i=function(){var n=arguments[0],t=Object.assign(n,{}),r=[];return u(arguments,function(n,t,e){e>0&&r.push(n)}),r.forEach(function(n){Object.assign(t,n)}),t},c=function(n){return"object"===(void 0===n?"undefined":o(n))&&!a(n)&&!f(n)},f=function(n){return null===n},a=function(n){return Array.isArray(n)},s=function(n){return"string"==typeof n},l=function(n){return void 0===n},y=function(n,t){var r=t.split("."),e=r.length-1,o=0,u=!0,i=Object.assign({},n),a=void 0,s=void 0;if(r.length>0)for(;u;){if(s=i[r[o]],o===e){a=l(s)||f(s)?void 0:s;break}if(!c(s)){u=!1;break}i=s,o++}return a},p=function(n,t,r,e){return n.sort(function(n,o){var u=s(t)?y(n,t):"",i=s(t)?y(o,t):"";return l(u)||f(u)?"asc"===e?-1:1:l(i)||f(i)?"asc"===e?1:-1:"string"===r||"email"===r?u.toLowerCase()>i.toLowerCase()?"asc"===e?1:-1:u.toLowerCase()<i.toLowerCase()?"asc"===e?-1:1:0:"number"===r||"integer"===r||"float"===r?u>i?"asc"===e?1:-1:u<i?"asc"===e?-1:1:0:"date"===r?"asc"===e?new Date(u)-new Date(i):new Date(i)-new Date(u):"combo"===r?(u=t.map(function(t){return y(n,t)}).join(" "),i=t.map(function(n){return y(o,n)}).join(" "),l(u)||f(u)?"asc"===e?-1:1:l(i)||f(i)?"asc"===e?1:-1:u.toLowerCase()>i.toLowerCase()?"asc"===e?1:-1:u.toLowerCase()<i.toLowerCase()?"asc"===e?-1:1:0):void 0})},v=function(n,t){return n.reduce(function(n,r){var e=y(r,t);if(n.filter(function(n){return y(n,t)===e}).length>0)return n;var o=i({},r);return n.push(o),n},[])},d=function(n,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:2;return n.filter(function(e){var o=y(e,t),u=r-1;return n.filter(function(n){return y(n,t)===o}).length>u})};t.shape=function(n){var t=[].concat(e(n));return{fetch:function(){return t},fetchIndex:function(n){return t[n]},filterByUnique:function(n){return t=v(t,n),this},filterByDuplicate:function(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2;return t=d(t,n,r),this},filterByProp:function(n,r){return t=t.filter(function(t){return y(t,n)===r}),this},sortBy:function(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"string",e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"asc";return t=p(t,n,r,e),this},reduceTo:function(n){return t=t.reduce(function(t,r){var o=y(r,n);return a(o)?[].concat(e(t),e(o)):l(o)||f(o)?t:[].concat(e(t),[o])},[]),this}}}}]);

@@ -231,3 +231,3 @@ /**

},
sortBy({ key, type = 'string', direction = 'asc' }) {
sortBy(key, type = 'string', direction = 'asc') {
shapeItems = sortBy(shapeItems, key, type, direction);

@@ -244,2 +244,3 @@ return this;

}
return accumulator;
}, []);

@@ -250,3 +251,1 @@ return this;

};
window['shape'] = shape;
{
"name": "shape-collection",
"version": "0.0.1",
"version": "0.0.2",
"description": "Utility for manipulating data in arrays of objects",

@@ -5,0 +5,0 @@ "main": "input.js",

@@ -49,7 +49,7 @@ <!-- Name -->

### fetchIndex
### fetchIndex(index)
`Function`. Returns item at a specific index from the shaped collection.
### filterByUnique
### filterByUnique(key, value)

@@ -75,3 +75,3 @@ `Function`. Filters the collection by unique value:

### filterByDuplicate
### filterByDuplicate(key, length = 2)

@@ -101,3 +101,3 @@ `Function`. Filter and extract duplicate items from collection:

### filterByProp
### filterByProp(key, value)

@@ -127,3 +127,3 @@ `Function`. Filter collection by property value:

### sortBy
### sortBy(key, type, direction)

@@ -169,3 +169,3 @@ `Function`. Sort collection by key, type and direction:

### reduceTo
### reduceTo(key)

@@ -194,1 +194,139 @@ `Function`. Reduce collection to another collection:

```
## Examples
```javascript
const groups = [{
id: 1,
type: 'day_group',
events: {
summerBreak: {
startDate: '22/06/2018',
endDate: '22/09/2018'
},
winterBreak: {
startDate: '22/12/2018',
endDate: '02/01/2019'
}
},
users: [{
id: 'abc',
name: 'John Doe',
age: 33,
exams: [{
name: 'English B1',
score: 5
}, {
name: 'Exam B',
score: 10
}]
}, {
id: 'xyz',
name: 'Teddy Williams',
age: 42,
exams: [{
name: 'English B1',
score: 6
}, {
name: 'Exam B',
score: 3
}]
}, {
id: 'zzz',
name: 'Jake McCoy',
age: 14,
exams: []
}]
}, {
id: 2,
type: 'evening_group',
events: {
summerBreak: {
startDate: '12/06/2018',
endDate: '12/09/2018'
},
winterBreak: {
startDate: '01/12/2018',
endDate: '01/02/2019'
}
},
users: [{
id: 'yyy',
name: 'Teddy Smith',
age: 23,
exams: [{
name: 'English B1',
score: 3
}, {
name: 'Exam B',
score: 7
}]
}, {
id: 'jjj',
name: 'Jane Doe',
age: 42,
exams: [{
name: 'English B1',
score: 4
}, {
name: 'Exam B',
score: 1
}]
}]
}, {
id: 3,
type: 'weekend_group',
users: []
}];
const examsSortedByName = shape(groups)
.reduceTo('users')
.reduceTo('exams')
.sortBy('name')
.fetch();
// examsSortedByName contains
/*
[
{name: "English B1", score: 5},
{name: "English B1", score: 6},
{name: "English B1", score: 3},
{name: "English B1", score: 4},
{name: "Exam B", score: 10},
{name: "Exam B", score: 3},
{name: "Exam B", score: 7},
{name: "Exam B", score: 1}
]
*/
const examsSortedByScore = shape(groups)
.reduceTo('users')
.reduceTo('exams')
.sortBy('score', 'number', 'desc')
.fetch();
// examsSortedByScore contains
/*
[
{name: "Exam B", score: 10},
{name: "Exam B", score: 7},
{name: "English B1", score: 6},
{name: "English B1", score: 5},
{name: "English B1", score: 4},
{name: "Exam B", score: 3},
{name: "English B1", score: 3},
{name: "Exam B", score: 1}
]
*/
// getting nested props from object fields, using comma-separated keys
const summerBreaks = shape(groups).reduceTo('events.summerBreak').fetch();
// summerBreaks contains
/*
[
{startDate: "22/06/2018", endDate: "22/09/2018"},
{startDate: "12/06/2018", endDate: "12/09/2018"}
]
*/
```
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