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

@rss/common

Package Overview
Dependencies
Maintainers
1
Versions
895
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rss/common - npm Package Compare versions

Comparing version 0.0.36 to 0.0.37

dist/model/chemical/transfer.js

56

dist/model/chemical/container.js

@@ -15,2 +15,3 @@ 'use strict';

var InventoryReference = require('./inventory-reference');
var Transfer = require('./transfer');
var Location = require('../core/location');

@@ -34,2 +35,3 @@

this.size = null;
this.amount = null;
this.units = null;

@@ -49,6 +51,11 @@ this.physicalState = null;

this.checkout = null;
this.normalized = {
this.normalizedSize = {
gram: null,
liter: null
};
this.normalizeAmount = {
gram: null,
liter: null
};
this.transfer = null;
this.solvent = null;

@@ -74,2 +81,3 @@ this.concentration = null;

this.size = opt.size ? parseFloat(opt.size, 10) : null;
this.amount = parseFloat(!isNaN(opt.amount) ? opt.amount : opt.size, 10); // eslint-disable-line
this.units = opt.units || null;

@@ -87,2 +95,3 @@ this.physicalState = opt.physicalState || null;

this.checkout = opt.checkout ? new Checkout(opt.checkout) : null;
this.transfer = opt.transfer ? new Transfer(opt.transfer) : null;
this.solvent = opt.solvent || null;

@@ -104,3 +113,8 @@ this.concentration = opt.concentration ? parseFloat(opt.concentration) || null : null;

this.normalized = this.normalizeSize(this.size, this.units, this.family.density ? this.family.density.value : null);
var _normalizeSizeAndAmou = this.normalizeSizeAndAmount(this.size, this.amount, this.units, this.family.density ? this.family.density.value : null),
normalizedSize = _normalizeSizeAndAmou.normalizedSize,
normalizedAmount = _normalizeSizeAndAmou.normalizedAmount;
this.normalizedSize = normalizedSize;
this.normalizedAmount = normalizedAmount;
}

@@ -114,5 +128,5 @@ }, {

}, {
key: 'normalizeSize',
value: function normalizeSize(size, units, density) {
var normalized = {
key: 'normalizeSizeAndAmount',
value: function normalizeSizeAndAmount(size, amount, units, density) {
var normalizedSize = {
gram: null,

@@ -122,2 +136,7 @@ liter: null

var normalizedAmount = {
gram: null,
liter: null
};
var conversion = UNITS_CONVERSION[units];

@@ -127,9 +146,13 @@ if (conversion) {

case 'mass':
normalized.gram = size * conversion.conversionFactor;
normalized.liter = size * conversion.conversionFactor * 0.001 / (density || 1); // eslint-disable-line
normalizedSize.gram = size * conversion.conversionFactor;
normalizedSize.liter = size * conversion.conversionFactor * 0.001 / (density || 1); // eslint-disable-line
normalizedAmount.gram = amount * conversion.conversionFactor;
normalizedAmount.liter = amount * conversion.conversionFactor * 0.001 / (density || 1); // eslint-disable-line
break;
case 'volume':
normalized.gram = size * conversion.conversionFactor * density * 1000 || null;
normalized.liter = size * conversion.conversionFactor;
normalizedSize.gram = size * conversion.conversionFactor * density * 1000 || null;
normalizedSize.liter = size * conversion.conversionFactor;
normalizedAmount.gram = amount * conversion.conversionFactor * density * 1000 || null;
normalizedAmount.liter = amount * conversion.conversionFactor;
break;

@@ -142,3 +165,3 @@

return normalized;
return { normalizedSize: normalizedSize, normalizedAmount: normalizedAmount };
}

@@ -159,3 +182,4 @@ }], [{

size: { type: 'number' },
normalized: {
amount: { type: 'number' },
normalizedSize: {
type: 'object',

@@ -167,2 +191,9 @@ properties: {

},
normalizedAmount: {
type: 'object',
properties: {
gram: { type: ['number', 'null'] },
liter: { type: ['number', 'null'] }
}
},
units: { enum: UNITS.map(function (unit) {

@@ -186,3 +217,4 @@ return unit.value;

concentrationUnits: { type: ['string', 'null'] },
checkout: { anyOf: [{ $ref: 'checkout.schema.json' }, { type: ['null'] }] }
checkout: { anyOf: [{ $ref: 'checkout.schema.json' }, { type: ['null'] }] },
transfer: { anyOf: [{ $ref: 'transfer.schema.json' }, { type: ['null'] }] }
},

@@ -189,0 +221,0 @@

@@ -87,2 +87,3 @@ // constant - core

exports.Substance = require('./dist/model/chemical/substance');
exports.Transfer = require('./dist/model/chemical/transfer');

@@ -89,0 +90,0 @@ // model - location

{
"name": "@rss/common",
"version": "0.0.36",
"version": "0.0.37",
"description": "common constant, classes, & helper",

@@ -5,0 +5,0 @@ "author": "Risk & Safety Solution",

@@ -9,2 +9,3 @@ const ObjectId = require('bson').ObjectID;

const InventoryReference = require('./inventory-reference');
const Transfer = require('./transfer');
const Location = require('../core/location');

@@ -26,2 +27,3 @@

this.size = null;
this.amount = null;
this.units = null;

@@ -41,6 +43,11 @@ this.physicalState = null;

this.checkout = null;
this.normalized = {
this.normalizedSize = {
gram: null,
liter: null,
};
this.normalizeAmount = {
gram: null,
liter: null,
};
this.transfer = null;
this.solvent = null;

@@ -62,2 +69,3 @@ this.concentration = null;

this.size = opt.size ? parseFloat(opt.size, 10) : null;
this.amount = parseFloat(!isNaN(opt.amount) ? opt.amount : opt.size, 10); // eslint-disable-line
this.units = opt.units || null;

@@ -75,2 +83,3 @@ this.physicalState = opt.physicalState || null;

this.checkout = opt.checkout ? new Checkout(opt.checkout) : null;
this.transfer = opt.transfer ? new Transfer(opt.transfer) : null;
this.solvent = opt.solvent || null;

@@ -88,3 +97,10 @@ this.concentration = opt.concentration ? parseFloat(opt.concentration) || null : null;

this.normalized = this.normalizeSize(this.size, this.units, this.family.density ? this.family.density.value : null);
const { normalizedSize, normalizedAmount } = this.normalizeSizeAndAmount(
this.size,
this.amount,
this.units,
this.family.density ? this.family.density.value : null,
);
this.normalizedSize = normalizedSize;
this.normalizedAmount = normalizedAmount;
}

@@ -97,4 +113,4 @@

normalizeSize(size, units, density) {
const normalized = {
normalizeSizeAndAmount(size, amount, units, density) {
const normalizedSize = {
gram: null,

@@ -104,2 +120,7 @@ liter: null,

const normalizedAmount = {
gram: null,
liter: null,
};
const conversion = UNITS_CONVERSION[units];

@@ -109,9 +130,13 @@ if (conversion) {

case 'mass':
normalized.gram = size * conversion.conversionFactor;
normalized.liter = size * conversion.conversionFactor * 0.001 / (density || 1); // eslint-disable-line
normalizedSize.gram = size * conversion.conversionFactor;
normalizedSize.liter = (size * conversion.conversionFactor * 0.001) / (density || 1); // eslint-disable-line
normalizedAmount.gram = amount * conversion.conversionFactor;
normalizedAmount.liter = (amount * conversion.conversionFactor * 0.001) / (density || 1); // eslint-disable-line
break;
case 'volume':
normalized.gram = size * conversion.conversionFactor * density * 1000 || null;
normalized.liter = size * conversion.conversionFactor;
normalizedSize.gram = size * conversion.conversionFactor * density * 1000 || null;
normalizedSize.liter = size * conversion.conversionFactor;
normalizedAmount.gram = amount * conversion.conversionFactor * density * 1000 || null;
normalizedAmount.liter = amount * conversion.conversionFactor;
break;

@@ -124,3 +149,3 @@

return normalized;
return { normalizedSize, normalizedAmount };
}

@@ -140,3 +165,4 @@

size: { type: 'number' },
normalized: {
amount: { type: 'number' },
normalizedSize: {
type: 'object',

@@ -148,2 +174,9 @@ properties: {

},
normalizedAmount: {
type: 'object',
properties: {
gram: { type: ['number', 'null'] },
liter: { type: ['number', 'null'] },
},
},
units: { enum: UNITS.map((unit) => unit.value) },

@@ -166,2 +199,3 @@ physicalState: { type: ['string', 'null'] },

checkout: { anyOf: [{ $ref: 'checkout.schema.json' }, { type: ['null'] }] },
transfer: { anyOf: [{ $ref: 'transfer.schema.json' }, { type: ['null'] }] },
},

@@ -168,0 +202,0 @@

@@ -8,17 +8,27 @@ const Container = require('./container');

it('should return null normalize values if no units are passed in', () => {
expect(container.normalizeSize(1, null)).toEqual({ gram: null, liter: null });
expect(container.normalizeSizeAndAmount(1, 1, null).normalizedSize).toEqual({ gram: null, liter: null });
});
it('should return null normalize values if unit isother ', () => {
expect(container.normalizeSize(1, 'other')).toEqual({ gram: null, liter: null });
expect(container.normalizeSizeAndAmount(1, 1, 'other').normalizedSize).toEqual({ gram: null, liter: null });
});
it('should normalize to gram using conversion factory', () => {
expect(container.normalizeSize(2, 'μg')).toEqual({ gram: 0.000002, liter: 2e-9 });
expect(container.normalizeSizeAndAmount(2, 1, 'μg').normalizedSize).toEqual({ gram: 0.000002, liter: 2e-9 });
});
it('should normalize units gram using density when unit is volume', () => {
expect(container.normalizeSize(2, 'μL', '.5')).toEqual({ gram: 0.001, liter: 0.000002 });
expect(container.normalizeSizeAndAmount(2, 1, 'μL', '.5').normalizedSize).toEqual({ gram: 0.001, liter: 0.000002 });
});
it('should set container amount to container size if not passed in', () => {
const cont = new Container({ size: 10 });
expect(cont.amount).toEqual(10);
});
it('should allow container amount to be zero', () => {
const cont = new Container({ amount: 0, size: 10 });
expect(cont.amount).toEqual(0);
});
describe('barcode', () => {

@@ -25,0 +35,0 @@ const containerData = {

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