@cohostvip/cohost-react 0.1.11 → 0.1.12
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/types/index.d.ts +41 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +1 -0
- package/dist/utils/cost.d.ts +7 -0
- package/dist/utils/cost.d.ts.map +1 -0
- package/dist/utils/cost.js +31 -0
- package/dist/utils/dates.d.ts +3 -0
- package/dist/utils/dates.d.ts.map +1 -0
- package/dist/utils/dates.js +37 -0
- package/package.json +4 -4
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A pre-parsed human-friendly representation of a date and time.
|
|
3
|
+
*/
|
|
4
|
+
export interface StructuredDate {
|
|
5
|
+
/** Formatted date strings. */
|
|
6
|
+
date: {
|
|
7
|
+
/** Full format, e.g., "Tuesday, October 3". */
|
|
8
|
+
EEEEMMMMd: string;
|
|
9
|
+
/** Short weekday/month/day, e.g., "Tue, Oct. 3". */
|
|
10
|
+
EEEMMMd: string;
|
|
11
|
+
/** Long date format, e.g., "Tuesday, October 3, 2023". */
|
|
12
|
+
long: string;
|
|
13
|
+
/** Short numeric format, e.g., "10/03/2023". */
|
|
14
|
+
short: string;
|
|
15
|
+
};
|
|
16
|
+
/** Time string (e.g., "3:00 PM"). */
|
|
17
|
+
time: string;
|
|
18
|
+
/** UTC timestamp (e.g., "2006-10-25T12:00:00Z"). */
|
|
19
|
+
utc: string;
|
|
20
|
+
/** IANA timezone (e.g., "America/New_York"). */
|
|
21
|
+
timezone: string;
|
|
22
|
+
/** Local timestamp (e.g., "2006-10-25T12:00:00-04:00"). */
|
|
23
|
+
local: string;
|
|
24
|
+
/** Whether this date is in the future. */
|
|
25
|
+
upcoming: boolean;
|
|
26
|
+
/** Duration details from now to the date. */
|
|
27
|
+
duration: {
|
|
28
|
+
days: number;
|
|
29
|
+
hours: number;
|
|
30
|
+
minutes: number;
|
|
31
|
+
weeks: number;
|
|
32
|
+
months: number;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export interface StructuredCost {
|
|
36
|
+
currency: string;
|
|
37
|
+
formatted: string;
|
|
38
|
+
value: number;
|
|
39
|
+
majorValue: number;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AACA;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,8BAA8B;IAC9B,IAAI,EAAE;QACJ,+CAA+C;QAC/C,SAAS,EAAE,MAAM,CAAC;QAElB,oDAAoD;QACpD,OAAO,EAAE,MAAM,CAAC;QAEhB,0DAA0D;QAC1D,IAAI,EAAE,MAAM,CAAC;QAEb,gDAAgD;QAChD,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;IAEF,qCAAqC;IACrC,IAAI,EAAE,MAAM,CAAC;IAEb,oDAAoD;IACpD,GAAG,EAAE,MAAM,CAAC;IAEZ,gDAAgD;IAChD,QAAQ,EAAE,MAAM,CAAC;IAEjB,2DAA2D;IAC3D,KAAK,EAAE,MAAM,CAAC;IAEd,0CAA0C;IAC1C,QAAQ,EAAE,OAAO,CAAC;IAElB,6CAA6C;IAC7C,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH;AAGD,MAAM,WAAW,cAAc;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;CACtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { StructuredCost } from "../types";
|
|
2
|
+
export declare const formatCost: (currency: string, amount: number, option?: {
|
|
3
|
+
valueBase?: "major" | "minor";
|
|
4
|
+
}) => string;
|
|
5
|
+
export declare const toStructuredCost: (cost: string) => StructuredCost | undefined;
|
|
6
|
+
export declare const toStructuredCosts: <T extends { [K in keyof T]: string; }>(costs: T) => { [K in keyof T]: StructuredCost | null; };
|
|
7
|
+
//# sourceMappingURL=cost.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cost.d.ts","sourceRoot":"","sources":["../../src/utils/cost.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAG1C,eAAO,MAAM,UAAU,GAAI,UAAU,MAAM,EAAE,QAAQ,MAAM,EAAE,SAAS;IAClE,SAAS,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC;CACjC,KAAG,MAAyF,CAAC;AAO9F,eAAO,MAAM,gBAAgB,GAAI,MAAM,MAAM,KAAG,cAAc,GAAG,SAoBhE,CAAC;AAGF,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,GAAG,CAAC,IAAI,MAAM,CAAC,GAAG,MAAM,GAAE,EAClE,OAAO,CAAC,KACT,GAAG,CAAC,IAAI,MAAM,CAAC,GAAG,cAAc,GAAG,IAAI,GASzC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export const formatCost = (currency, amount, option) => `${currency},${Math.round(amount * (option?.valueBase === 'major' ? 100 : 1))}`;
|
|
2
|
+
const costValue = (cost) => {
|
|
3
|
+
const [currency, value] = cost.split(",");
|
|
4
|
+
return Number(value);
|
|
5
|
+
};
|
|
6
|
+
export const toStructuredCost = (cost) => {
|
|
7
|
+
if (!cost || !cost.includes(","))
|
|
8
|
+
return undefined;
|
|
9
|
+
const [currency, strValue] = cost.split(",");
|
|
10
|
+
const value = Number(strValue);
|
|
11
|
+
const majorValue = value / 100;
|
|
12
|
+
const formatted = majorValue.toLocaleString("en-US", {
|
|
13
|
+
style: "currency",
|
|
14
|
+
currency,
|
|
15
|
+
// minimumFractionDigits: 0
|
|
16
|
+
});
|
|
17
|
+
return {
|
|
18
|
+
currency,
|
|
19
|
+
value,
|
|
20
|
+
majorValue,
|
|
21
|
+
formatted,
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export const toStructuredCosts = (costs) => {
|
|
25
|
+
const result = {};
|
|
26
|
+
for (const key in costs) {
|
|
27
|
+
const cost = costs[key];
|
|
28
|
+
result[key] = toStructuredCost(cost) ?? null;
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dates.d.ts","sourceRoot":"","sources":["../../src/utils/dates.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAGnE,eAAO,MAAM,iBAAiB,GAC1B,OAAO,IAAI,GAAG,MAAM,EACpB,UAAU,MAAM,GAAG,IAAI,KACxB,cA4CF,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { DateTime } from 'luxon';
|
|
2
|
+
export const getStructuredDate = (input, timezone) => {
|
|
3
|
+
// Convert to Luxon DateTime, assuming input is UTC if string
|
|
4
|
+
const parsed = typeof input === 'string'
|
|
5
|
+
? DateTime.fromISO(input, { zone: 'utc' }).setZone(timezone || DateTime.local().zoneName)
|
|
6
|
+
: DateTime.fromJSDate(input, { zone: timezone || DateTime.local().zoneName });
|
|
7
|
+
// Check for invalid date
|
|
8
|
+
if (!parsed.isValid) {
|
|
9
|
+
throw new Error(`Invalid date input: "${input}". Details: ${parsed.invalidExplanation}`);
|
|
10
|
+
}
|
|
11
|
+
// Check for invalid timezone (e.g., if Luxon silently falls back to local)
|
|
12
|
+
if (timezone !== null && parsed.zoneName !== timezone) {
|
|
13
|
+
throw new Error(`Invalid timezone: "${timezone}"`);
|
|
14
|
+
}
|
|
15
|
+
const now = DateTime.now();
|
|
16
|
+
const diff = parsed.diff(now, ['days', 'hours', 'minutes', 'months', 'weeks']);
|
|
17
|
+
return {
|
|
18
|
+
duration: {
|
|
19
|
+
days: diff.days,
|
|
20
|
+
hours: diff.hours,
|
|
21
|
+
minutes: diff.minutes,
|
|
22
|
+
weeks: diff.weeks,
|
|
23
|
+
months: diff.months,
|
|
24
|
+
},
|
|
25
|
+
upcoming: parsed > now,
|
|
26
|
+
date: {
|
|
27
|
+
EEEEMMMMd: parsed.toFormat('EEEE, MMMM d'),
|
|
28
|
+
EEEMMMd: parsed.toFormat("EEE, MMM'.' d"),
|
|
29
|
+
long: parsed.toFormat('EEEE, MMMM d, yyyy'),
|
|
30
|
+
short: parsed.toFormat('MM/dd/yyyy'),
|
|
31
|
+
},
|
|
32
|
+
time: parsed.toFormat('h:mm a'),
|
|
33
|
+
utc: parsed.toUTC().toISO() ?? '',
|
|
34
|
+
timezone: parsed.zoneName,
|
|
35
|
+
local: parsed.toISO() ?? '',
|
|
36
|
+
};
|
|
37
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cohostvip/cohost-react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
4
4
|
"description": "React bindings for the Cohost API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"react-dom": "^18.0.0 || ^19.0.0"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@cohostvip/cohost-node": "
|
|
30
|
+
"@cohostvip/cohost-node": "workspace:^"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@testing-library/jest-dom": "6.6.3",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"@types/react": "19.0.10",
|
|
36
36
|
"@types/react-dom": "19.0.4",
|
|
37
37
|
"jsdom": "26.0.0",
|
|
38
|
-
"typescript": "
|
|
39
|
-
"vitest": "^3.
|
|
38
|
+
"typescript": "5.8.2",
|
|
39
|
+
"vitest": "^3.2.0"
|
|
40
40
|
},
|
|
41
41
|
"repository": {
|
|
42
42
|
"type": "git",
|