@axium/core 0.3.0 → 0.4.1

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.
@@ -0,0 +1,7 @@
1
+ export declare function formatDateRange(date: Date): string;
2
+ export declare function formatBytes(bytes: number): string;
3
+ declare const _default: {
4
+ dateRange: typeof formatDateRange;
5
+ bytes: typeof formatBytes;
6
+ };
7
+ export default _default;
package/dist/format.js ADDED
@@ -0,0 +1,17 @@
1
+ export function formatDateRange(date) {
2
+ const rawDays = (date.getTime() - Date.now()) / (24 * 3600_000);
3
+ const daysCount = Math.abs(rawDays);
4
+ const daysText = Number.isInteger(daysCount) ? daysCount : daysCount.toFixed(1);
5
+ const plural = daysCount == 1 ? '' : 's';
6
+ return `${date.toLocaleString()} (${rawDays >= 0 ? `in ${daysText} day${plural}` : `${daysText} day${plural} ago`})`;
7
+ }
8
+ export function formatBytes(bytes) {
9
+ const units = ['B', 'KB', 'MB', 'GB', 'TB'];
10
+ const i = bytes == 0 ? 0 : Math.floor(Math.log10(bytes) / 3);
11
+ const value = bytes == 0 ? 0 : bytes / Math.pow(1000, i);
12
+ return `${Number.isInteger(value) ? value : value.toFixed(2)} ${units[i]}`;
13
+ }
14
+ export default {
15
+ dateRange: formatDateRange,
16
+ bytes: formatBytes,
17
+ };
package/dist/user.d.ts CHANGED
@@ -11,11 +11,14 @@ export declare const User: z.ZodObject<{
11
11
  email: z.ZodEmail;
12
12
  emailVerified: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
13
13
  image: z.ZodOptional<z.ZodNullable<z.ZodURL>>;
14
+ preferences: z.ZodRecord<z.ZodString, z.ZodAny>;
15
+ roles: z.ZodArray<z.ZodString>;
16
+ registeredAt: z.ZodDate;
14
17
  }, z.core.$strip>;
15
18
  export interface User extends z.infer<typeof User> {
16
- preferences?: Preferences;
19
+ preferences: Preferences;
17
20
  }
18
- export declare const userPublicFields: ["id", "image", "name"];
21
+ export declare const userPublicFields: ["id", "image", "name", "registeredAt", "roles"];
19
22
  type UserPublicField = (typeof userPublicFields)[number];
20
23
  export interface UserPublic extends Pick<User, UserPublicField> {
21
24
  }
@@ -24,6 +27,7 @@ export declare const UserChangeable: z.ZodObject<{
24
27
  email: z.ZodOptional<z.ZodEmail>;
25
28
  name: z.ZodOptional<z.ZodString>;
26
29
  image: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodURL>>>;
30
+ preferences: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
27
31
  }, z.core.$strip>;
28
32
  export type UserChangeable = z.infer<typeof UserChangeable>;
29
33
  export declare function getUserImage(user: {
package/dist/user.js CHANGED
@@ -5,13 +5,17 @@ export const User = z.object({
5
5
  email: z.email(),
6
6
  emailVerified: z.date().nullable().optional(),
7
7
  image: z.url().nullable().optional(),
8
+ preferences: z.record(z.string(), z.any()),
9
+ roles: z.array(z.string()),
10
+ registeredAt: z.date(),
8
11
  });
9
- export const userPublicFields = ['id', 'image', 'name'];
12
+ export const userPublicFields = ['id', 'image', 'name', 'registeredAt', 'roles'];
10
13
  export const userProtectedFields = ['email', 'emailVerified', 'preferences'];
11
14
  export const UserChangeable = User.pick({
12
15
  name: true,
13
16
  email: true,
14
17
  image: true,
18
+ preferences: true,
15
19
  }).partial();
16
20
  export function getUserImage(user) {
17
21
  if (user.image)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axium/core",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "author": "James Prevett <axium@jamespre.dev> (https://jamespre.dev)",
5
5
  "funding": {
6
6
  "type": "individual",