From 9484e05698dd1c23761e561e8559d62af63702e9 Mon Sep 17 00:00:00 2001 From: devdevdata222 Date: Mon, 16 Nov 2015 14:04:57 -0500 Subject: [PATCH 1/5] PLURALS -> ALIASES, add arcmin, arcsec Change PLURALS to ALIASES, clean up manual aliases. Add new angle units arcmin and arcsec, along with appropriate aliases. --- lib/type/unit/Unit.js | 55 ++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/lib/type/unit/Unit.js b/lib/type/unit/Unit.js index b3f1c0569..c0f9e4c1d 100644 --- a/lib/type/unit/Unit.js +++ b/lib/type/unit/Unit.js @@ -1901,7 +1901,23 @@ function factory (type, config, load, typed) { value: 6.2831853071795864769252867665793, offset: 0 }, - + // arcsec = rad / (3600 * (360 / 2 * pi)) = rad / 0.0000048481368110953599358991410235795 + arcsec: { + name: 'arcsec', + base: BASE_UNITS.ANGLE, + prefixes: PREFIXES.NONE, + value: 0.0000048481368110953599358991410235795, + offset: 0 + }, + // arcmin = rad / (60 * (360 / 2 * pi)) = rad / 0.00029088820866572159615394846141477 + arcmin: { + name: 'arcmin', + base: BASE_UNITS.ANGLE, + prefixes: PREFIXES.NONE, + value: 0.00029088820866572159615394846141477, + offset: 0 + }, + // Electric current A: { name: 'A', @@ -2310,8 +2326,8 @@ function factory (type, config, load, typed) { } }; - // plurals - var PLURALS = { + // aliases (formerly plurals) + var ALIASES = { meters: 'meter', inches: 'inch', feet: 'foot', @@ -2322,6 +2338,9 @@ function factory (type, config, load, typed) { chains: 'chain', angstroms: 'angstrom', + lt: 'litre', + liter: 'litre', + liters: 'litre', litres: 'litre', teaspoons: 'teaspoon', tablespoons: 'tablespoon', @@ -2344,6 +2363,8 @@ function factory (type, config, load, typed) { grains: 'grain', drams: 'dram', ounces: 'ounce', + lb: 'poundmass', + lbm: 'poundmass', poundmasses: 'poundmass', hundredweights: 'hundredweight', sticks: 'stick', @@ -2353,10 +2374,17 @@ function factory (type, config, load, typed) { hours: 'hour', days: 'day', + radian: 'rad', radians: 'rad', + degree: 'deg', degrees: 'deg', - gradients: 'grad', + gradian: 'grad', + gradians: 'grad', cycles: 'cycle', + arcsecond: 'arcsec', + arcseconds: 'arcsec', + arcminute: 'arcmin', + arcminutes: 'arcmin', BTUs: 'BTU', watts: 'watt', @@ -2481,23 +2509,16 @@ function factory (type, config, load, typed) { unit.dimensions = unit.base.dimensions; } - for (var name in PLURALS) { + for (var name in ALIASES) { /* istanbul ignore next (we cannot really test next statement) */ - if (PLURALS.hasOwnProperty(name)) { - var unit = UNITS[PLURALS[name]]; - var plural = Object.create(unit); - plural.name = name; - UNITS[name] = plural; + if (ALIASES.hasOwnProperty(name)) { + var unit = UNITS[ALIASES[name]]; + var alias = Object.create(unit); + alias.name = name; + UNITS[name] = alias; } } - // aliases - UNITS.lt = UNITS.l; - UNITS.liter = UNITS.litre; - UNITS.liters = UNITS.litres; - UNITS.lb = UNITS.lbm; - UNITS.lbs = UNITS.lbm; - Unit.PREFIXES = PREFIXES; Unit.BASE_UNITS = BASE_UNITS; Unit.UNITS = UNITS; From 0851ffc28cec085bf15bfeacf339bbb8b515b1f4 Mon Sep 17 00:00:00 2001 From: devdevdata222 Date: Mon, 16 Nov 2015 14:10:15 -0500 Subject: [PATCH 2/5] Fix alias for lbs Incorrectly transferred lbs alias. --- lib/type/unit/Unit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/type/unit/Unit.js b/lib/type/unit/Unit.js index c0f9e4c1d..f36d14c02 100644 --- a/lib/type/unit/Unit.js +++ b/lib/type/unit/Unit.js @@ -2364,7 +2364,7 @@ function factory (type, config, load, typed) { drams: 'dram', ounces: 'ounce', lb: 'poundmass', - lbm: 'poundmass', + lbs: 'poundmass', poundmasses: 'poundmass', hundredweights: 'hundredweight', sticks: 'stick', From f2843a65e67e81302d0c20fc5181a6ce2c474d14 Mon Sep 17 00:00:00 2001 From: devdevdata222 Date: Mon, 16 Nov 2015 14:19:59 -0500 Subject: [PATCH 3/5] Forgot alias l -> litre In moving the hard-coded aliases to the aliases array I forgot to set l -> base unit defined by name 'litre'. --- lib/type/unit/Unit.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/type/unit/Unit.js b/lib/type/unit/Unit.js index f36d14c02..b70770a59 100644 --- a/lib/type/unit/Unit.js +++ b/lib/type/unit/Unit.js @@ -2338,6 +2338,7 @@ function factory (type, config, load, typed) { chains: 'chain', angstroms: 'angstrom', + l: 'litre', lt: 'litre', liter: 'litre', liters: 'litre', From b7e91952a184376070a22b02adc9c47911799621 Mon Sep 17 00:00:00 2001 From: devdevdata222 Date: Mon, 16 Nov 2015 14:42:42 -0500 Subject: [PATCH 4/5] Fix alias definitions The hard-coded aliases needed to be matched to specific units in ALIASES. --- lib/type/unit/Unit.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/type/unit/Unit.js b/lib/type/unit/Unit.js index b70770a59..9bc89c0b0 100644 --- a/lib/type/unit/Unit.js +++ b/lib/type/unit/Unit.js @@ -2338,10 +2338,9 @@ function factory (type, config, load, typed) { chains: 'chain', angstroms: 'angstrom', - l: 'litre', - lt: 'litre', + lt: 'l', liter: 'litre', - liters: 'litre', + liters: 'litre' litres: 'litre', teaspoons: 'teaspoon', tablespoons: 'tablespoon', @@ -2364,8 +2363,8 @@ function factory (type, config, load, typed) { grains: 'grain', drams: 'dram', ounces: 'ounce', - lb: 'poundmass', - lbs: 'poundmass', + lb: 'lbm', + lbs: 'lbm', poundmasses: 'poundmass', hundredweights: 'hundredweight', sticks: 'stick', @@ -2519,7 +2518,7 @@ function factory (type, config, load, typed) { UNITS[name] = alias; } } - + Unit.PREFIXES = PREFIXES; Unit.BASE_UNITS = BASE_UNITS; Unit.UNITS = UNITS; From 82d1057128bd8c143e3ac1c7b99feaf1878c6d08 Mon Sep 17 00:00:00 2001 From: devdevdata222 Date: Mon, 16 Nov 2015 15:09:52 -0500 Subject: [PATCH 5/5] Restore original aliases Need the hard-coded aliases at the end, presumably; I had tried to remove them and incorporate them in ALIASES, did not work. --- lib/type/unit/Unit.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/type/unit/Unit.js b/lib/type/unit/Unit.js index 9bc89c0b0..8604f4487 100644 --- a/lib/type/unit/Unit.js +++ b/lib/type/unit/Unit.js @@ -2338,9 +2338,6 @@ function factory (type, config, load, typed) { chains: 'chain', angstroms: 'angstrom', - lt: 'l', - liter: 'litre', - liters: 'litre' litres: 'litre', teaspoons: 'teaspoon', tablespoons: 'tablespoon', @@ -2363,8 +2360,6 @@ function factory (type, config, load, typed) { grains: 'grain', drams: 'dram', ounces: 'ounce', - lb: 'lbm', - lbs: 'lbm', poundmasses: 'poundmass', hundredweights: 'hundredweight', sticks: 'stick', @@ -2519,6 +2514,13 @@ function factory (type, config, load, typed) { } } + // aliases + UNITS.lt = UNITS.l; + UNITS.liter = UNITS.litre; + UNITS.liters = UNITS.litres; + UNITS.lb = UNITS.lbm; + UNITS.lbs = UNITS.lbm; + Unit.PREFIXES = PREFIXES; Unit.BASE_UNITS = BASE_UNITS; Unit.UNITS = UNITS;