@supercmd/calculator 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1798,7 +1798,7 @@ var TIME_IN_PATTERNS = [
1798
1798
  /^(?:what time is it|whats the time|what is the time|current time|time now) (?:in|at) (.+)$/i,
1799
1799
  /^(?:now|current time) in (.+)$/i
1800
1800
  ];
1801
- var TIME_EXPLICIT_CONVERT_PATTERN = /^(midnight|noon|\d{1,2}(?::\d{2})?(?:\s*(?:am|pm))?)\s+(.+?)\s+to\s+(.+?)$/i;
1801
+ var TIME_EXPLICIT_CONVERT_PATTERN = /^(midnight|noon|\d{1,2}(?::\d{2})?(?:\s*(?:am|pm))?)\s+(?:in\s+)?(.+?)\s+to\s+(.+?)(?:\s+time)?$/i;
1802
1802
  var TIME_CONVERT_PATTERN = /^(.+?) to (.+?)(?: time)?$/i;
1803
1803
  var TIME_NOW_PATTERN = /^(?:what(?:'s| is) )?(?:the )?(?:current )?time(?: now)?$/i;
1804
1804
  function tryTimeIntent(input) {
@@ -1806,7 +1806,7 @@ function tryTimeIntent(input) {
1806
1806
  for (const pattern of TIME_IN_PATTERNS) {
1807
1807
  match = input.match(pattern);
1808
1808
  if (match) {
1809
- const place = match[1].trim();
1809
+ const place = normalizeTimePlace(match[1]);
1810
1810
  const tz2 = resolveTimezone(place);
1811
1811
  if (tz2) return { kind: "time", query: input, to: tz2 };
1812
1812
  return { kind: "time", query: input, to: place };
@@ -1815,8 +1815,8 @@ function tryTimeIntent(input) {
1815
1815
  match = input.match(TIME_EXPLICIT_CONVERT_PATTERN);
1816
1816
  if (match) {
1817
1817
  const time = match[1].trim();
1818
- const from = match[2].trim();
1819
- const to = match[3].trim();
1818
+ const from = normalizeTimePlace(match[2]);
1819
+ const to = normalizeTimePlace(match[3]);
1820
1820
  const fromTz = resolveTimezone(from);
1821
1821
  const toTz = resolveTimezone(to);
1822
1822
  if (fromTz && toTz) {
@@ -1825,8 +1825,8 @@ function tryTimeIntent(input) {
1825
1825
  }
1826
1826
  match = input.match(TIME_CONVERT_PATTERN);
1827
1827
  if (match) {
1828
- const from = match[1].trim();
1829
- const to = match[2].trim();
1828
+ const from = normalizeTimePlace(match[1]);
1829
+ const to = normalizeTimePlace(match[2]);
1830
1830
  const fromTz = resolveTimezone(from);
1831
1831
  const toTz = resolveTimezone(to);
1832
1832
  if (fromTz || toTz) {
@@ -1842,11 +1842,11 @@ function tryTimeIntent(input) {
1842
1842
  }
1843
1843
  const placeSuffixMatch = input.match(/^(.+?)\s+(?:time|now|time now)$/i);
1844
1844
  if (placeSuffixMatch) {
1845
- const place = placeSuffixMatch[1].trim();
1845
+ const place = normalizeTimePlace(placeSuffixMatch[1]);
1846
1846
  const tz2 = resolveTimezone(place);
1847
1847
  if (tz2) return { kind: "time", query: place, to: tz2 };
1848
1848
  }
1849
- const tz = resolveTimezone(input);
1849
+ const tz = resolveTimezone(normalizeTimePlace(input));
1850
1850
  if (tz) {
1851
1851
  return { kind: "time", query: input, to: tz };
1852
1852
  }
@@ -1936,6 +1936,9 @@ function normalizeConversionInput(input) {
1936
1936
  normalized = normalized.replace(/^([$€£¥₹₩₽₺₦₵₪฿])\s*([\d.,]+)/, "$2 $1");
1937
1937
  return normalized;
1938
1938
  }
1939
+ function normalizeTimePlace(value) {
1940
+ return normalizeWhitespace(value).replace(/^(?:time|current time|time now|now)\s+(?:in|at)\s+/i, "").replace(/^(?:in|at)\s+/i, "").replace(/\s+(?:time|now|time now)$/i, "").trim();
1941
+ }
1939
1942
 
1940
1943
  // src/evaluators/math.ts
1941
1944
  var CONSTANTS = {
package/dist/index.mjs CHANGED
@@ -1761,7 +1761,7 @@ var TIME_IN_PATTERNS = [
1761
1761
  /^(?:what time is it|whats the time|what is the time|current time|time now) (?:in|at) (.+)$/i,
1762
1762
  /^(?:now|current time) in (.+)$/i
1763
1763
  ];
1764
- var TIME_EXPLICIT_CONVERT_PATTERN = /^(midnight|noon|\d{1,2}(?::\d{2})?(?:\s*(?:am|pm))?)\s+(.+?)\s+to\s+(.+?)$/i;
1764
+ var TIME_EXPLICIT_CONVERT_PATTERN = /^(midnight|noon|\d{1,2}(?::\d{2})?(?:\s*(?:am|pm))?)\s+(?:in\s+)?(.+?)\s+to\s+(.+?)(?:\s+time)?$/i;
1765
1765
  var TIME_CONVERT_PATTERN = /^(.+?) to (.+?)(?: time)?$/i;
1766
1766
  var TIME_NOW_PATTERN = /^(?:what(?:'s| is) )?(?:the )?(?:current )?time(?: now)?$/i;
1767
1767
  function tryTimeIntent(input) {
@@ -1769,7 +1769,7 @@ function tryTimeIntent(input) {
1769
1769
  for (const pattern of TIME_IN_PATTERNS) {
1770
1770
  match = input.match(pattern);
1771
1771
  if (match) {
1772
- const place = match[1].trim();
1772
+ const place = normalizeTimePlace(match[1]);
1773
1773
  const tz2 = resolveTimezone(place);
1774
1774
  if (tz2) return { kind: "time", query: input, to: tz2 };
1775
1775
  return { kind: "time", query: input, to: place };
@@ -1778,8 +1778,8 @@ function tryTimeIntent(input) {
1778
1778
  match = input.match(TIME_EXPLICIT_CONVERT_PATTERN);
1779
1779
  if (match) {
1780
1780
  const time = match[1].trim();
1781
- const from = match[2].trim();
1782
- const to = match[3].trim();
1781
+ const from = normalizeTimePlace(match[2]);
1782
+ const to = normalizeTimePlace(match[3]);
1783
1783
  const fromTz = resolveTimezone(from);
1784
1784
  const toTz = resolveTimezone(to);
1785
1785
  if (fromTz && toTz) {
@@ -1788,8 +1788,8 @@ function tryTimeIntent(input) {
1788
1788
  }
1789
1789
  match = input.match(TIME_CONVERT_PATTERN);
1790
1790
  if (match) {
1791
- const from = match[1].trim();
1792
- const to = match[2].trim();
1791
+ const from = normalizeTimePlace(match[1]);
1792
+ const to = normalizeTimePlace(match[2]);
1793
1793
  const fromTz = resolveTimezone(from);
1794
1794
  const toTz = resolveTimezone(to);
1795
1795
  if (fromTz || toTz) {
@@ -1805,11 +1805,11 @@ function tryTimeIntent(input) {
1805
1805
  }
1806
1806
  const placeSuffixMatch = input.match(/^(.+?)\s+(?:time|now|time now)$/i);
1807
1807
  if (placeSuffixMatch) {
1808
- const place = placeSuffixMatch[1].trim();
1808
+ const place = normalizeTimePlace(placeSuffixMatch[1]);
1809
1809
  const tz2 = resolveTimezone(place);
1810
1810
  if (tz2) return { kind: "time", query: place, to: tz2 };
1811
1811
  }
1812
- const tz = resolveTimezone(input);
1812
+ const tz = resolveTimezone(normalizeTimePlace(input));
1813
1813
  if (tz) {
1814
1814
  return { kind: "time", query: input, to: tz };
1815
1815
  }
@@ -1899,6 +1899,9 @@ function normalizeConversionInput(input) {
1899
1899
  normalized = normalized.replace(/^([$€£¥₹₩₽₺₦₵₪฿])\s*([\d.,]+)/, "$2 $1");
1900
1900
  return normalized;
1901
1901
  }
1902
+ function normalizeTimePlace(value) {
1903
+ return normalizeWhitespace(value).replace(/^(?:time|current time|time now|now)\s+(?:in|at)\s+/i, "").replace(/^(?:in|at)\s+/i, "").replace(/\s+(?:time|now|time now)$/i, "").trim();
1904
+ }
1902
1905
 
1903
1906
  // src/evaluators/math.ts
1904
1907
  var CONSTANTS = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supercmd/calculator",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Powerful natural language calculator — math, units, currency, crypto, time zones, dates",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",