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

angular-nav-thresholds

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-nav-thresholds - npm Package Compare versions

Comparing version 1.2.3 to 2.0.0

dist/bundle.min.js

195

dist/bundle.js

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

!function(e){"use strict";e="default"in e?e.default:e;var t=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},n=function(){function e(e,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,n,a){return n&&e(t.prototype,n),a&&e(t,a),t}}(),a=function(e,t){for(var n=0;n<e.length;n++)if(t(e[n]))return e[n]},r=function(e,t){return t.version===e},l=function(e,t){return t._id===e},i={min:0,reOrder:3,max:6},o=function(){function e(n,a,r,l){t(this,e),this.$q=n,this.smartId=a,this.lgasService=r,this.statesService=l}return n(e,[{key:"calculateThresholds",value:function(e,t){var n=arguments.length<=2||void 0===arguments[2]?{}:arguments[2];if(e&&e.allocations&&e.plans&&e.level&&t&&t.allocations&&t.allocations.version&&t.plans&&t.plans.version){var l=a(e.allocations,r.bind(null,t.allocations.version));if(l&&l.weeklyLevels){var o=l.weeklyLevels,s=i;if("zone"!==e.level){var u=a(e.plans,r.bind(null,t.plans.version));if(!u||!u.weeksOfStock)return;s=u.weeksOfStock}var c=Object.keys(o).reduce(function(t,a){return t[a]=Object.keys(s).reduce(function(t,r){return t[r]=Math.round(o[a]*s[r]),"zone"===e.level&&n[a]&&(t[r]+=n[a]),t},{}),e.targetPopulation&&(t[a].targetPopulation=e.targetPopulation[a]),t},{});return c}}}},{key:"getThresholdsFor",value:function(e){var t=this,n="zone:?state:?lga",r={},i={};r=e.reduce(function(e,a){var r=a.location;if(!r)return e;var l=t.smartId.idify(r,n),o=a.allocations||{version:1},s=a.plans||{version:1};return e[l]=angular.merge({},{allocations:o,plans:s}),r.lga?(i.lga||(i.lga=t.lgasService.list()),e[l].type="lga"):r.state&&(i.state||(i.state=t.statesService.list()),e[l].type="state"),e},{});var o=function(e){return Object.keys(r).forEach(function(n){var i=r[n],o=a(e[i.type],l.bind(null,n));i.thresholds=t.calculateThresholds(o,i),delete i.type}),r};return this.$q.all(i).then(o)}}]),e}();o.$inject=["$q","smartId","lgasService","statesService"],e.module("angularNavThresholds",["angularNavData","ngSmartId"]).service("thresholdsService",o)}(angular);
(function (angular$1) {
'use strict';
angular$1 = 'default' in angular$1 ? angular$1['default'] : angular$1;
var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
var createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
}();
// TODO: replace with Array#find ponyfill
var find = function find(list, match) {
for (var i = 0; i < list.length; i++) {
if (match(list[i])) {
return list[i];
}
}
return undefined;
};
var isVersion = function isVersion(version, item) {
return item.version === version;
};
var isId = function isId(id, item) {
return item._id === id;
};
// Zones config
var zonesPlan = {
min: 0,
reOrder: 3,
max: 6
};
var ThresholdsService = function () {
function ThresholdsService($q, smartId, lgasService, statesService) {
classCallCheck(this, ThresholdsService);
this.$q = $q;
this.smartId = smartId;
this.lgasService = lgasService;
this.statesService = statesService;
}
// For zones the thresholds are based on the state store required allocation for
// the week, that information is passed as an optional param (`requiredStateStoresAllocation`).
// That param is only used for zones.
createClass(ThresholdsService, [{
key: 'calculateThresholds',
value: function calculateThresholds(location, stockCount, products) {
var requiredStateStoresAllocation = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3];
if (!location || !location.allocations || !location.plans || !location.level) {
return;
}
if (!stockCount || !stockCount.allocations || !stockCount.allocations.version || !stockCount.plans || !stockCount.plans.version) {
return;
}
if (!products || !products.length) {
return;
}
var allocation = find(location.allocations, isVersion.bind(null, stockCount.allocations.version));
if (!(allocation && allocation.weeklyLevels)) {
return;
}
var weeklyLevels = allocation.weeklyLevels;
var weeksOfStock = zonesPlan;
if (location.level !== 'zone') {
var plan = find(location.plans, isVersion.bind(null, stockCount.plans.version));
if (!(plan && plan.weeksOfStock)) {
return;
}
weeksOfStock = plan.weeksOfStock;
}
var thresholds = Object.keys(weeklyLevels).reduce(function (index, productId) {
index[productId] = Object.keys(weeksOfStock).reduce(function (productThresholds, threshold) {
var level = weeklyLevels[productId] * weeksOfStock[threshold];
var product = find(products, isId.bind(null, productId));
// Default rounding used in VSPMD and highest possible presentation
var presentation = 20;
if (product && product.presentation) {
// TODO: product presentations should be ints, not strings
presentation = parseInt(product.presentation, 10);
}
var roundedLevel = Math.ceil(level / presentation) * presentation;
productThresholds[threshold] = roundedLevel;
if (location.level === 'zone' && requiredStateStoresAllocation[productId]) {
productThresholds[threshold] += requiredStateStoresAllocation[productId];
}
return productThresholds;
}, {});
if (location.targetPopulation) {
index[productId].targetPopulation = location.targetPopulation[productId];
}
return index;
}, {});
return thresholds;
}
}, {
key: 'getThresholdsFor',
value: function getThresholdsFor(stockCounts, products) {
var _this = this;
// TODO: make it work for zones too.
// For making it work with zones, we need to take into account the amount of stock
// to be allocated to the zone state stores in a particular week
var locationIdPattern = 'zone:?state:?lga';
var index = {};
var promises = {};
index = stockCounts.reduce(function (index, stockCount) {
var scLocation = stockCount.location;
if (!scLocation) {
return index;
}
var id = _this.smartId.idify(scLocation, locationIdPattern);
var allocations = stockCount.allocations || { version: 1 };
var plans = stockCount.plans || { version: 1 };
index[id] = angular.merge({}, { allocations: allocations, plans: plans });
if (scLocation.lga) {
if (!promises.lga) {
promises.lga = _this.lgasService.list();
}
index[id].type = 'lga';
} else if (scLocation.state) {
if (!promises.state) {
promises.state = _this.statesService.list();
}
index[id].type = 'state';
}
return index;
}, {});
var addThresholds = function addThresholds(promisesRes) {
Object.keys(index).forEach(function (key) {
var item = index[key];
var location = find(promisesRes[item.type], isId.bind(null, key));
item.thresholds = _this.calculateThresholds(location, item, products);
delete item.type;
});
return index;
};
return this.$q.all(promises).then(addThresholds);
}
}]);
return ThresholdsService;
}();
ThresholdsService.$inject = ['$q', 'smartId', 'lgasService', 'statesService'];
angular$1.module('angularNavThresholds', ['angularNavData', 'ngSmartId']).service('thresholdsService', ThresholdsService);
}(angular));
{
"name": "angular-nav-thresholds",
"version": "1.2.3",
"description": "",
"description": "Angular NAV module for calculating thresholds",
"main": "dist/bundle.js",
"scripts": {
"build": "rollup -c",
"postbuild": "uglifyjs dist/bundle.js --compress --mangle --output dist/bundle.min.js",
"pretest": "standard",
"test": "npm run -s build && karma start"
"test": "npm run -s build && karma start",
"prepublish-dist": "npm run build",
"publish-dist": "publish-dist --author-name 'Field Bot' --author-email 'ops+github@field.partners'",
"semantic-release": "semantic-release pre && npm run publish-dist && npm publish && semantic-release post"
},
"keywords": [],
"author": "Patricia Garcia <pat@patriciagarcia.me>",
"license": "Apache 2.0",
"keywords": [
"nav",
"navision",
"angular",
"thresholds"
],
"contributors": [
"Patricia Garcia <pat@patriciagarcia.me>",
"Tom Vincent <git@tlvince.com>"
],
"license": "Apache-2.0",
"engines": {
"node": ">=5"
},
"dependencies": {

@@ -21,2 +35,3 @@ "angular": "^1.5.5"

"babel-preset-es2015-rollup": "^1.1.1",
"ghooks": "^1.3.2",
"jasmine-core": "^2.4.1",

@@ -28,2 +43,3 @@ "karma": "^0.13.22",

"phantomjs-prebuilt": "^2.1.7",
"publish-dist": "^1.0.8",
"rollup": "^0.26.3",

@@ -33,4 +49,6 @@ "rollup-plugin-babel": "^2.4.0",

"rollup-plugin-node-resolve": "^1.5.0",
"rollup-plugin-uglify": "^1.0.0",
"standard": "^7.1.1"
"semantic-release": "^4.3.5",
"standard": "^7.1.1",
"uglify-js": "^2.7.3",
"validate-commit-msg": "^2.8.0"
},

@@ -46,3 +64,17 @@ "standard": {

}
}
}
},
"repository": {
"type": "git",
"url": "https://github.com/fielded/angular-nav-thresholds.git"
},
"config": {
"ghooks": {
"commit-msg": "validate-commit-msg",
"pre-push": "npm test"
}
},
"files": [
"dist/*"
],
"version": "2.0.0"
}
# angular-nav-thresholds
[![Build Status](https://travis-ci.org/fielded/angular-nav-thresholds.svg)](https://travis-ci.org/fielded/angular-nav-thresholds) ![Dependecy Status](https://david-dm.org/fielded/angular-nav-thresholds.svg) ![Dev Dependecy Status](https://david-dm.org/fielded/angular-nav-thresholds/dev-status.svg)
[![Build Status][travis-image]][travis-url]
[![npm version][npm-image]][npm-url]
[![License][license-image]][license-url]
[![semantic-release][semantic-release-image]][semantic-release-url]
[travis-url]: https://travis-ci.org/fielded/angular-nav-thresholds
[travis-image]: https://img.shields.io/travis/fielded/angular-nav-thresholds.svg
[npm-url]: https://www.npmjs.com/package/angular-nav-thresholds
[npm-image]: https://img.shields.io/npm/v/angular-nav-thresholds.svg
[license-url]: https://opensource.org/licenses/Apache-2.0
[license-image]: https://img.shields.io/npm/l/angular-nav-thresholds.svg
[semantic-release-url]: https://github.com/semantic-release/semantic-release
[semantic-release-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
> Angular NAV module for calculating thresholds
## Installation

@@ -13,3 +27,3 @@

npm install --save fielded/angular-nav-thresholds
npm install --save angular-nav-thresholds

@@ -46,4 +60,6 @@ Then simply add `angularNavThresholds` as a dependency somewhere in your project that makes sense and you're good to go.

To make a release, you need to run `npm run build`, commit the `dist` folder and tag the commit with an appropiate version according to the [SemVer spec](http://semver.org/).
This project uses [semantic-release][semantic-release-url] following the [AngularJS Git commit conventions][ccng].
[ccng]: https://github.com/conventional-changelog/conventional-changelog-angular/blob/e32d954eac0766916b9b7408efed95d643a198a9/convention.md
## License

@@ -50,0 +66,0 @@

.babelrc
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