added week and months to unit plugin
This commit is contained in:
parent
37b300b8e9
commit
602e92f986
2 changed files with 13 additions and 3 deletions
|
|
@ -29,7 +29,7 @@ const TEMP_UNIT_DEG = '°\\s*[FfCc]';
|
|||
const TEMP_UNIT_BARE = '[FfCc]';
|
||||
const WEIGHT_UNIT = '(?:kg|g|oz|lbs?|ounces?|pounds?)';
|
||||
const VOLUME_UNIT = '(?:cups?|tablespoons?|table\\s+spoons?|tbsp|teaspoons?|tsp|ml|mL|L|liters?|litres?|quarts?|gallons?|pints?|fl\\.?\\s*oz|fluid\\s+ounces?|parts\\s+by\\s+(?:volume|weight))';
|
||||
const TIME_UNIT = '(?:minutes?|mins?|hours?|hrs?|days?|seconds?|secs?)';
|
||||
const TIME_UNIT = '(?:minutes?|mins?|hours?|hrs?|days?|weeks?|months?|seconds?|secs?)';
|
||||
const DIM_UNIT = '(?:inch(?:es)?|in\\.?|cm|mm)';
|
||||
|
||||
// ─── Amount Parsing ───────────────────────────────────────
|
||||
|
|
@ -189,6 +189,8 @@ function normalizeUnit(unit) {
|
|||
if (/^minutes?$/.test(u) || /^mins?$/.test(u)) return 'minute';
|
||||
if (/^hours?$/.test(u) || /^hrs?$/.test(u)) return 'hour';
|
||||
if (/^days?$/.test(u)) return 'day';
|
||||
if (/^weeks?$/.test(u)) return 'week';
|
||||
if (/^months?$/.test(u)) return 'month';
|
||||
if (/^seconds?$/.test(u) || /^secs?$/.test(u)) return 'second';
|
||||
|
||||
// Dimension units
|
||||
|
|
@ -206,7 +208,7 @@ function unitType(normalizedUnit) {
|
|||
if (['°F', '°C'].includes(normalizedUnit)) return 'temperature';
|
||||
if (['g', 'kg', 'oz', 'lb'].includes(normalizedUnit)) return 'weight';
|
||||
if (['cup', 'tablespoon', 'teaspoon', 'ml', 'L', 'quart', 'gallon', 'pint', 'fl oz', 'parts by volume', 'parts by weight'].includes(normalizedUnit)) return 'volume';
|
||||
if (['minute', 'hour', 'day', 'second'].includes(normalizedUnit)) return 'time';
|
||||
if (['minute', 'hour', 'day', 'week', 'month', 'second'].includes(normalizedUnit)) return 'time';
|
||||
if (['inch', 'cm', 'mm', 'ft'].includes(normalizedUnit)) return 'dimension';
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue