@storyteller-platform/align 0.1.24 → 0.1.25

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.
@@ -25,16 +25,16 @@ var import_locale_currency = require("locale-currency");
25
25
  var import_to_words = require("to-words");
26
26
  var import_transliteration = require("@storyteller-platform/transliteration");
27
27
  const replacerMap = /* @__PURE__ */ new WeakMap();
28
- function createReplacers(locale) {
29
- const maximizedLocale = locale.maximize();
28
+ function getCurrencySymbols(locale) {
29
+ const region = locale.maximize().region;
30
30
  const demoNumber = 123456.789;
31
31
  const currencyFormat = new Intl.NumberFormat(locale, {
32
32
  style: "currency",
33
33
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
34
- currency: (0, import_locale_currency.getCurrency)(locale.maximize().region)
34
+ currency: region ? (0, import_locale_currency.getCurrency)(locale.maximize().region) : "USD"
35
35
  });
36
36
  const currencyParts = currencyFormat.formatToParts(demoNumber);
37
- const currencySymbols = currencyParts.reduce(
37
+ return currencyParts.reduce(
38
38
  (acc, part, index) => {
39
39
  if (part.type === "group") {
40
40
  return {
@@ -59,27 +59,12 @@ function createReplacers(locale) {
59
59
  },
60
60
  { group: "", decimal: "", currency: "", currencyLeading: true }
61
61
  );
62
- const numeralRegexPart = `(\\p{Number}[\\p{Number}${currencySymbols.group}]*(?:[${currencySymbols.decimal}]\\p{Number}*)?)`;
63
- const currencyRegex = currencySymbols.currencyLeading ? new RegExp(`[${currencySymbols.currency}]\\s?${numeralRegexPart}`, "gu") : new RegExp(`${numeralRegexPart}\\s?[${currencySymbols.currency}]`, "gu");
64
- function currencyReplacer(match) {
65
- const numeralMatch = match[1];
66
- if (!numeralMatch) return match[0];
67
- const normalizedNumeral = numeralMatch.replaceAll(new RegExp(`\\${currencySymbols.group}`, "g"), "").replace(new RegExp(`\\${currencySymbols.decimal}`), ".");
68
- const number = parseFloat(normalizedNumeral);
69
- if (Number.isNaN(number)) return match[0];
70
- try {
71
- return (0, import_to_words.toWords)(number, {
72
- localeCode: `${maximizedLocale.language}-${maximizedLocale.region}`,
73
- currency: true,
74
- doNotAddOnly: true
75
- });
76
- } catch {
77
- return match[0];
78
- }
79
- }
62
+ }
63
+ function getNumberSymbols(locale) {
64
+ const demoNumber = 123456.789;
80
65
  const numberFormat = new Intl.NumberFormat(locale);
81
66
  const numberParts = numberFormat.formatToParts(demoNumber);
82
- const numberSymbols = numberParts.reduce(
67
+ return numberParts.reduce(
83
68
  (acc, part) => {
84
69
  if (part.type === "group") {
85
70
  return {
@@ -97,6 +82,29 @@ function createReplacers(locale) {
97
82
  },
98
83
  { group: "", decimal: "" }
99
84
  );
85
+ }
86
+ function createReplacers(locale) {
87
+ const maximizedLocale = locale.maximize();
88
+ const currencySymbols = getCurrencySymbols(maximizedLocale);
89
+ const numeralRegexPart = `(\\p{Number}[\\p{Number}${currencySymbols.group}]*(?:[${currencySymbols.decimal}]\\p{Number}*)?)`;
90
+ const currencyRegex = currencySymbols.currencyLeading ? new RegExp(`[${currencySymbols.currency}]\\s?${numeralRegexPart}`, "gu") : new RegExp(`${numeralRegexPart}\\s?[${currencySymbols.currency}]`, "gu");
91
+ function currencyReplacer(match) {
92
+ const numeralMatch = match[1];
93
+ if (!numeralMatch) return match[0];
94
+ const normalizedNumeral = numeralMatch.replaceAll(new RegExp(`\\${currencySymbols.group}`, "g"), "").replace(new RegExp(`\\${currencySymbols.decimal}`), ".");
95
+ const number = parseFloat(normalizedNumeral);
96
+ if (Number.isNaN(number)) return match[0];
97
+ try {
98
+ return (0, import_to_words.toWords)(number, {
99
+ localeCode: `${maximizedLocale.language}-${maximizedLocale.region}`,
100
+ currency: true,
101
+ doNotAddOnly: true
102
+ });
103
+ } catch {
104
+ return match[0];
105
+ }
106
+ }
107
+ const numberSymbols = getNumberSymbols(maximizedLocale);
100
108
  const numberRegex = new RegExp(
101
109
  `(\\p{Number}[\\p{Number}${numberSymbols.group}]*(?:[${numberSymbols.decimal}]\\p{Number}*)?)`,
102
110
  "gu"
@@ -3,16 +3,16 @@ import { getCurrency } from "locale-currency";
3
3
  import { toWords } from "to-words";
4
4
  import { slugify as transliterateSlugify } from "@storyteller-platform/transliteration";
5
5
  const replacerMap = /* @__PURE__ */ new WeakMap();
6
- function createReplacers(locale) {
7
- const maximizedLocale = locale.maximize();
6
+ function getCurrencySymbols(locale) {
7
+ const region = locale.maximize().region;
8
8
  const demoNumber = 123456.789;
9
9
  const currencyFormat = new Intl.NumberFormat(locale, {
10
10
  style: "currency",
11
11
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
12
- currency: getCurrency(locale.maximize().region)
12
+ currency: region ? getCurrency(locale.maximize().region) : "USD"
13
13
  });
14
14
  const currencyParts = currencyFormat.formatToParts(demoNumber);
15
- const currencySymbols = currencyParts.reduce(
15
+ return currencyParts.reduce(
16
16
  (acc, part, index) => {
17
17
  if (part.type === "group") {
18
18
  return {
@@ -37,27 +37,12 @@ function createReplacers(locale) {
37
37
  },
38
38
  { group: "", decimal: "", currency: "", currencyLeading: true }
39
39
  );
40
- const numeralRegexPart = `(\\p{Number}[\\p{Number}${currencySymbols.group}]*(?:[${currencySymbols.decimal}]\\p{Number}*)?)`;
41
- const currencyRegex = currencySymbols.currencyLeading ? new RegExp(`[${currencySymbols.currency}]\\s?${numeralRegexPart}`, "gu") : new RegExp(`${numeralRegexPart}\\s?[${currencySymbols.currency}]`, "gu");
42
- function currencyReplacer(match) {
43
- const numeralMatch = match[1];
44
- if (!numeralMatch) return match[0];
45
- const normalizedNumeral = numeralMatch.replaceAll(new RegExp(`\\${currencySymbols.group}`, "g"), "").replace(new RegExp(`\\${currencySymbols.decimal}`), ".");
46
- const number = parseFloat(normalizedNumeral);
47
- if (Number.isNaN(number)) return match[0];
48
- try {
49
- return toWords(number, {
50
- localeCode: `${maximizedLocale.language}-${maximizedLocale.region}`,
51
- currency: true,
52
- doNotAddOnly: true
53
- });
54
- } catch {
55
- return match[0];
56
- }
57
- }
40
+ }
41
+ function getNumberSymbols(locale) {
42
+ const demoNumber = 123456.789;
58
43
  const numberFormat = new Intl.NumberFormat(locale);
59
44
  const numberParts = numberFormat.formatToParts(demoNumber);
60
- const numberSymbols = numberParts.reduce(
45
+ return numberParts.reduce(
61
46
  (acc, part) => {
62
47
  if (part.type === "group") {
63
48
  return {
@@ -75,6 +60,29 @@ function createReplacers(locale) {
75
60
  },
76
61
  { group: "", decimal: "" }
77
62
  );
63
+ }
64
+ function createReplacers(locale) {
65
+ const maximizedLocale = locale.maximize();
66
+ const currencySymbols = getCurrencySymbols(maximizedLocale);
67
+ const numeralRegexPart = `(\\p{Number}[\\p{Number}${currencySymbols.group}]*(?:[${currencySymbols.decimal}]\\p{Number}*)?)`;
68
+ const currencyRegex = currencySymbols.currencyLeading ? new RegExp(`[${currencySymbols.currency}]\\s?${numeralRegexPart}`, "gu") : new RegExp(`${numeralRegexPart}\\s?[${currencySymbols.currency}]`, "gu");
69
+ function currencyReplacer(match) {
70
+ const numeralMatch = match[1];
71
+ if (!numeralMatch) return match[0];
72
+ const normalizedNumeral = numeralMatch.replaceAll(new RegExp(`\\${currencySymbols.group}`, "g"), "").replace(new RegExp(`\\${currencySymbols.decimal}`), ".");
73
+ const number = parseFloat(normalizedNumeral);
74
+ if (Number.isNaN(number)) return match[0];
75
+ try {
76
+ return toWords(number, {
77
+ localeCode: `${maximizedLocale.language}-${maximizedLocale.region}`,
78
+ currency: true,
79
+ doNotAddOnly: true
80
+ });
81
+ } catch {
82
+ return match[0];
83
+ }
84
+ }
85
+ const numberSymbols = getNumberSymbols(maximizedLocale);
78
86
  const numberRegex = new RegExp(
79
87
  `(\\p{Number}[\\p{Number}${numberSymbols.group}]*(?:[${numberSymbols.decimal}]\\p{Number}*)?)`,
80
88
  "gu"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storyteller-platform/align",
3
- "version": "0.1.24",
3
+ "version": "0.1.25",
4
4
  "description": "A library and CLI for automatically aligning audiobooks and EPUBs to produce Media Overlays",
5
5
  "author": "Shane Friedman",
6
6
  "license": "MIT",
@@ -60,8 +60,8 @@
60
60
  "@optique/core": "^0.10.7",
61
61
  "@optique/run": "^0.10.7",
62
62
  "@storyteller-platform/audiobook": "^0.3.10",
63
- "@storyteller-platform/epub": "^0.4.9",
64
- "@storyteller-platform/ghost-story": "^0.1.9",
63
+ "@storyteller-platform/epub": "^0.4.10",
64
+ "@storyteller-platform/ghost-story": "^0.1.10",
65
65
  "@storyteller-platform/transliteration": "^3.1.2",
66
66
  "chalk": "^5.4.1",
67
67
  "cli-progress": "^3.12.0",
@@ -74,7 +74,7 @@
74
74
  "pino-pretty": "^13.1.3",
75
75
  "runes2": "^1.1.4",
76
76
  "to-words": "^5.3.0",
77
- "zod": "^3.24.0"
77
+ "zod": "^4.3.6"
78
78
  },
79
79
  "devDependencies": {
80
80
  "@storyteller-platform/eslint": "0.1.0",