1.3.1 • Published 3 years ago

@emealscom/packer v1.3.1

Weekly downloads
-
License
ISC
Repository
bitbucket
Last release
3 years ago

eMeals Measures Conversor Api

Measures supported

  • cups
  • grams
  • pounds
  • liters
  • mililiters
  • pint
  • quart
  • ounces
  • tablespoons
  • teaspoons
  • unit
  • each
  • package
  • slices
  • bunck
  • fz

Install

npm install --save-dev typescript

npm install --save @emealscom/packer

How to use it

Options

PropertyOptionalDescription
descriptionNoProduct Description
unitMeasureNoUnit of measure on recipe
unitQuantityNoQuantity on recipe
packageUnitMeasureNoUnit of measure on product package
packageUnitQuantityNoQuantity or content on product package
stapleYesIf staple or not, if yes, quantities factor is 1
rulesYesObject Array for rules

Rules

The Rules are used to perform calculations or replacements to the measurements and quantities of an ingredient or offer. The rules are applied in priority

PropertyOptionalDescription
priorNoPriority for apply
conditionNoObject for condition must be applied
convertionNoObject for all functions and convertions

condition and convertion is an object for OptionRule

OptionRule

PropertyOptionalDescription
descriptionYSet a value or ConvertFunction
unitMeasureYSet a value or ConvertFunction
unitQuantityYSet a value or ConvertFunction
packageUnitMeasureYSet a value or ConvertFunction
packageUnitQuantityYSet a value or ConvertFunction

ConvertFunction

PropertyOptionalDescription
nameNoName of a function
valueNoValues for function, string, number, array

Functions for convertions/conditions

test-regex, value must be a regular expression string, only return a boolean and must be used on condition.

math-c1, value must be a number, Math.ceil(property / value).

math-c2, value must be a number, property * value.

extract-c1, value must be an array set, index 0 has a property to applied a regular expression, index 1 has a regular expression, return an index 0 for match() result.

extract-c2, value must be an array set, index 0 has a property name to applied a regular expression, index 1 has a regular expression, return an index 1 for match() result.

setval-c1, value must be an array set, index 0 has a property name and return its value.

Rules examples

{
    prior: 2,
    condition: {
        unitMeasure: {
            name: "test-regex",
            value: "(jar|bottle|inch)"
        }
    },
    convertion: {
        unitQuantity: {
            name: "math-c2",
            value: ["packageUnitQuantity"]
        },
        unitMeasure: {
            name: "setval-c1",
            value: ["packageUnitMeasure"]
        }
    }
}
{
    prior: 2,
    condition: {
        unitMeasure: {
            name: "test-regex",
            value: "(ct|count|counts|ctn)"
        }
    },
    convertion: {
        packageUnitQuantity: {
            name: "math-c2",
            value: ["unitQuantity"]
        },
        packageUnitMeasure: "count"
    }
}

Coding

const packer = require('@emealscom/packer')

const packerRequest = {
    description: "Broccoli",
    offerDescription: "Pack of 4 Broccoli",
    unitMeasure: "grams",
    unitQuantity: 480,
    packageUnitMeasure: "ounces",
    packageUnitQuantity: 12
};

console.log(packer.convert(packerRequest));

Result

āžœ  test node index
{ estimatedQuantity: 2, status: true }
1.2.18

3 years ago

1.2.19

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.20

3 years ago

1.2.21

3 years ago

1.2.17

3 years ago

1.2.16

3 years ago

1.2.15

3 years ago

1.2.14

3 years ago

1.2.8

4 years ago

1.2.7

4 years ago

1.2.6

4 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.9

4 years ago

1.2.12

4 years ago

1.2.13

3 years ago

1.2.10

4 years ago

1.2.11

4 years ago

1.2.0

4 years ago

1.1.9

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.1.12

4 years ago

1.1.10

4 years ago

1.1.16

4 years ago

1.1.13

4 years ago

1.1.19

4 years ago

1.1.18

4 years ago

1.1.17

4 years ago

1.1.20

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago