aboutsummaryrefslogtreecommitdiffstats
path: root/library/moment/src/lib/units/aliases.js
diff options
context:
space:
mode:
Diffstat (limited to 'library/moment/src/lib/units/aliases.js')
-rw-r--r--library/moment/src/lib/units/aliases.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/library/moment/src/lib/units/aliases.js b/library/moment/src/lib/units/aliases.js
new file mode 100644
index 000000000..4ad513384
--- /dev/null
+++ b/library/moment/src/lib/units/aliases.js
@@ -0,0 +1,29 @@
+import hasOwnProp from '../utils/has-own-prop';
+
+var aliases = {};
+
+export function addUnitAlias (unit, shorthand) {
+ var lowerCase = unit.toLowerCase();
+ aliases[lowerCase] = aliases[lowerCase + 's'] = aliases[shorthand] = unit;
+}
+
+export function normalizeUnits(units) {
+ return typeof units === 'string' ? aliases[units] || aliases[units.toLowerCase()] : undefined;
+}
+
+export function normalizeObjectUnits(inputObject) {
+ var normalizedInput = {},
+ normalizedProp,
+ prop;
+
+ for (prop in inputObject) {
+ if (hasOwnProp(inputObject, prop)) {
+ normalizedProp = normalizeUnits(prop);
+ if (normalizedProp) {
+ normalizedInput[normalizedProp] = inputObject[prop];
+ }
+ }
+ }
+
+ return normalizedInput;
+}