Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@backpack/luggage

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

@backpack/luggage - npm Package Compare versions

Comparing version
1.0.7
to
1.1.0
+8
-3
lib/fill-calculator.js

@@ -13,4 +13,6 @@ 'use strict';

*
* @param items {Array<{length: number, width: number, height: number, weight: number, price: number}>}
* @param items {Array<{length: number, width: number, height: number, weight: number,
* price: number, quantity: number}>}
* @returns {{numItems: number,
* quantity: number,
* itemWeight: number, itemVolume: number, filledWeight: number, filledVolume: number, itemPrice: number}}

@@ -23,7 +25,9 @@ */

var price = acc.price + (item.price === undefined ? 0 : Number(item.price));
return { weight: weight, volume: volume, price: price };
var quantity = acc.quantity + (item.quantity === undefined ? 1 : item.quantity);
return { weight: weight, volume: volume, price: price, quantity: quantity };
}, {
weight: 0,
volume: 0,
price: 0
price: 0,
quantity: 0
});

@@ -36,2 +40,3 @@

numItems: items.length,
quantity: total.quantity,
itemWeight: total.weight,

@@ -38,0 +43,0 @@ itemVolume: total.volume,

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

{"version":3,"sources":["../src/fill-calculator.js"],"names":["module","exports","utils","require","calculateFill","items","total","reduce","acc","item","weight","normalizedWeight","volume","normalizedVolume","price","undefined","Number","filledWeight","Math","round","weightPercent","filledVolume","volumePercent","numItems","length","itemWeight","itemVolume","itemPrice"],"mappings":";;AAAA;;;;AAIAA,OAAOC,OAAP,GAAkB,YAAY;AAC5B,MAAMC,QAAQC,QAAQ,SAAR,CAAd;;AAEA;;;;;;;AAOA,WAASC,aAAT,CAAuBC,KAAvB,EAA8B;AAC5B,QAAMC,QAAQD,MAAME,MAAN,CAAa,UAAUC,GAAV,EAAeC,IAAf,EAAqB;AAC9C,UAAMC,SAASF,IAAIE,MAAJ,GAAaR,MAAMS,gBAAN,CAAuBF,IAAvB,CAA5B;AACA,UAAMG,SAASJ,IAAII,MAAJ,GAAaV,MAAMW,gBAAN,CAAuBJ,IAAvB,CAA5B;AACA,UAAMK,QAAQN,IAAIM,KAAJ,IAAaL,KAAKK,KAAL,KAAeC,SAAf,GAA2B,CAA3B,GAA+BC,OAAOP,KAAKK,KAAZ,CAA5C,CAAd;AACA,aAAO,EAAEJ,cAAF,EAAUE,cAAV,EAAkBE,YAAlB,EAAP;AACD,KALa,EAKX;AACDJ,cAAQ,CADP;AAEDE,cAAQ,CAFP;AAGDE,aAAO;AAHN,KALW,CAAd;;AAWA,QAAMG,eAAeC,KAAKC,KAAL,CAAWjB,MAAMkB,aAAN,CAAoBd,MAAMI,MAA1B,CAAX,CAArB;AACA,QAAMW,eAAeH,KAAKC,KAAL,CAAWjB,MAAMoB,aAAN,CAAoBhB,MAAMM,MAA1B,CAAX,CAArB;;AAEA,WAAO;AACLW,gBAAUlB,MAAMmB,MADX;AAELC,kBAAYnB,MAAMI,MAFb;AAGLgB,kBAAYpB,MAAMM,MAHb;AAILK,gCAJK;AAKLI,gCALK;AAMLM,iBAAWT,KAAKC,KAAL,CAAWb,MAAMQ,KAAjB;AANN,KAAP;AAQD;;AAED,SAAOV,aAAP;AACD,CApCiB,EAAlB","file":"fill-calculator.js","sourcesContent":["/**\n * @author masum\n * @since 8/28/16\n */\nmodule.exports = (function () {\n const utils = require('./utils');\n\n /**\n * Calculate luggage fill information of items.\n *\n * @param items {Array<{length: number, width: number, height: number, weight: number, price: number}>}\n * @returns {{numItems: number,\n * itemWeight: number, itemVolume: number, filledWeight: number, filledVolume: number, itemPrice: number}}\n */\n function calculateFill(items) {\n const total = items.reduce(function (acc, item) {\n const weight = acc.weight + utils.normalizedWeight(item);\n const volume = acc.volume + utils.normalizedVolume(item);\n const price = acc.price + (item.price === undefined ? 0 : Number(item.price));\n return { weight, volume, price };\n }, {\n weight: 0,\n volume: 0,\n price: 0,\n });\n\n const filledWeight = Math.round(utils.weightPercent(total.weight));\n const filledVolume = Math.round(utils.volumePercent(total.volume));\n\n return {\n numItems: items.length,\n itemWeight: total.weight,\n itemVolume: total.volume,\n filledWeight,\n filledVolume,\n itemPrice: Math.round(total.price),\n };\n }\n\n return calculateFill;\n}());\n"]}
{"version":3,"sources":["../src/fill-calculator.js"],"names":["module","exports","utils","require","calculateFill","items","total","reduce","acc","item","weight","normalizedWeight","volume","normalizedVolume","price","undefined","Number","quantity","filledWeight","Math","round","weightPercent","filledVolume","volumePercent","numItems","length","itemWeight","itemVolume","itemPrice"],"mappings":";;AAAA;;;;AAIAA,OAAOC,OAAP,GAAkB,YAAY;AAC5B,MAAMC,QAAQC,QAAQ,SAAR,CAAd;;AAEA;;;;;;;;;AASA,WAASC,aAAT,CAAuBC,KAAvB,EAA8B;AAC5B,QAAMC,QAAQD,MAAME,MAAN,CAAa,UAAUC,GAAV,EAAeC,IAAf,EAAqB;AAC9C,UAAMC,SAASF,IAAIE,MAAJ,GAAaR,MAAMS,gBAAN,CAAuBF,IAAvB,CAA5B;AACA,UAAMG,SAASJ,IAAII,MAAJ,GAAaV,MAAMW,gBAAN,CAAuBJ,IAAvB,CAA5B;AACA,UAAMK,QAAQN,IAAIM,KAAJ,IAAaL,KAAKK,KAAL,KAAeC,SAAf,GAA2B,CAA3B,GAA+BC,OAAOP,KAAKK,KAAZ,CAA5C,CAAd;AACA,UAAMG,WAAWT,IAAIS,QAAJ,IAAgBR,KAAKQ,QAAL,KAAkBF,SAAlB,GAA8B,CAA9B,GAAkCN,KAAKQ,QAAvD,CAAjB;AACA,aAAO,EAAEP,cAAF,EAAUE,cAAV,EAAkBE,YAAlB,EAAyBG,kBAAzB,EAAP;AACD,KANa,EAMX;AACDP,cAAQ,CADP;AAEDE,cAAQ,CAFP;AAGDE,aAAO,CAHN;AAIDG,gBAAU;AAJT,KANW,CAAd;;AAaA,QAAMC,eAAeC,KAAKC,KAAL,CAAWlB,MAAMmB,aAAN,CAAoBf,MAAMI,MAA1B,CAAX,CAArB;AACA,QAAMY,eAAeH,KAAKC,KAAL,CAAWlB,MAAMqB,aAAN,CAAoBjB,MAAMM,MAA1B,CAAX,CAArB;;AAEA,WAAO;AACLY,gBAAUnB,MAAMoB,MADX;AAELR,gBAAUX,MAAMW,QAFX;AAGLS,kBAAYpB,MAAMI,MAHb;AAILiB,kBAAYrB,MAAMM,MAJb;AAKLM,gCALK;AAMLI,gCANK;AAOLM,iBAAWT,KAAKC,KAAL,CAAWd,MAAMQ,KAAjB;AAPN,KAAP;AASD;;AAED,SAAOV,aAAP;AACD,CAzCiB,EAAlB","file":"fill-calculator.js","sourcesContent":["/**\n * @author masum\n * @since 8/28/16\n */\nmodule.exports = (function () {\n const utils = require('./utils');\n\n /**\n * Calculate luggage fill information of items.\n *\n * @param items {Array<{length: number, width: number, height: number, weight: number,\n * price: number, quantity: number}>}\n * @returns {{numItems: number,\n * quantity: number,\n * itemWeight: number, itemVolume: number, filledWeight: number, filledVolume: number, itemPrice: number}}\n */\n function calculateFill(items) {\n const total = items.reduce(function (acc, item) {\n const weight = acc.weight + utils.normalizedWeight(item);\n const volume = acc.volume + utils.normalizedVolume(item);\n const price = acc.price + (item.price === undefined ? 0 : Number(item.price));\n const quantity = acc.quantity + (item.quantity === undefined ? 1 : item.quantity);\n return { weight, volume, price, quantity };\n }, {\n weight: 0,\n volume: 0,\n price: 0,\n quantity: 0,\n });\n\n const filledWeight = Math.round(utils.weightPercent(total.weight));\n const filledVolume = Math.round(utils.volumePercent(total.volume));\n\n return {\n numItems: items.length,\n quantity: total.quantity,\n itemWeight: total.weight,\n itemVolume: total.volume,\n filledWeight,\n filledVolume,\n itemPrice: Math.round(total.price),\n };\n }\n\n return calculateFill;\n}());\n"]}
{
"name": "@backpack/luggage",
"version": "1.0.7",
"version": "1.1.0",
"description": "Backpack luggage related code",

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

@@ -58,2 +58,3 @@ /**

expect(fill.itemPrice).to.equal(0);
expect(fill.quantity).to.equal(0);
});

@@ -84,2 +85,12 @@

});
it('calculates quantity correctly', function () {
const items = [
{ length: 2, quantity: 1 },
{ length: 3, quantity: 2 },
{ length: 4, quantity: 1 },
];
const fill = luggage.calculateFill(items);
expect(fill.quantity).to.equal(4);
});
});