shopeasy-sdk 1.0.0

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.
Files changed (47) hide show
  1. package/README.md +383 -0
  2. package/dist/functions/api/config.cjs +81 -0
  3. package/dist/functions/api/config.mjs +71 -0
  4. package/dist/functions/api/index.cjs +35 -0
  5. package/dist/functions/api/index.mjs +33 -0
  6. package/dist/functions/api/services/carts.service.cjs +64 -0
  7. package/dist/functions/api/services/carts.service.mjs +62 -0
  8. package/dist/functions/api/services/catalog.service.cjs +60 -0
  9. package/dist/functions/api/services/catalog.service.mjs +58 -0
  10. package/dist/functions/api/services/configs.service.cjs +46 -0
  11. package/dist/functions/api/services/configs.service.mjs +44 -0
  12. package/dist/functions/api/services/coupons.service.cjs +54 -0
  13. package/dist/functions/api/services/coupons.service.mjs +52 -0
  14. package/dist/functions/api/services/customer.service.cjs +65 -0
  15. package/dist/functions/api/services/customer.service.mjs +63 -0
  16. package/dist/functions/api/services/images.service.cjs +17 -0
  17. package/dist/functions/api/services/images.service.mjs +15 -0
  18. package/dist/functions/api/services/orders.service.cjs +36 -0
  19. package/dist/functions/api/services/orders.service.mjs +34 -0
  20. package/dist/functions/api/services/payment.service.cjs +26 -0
  21. package/dist/functions/api/services/payment.service.mjs +24 -0
  22. package/dist/functions/api/services/plans.service.cjs +67 -0
  23. package/dist/functions/api/services/plans.service.mjs +65 -0
  24. package/dist/functions/api/services/products.service.cjs +104 -0
  25. package/dist/functions/api/services/products.service.mjs +102 -0
  26. package/dist/functions/api/services/sales.service.cjs +29 -0
  27. package/dist/functions/api/services/sales.service.mjs +27 -0
  28. package/dist/functions/api/services/token.service.cjs +17 -0
  29. package/dist/functions/api/services/token.service.mjs +15 -0
  30. package/dist/functions/api/services/users.service.cjs +13 -0
  31. package/dist/functions/api/services/users.service.mjs +11 -0
  32. package/dist/functions/api/services/wallet.service.cjs +33 -0
  33. package/dist/functions/api/services/wallet.service.mjs +31 -0
  34. package/dist/functions/utils/cart.cjs +53 -0
  35. package/dist/functions/utils/cart.mjs +47 -0
  36. package/dist/functions/utils/formarts.cjs +30 -0
  37. package/dist/functions/utils/formarts.mjs +25 -0
  38. package/dist/functions/utils/permission.cjs +31 -0
  39. package/dist/functions/utils/permission.mjs +29 -0
  40. package/dist/index.cjs +45 -0
  41. package/dist/index.d.cts +766 -0
  42. package/dist/index.d.mts +766 -0
  43. package/dist/index.d.ts +766 -0
  44. package/dist/index.mjs +32 -0
  45. package/dist/tools/pix.cjs +108 -0
  46. package/dist/tools/pix.mjs +101 -0
  47. package/package.json +47 -0
@@ -0,0 +1,67 @@
1
+ 'use strict';
2
+
3
+ const config = require('../config.cjs');
4
+
5
+ class PlansService {
6
+ async getByGuild(guildId) {
7
+ const { data } = await config.api.get(`/plans/${guildId}`);
8
+ return data;
9
+ }
10
+ async havePlan(guildId) {
11
+ const { data } = await config.api.get(`/plans/${guildId}/have`);
12
+ return data;
13
+ }
14
+ async create(args) {
15
+ const { data } = await config.api.post(`/plans`, args);
16
+ return data;
17
+ }
18
+ async getExpiring(days) {
19
+ const params = days ? `?days=${days}` : "";
20
+ const { data } = await config.api.get(`/plans/expiring${params}`);
21
+ return data;
22
+ }
23
+ async getExpired() {
24
+ const { data } = await config.api.get(`/plans/expired`);
25
+ return data;
26
+ }
27
+ async getPlansNeedingAlert(days) {
28
+ const params = days ? `?days=${days}` : "";
29
+ const { data } = await config.api.get(
30
+ `/plans/need-alert${params}`
31
+ );
32
+ return data;
33
+ }
34
+ async markAlertSent(guildId, daysUntilExpire) {
35
+ const { data } = await config.api.post(
36
+ `/plans/${guildId}/mark-alert`,
37
+ { daysUntilExpire }
38
+ );
39
+ return data;
40
+ }
41
+ async checkExpirations() {
42
+ const { data } = await config.api.get(
43
+ `/plans/check-expirations`
44
+ );
45
+ return data;
46
+ }
47
+ async getExpirationStatus(guildId) {
48
+ const { data } = await config.api.get(
49
+ `/plans/${guildId}/expiration-status`
50
+ );
51
+ return data;
52
+ }
53
+ async update(guildId, updates) {
54
+ const { data } = await config.api.patch(`/plans/${guildId}`, updates);
55
+ return data;
56
+ }
57
+ async delete(guildId) {
58
+ await config.api.delete(`/plans/${guildId}`);
59
+ }
60
+ async createSubscription(args) {
61
+ const { data } = await config.api.post("/plans/subscription", args);
62
+ return data;
63
+ }
64
+ }
65
+ const PlanService = new PlansService();
66
+
67
+ module.exports = PlanService;
@@ -0,0 +1,65 @@
1
+ import { api } from '../config.mjs';
2
+
3
+ class PlansService {
4
+ async getByGuild(guildId) {
5
+ const { data } = await api.get(`/plans/${guildId}`);
6
+ return data;
7
+ }
8
+ async havePlan(guildId) {
9
+ const { data } = await api.get(`/plans/${guildId}/have`);
10
+ return data;
11
+ }
12
+ async create(args) {
13
+ const { data } = await api.post(`/plans`, args);
14
+ return data;
15
+ }
16
+ async getExpiring(days) {
17
+ const params = days ? `?days=${days}` : "";
18
+ const { data } = await api.get(`/plans/expiring${params}`);
19
+ return data;
20
+ }
21
+ async getExpired() {
22
+ const { data } = await api.get(`/plans/expired`);
23
+ return data;
24
+ }
25
+ async getPlansNeedingAlert(days) {
26
+ const params = days ? `?days=${days}` : "";
27
+ const { data } = await api.get(
28
+ `/plans/need-alert${params}`
29
+ );
30
+ return data;
31
+ }
32
+ async markAlertSent(guildId, daysUntilExpire) {
33
+ const { data } = await api.post(
34
+ `/plans/${guildId}/mark-alert`,
35
+ { daysUntilExpire }
36
+ );
37
+ return data;
38
+ }
39
+ async checkExpirations() {
40
+ const { data } = await api.get(
41
+ `/plans/check-expirations`
42
+ );
43
+ return data;
44
+ }
45
+ async getExpirationStatus(guildId) {
46
+ const { data } = await api.get(
47
+ `/plans/${guildId}/expiration-status`
48
+ );
49
+ return data;
50
+ }
51
+ async update(guildId, updates) {
52
+ const { data } = await api.patch(`/plans/${guildId}`, updates);
53
+ return data;
54
+ }
55
+ async delete(guildId) {
56
+ await api.delete(`/plans/${guildId}`);
57
+ }
58
+ async createSubscription(args) {
59
+ const { data } = await api.post("/plans/subscription", args);
60
+ return data;
61
+ }
62
+ }
63
+ const PlanService = new PlansService();
64
+
65
+ export { PlanService as default };
@@ -0,0 +1,104 @@
1
+ 'use strict';
2
+
3
+ const config = require('../config.cjs');
4
+
5
+ class ProductService {
6
+ async setDraft(args) {
7
+ const { data } = await config.api.put(
8
+ `/products/draft/${args.id}/${args.id}`,
9
+ args.data
10
+ );
11
+ return data;
12
+ }
13
+ async pushStock({
14
+ product,
15
+ amount
16
+ }) {
17
+ const stock = [];
18
+ if (product.stockRepeat && product.stockText) {
19
+ for (let i = 0; i < amount; i++) stock.push(product.stockText);
20
+ product.stockCount = Math.max((product.stockCount ?? amount) - amount, 0);
21
+ await this.update({
22
+ id: product.id,
23
+ data: { stockCount: product.stockCount }
24
+ });
25
+ } else if (product.stockItems && product.stockItems.length > 0) {
26
+ const taken = product.stockItems.splice(0, amount);
27
+ stock.push(...taken);
28
+ product.stockCount = product.stockItems.length;
29
+ await this.update({
30
+ id: product.id,
31
+ data: {
32
+ stockItems: product.stockItems,
33
+ stockCount: product.stockCount
34
+ }
35
+ });
36
+ }
37
+ return stock;
38
+ }
39
+ countStock(product) {
40
+ if (product.stockMode === "AUTOMATIC")
41
+ return product.stockItems?.length ?? 0;
42
+ return product.stockCount ?? 0;
43
+ }
44
+ async getDraft(args) {
45
+ const { data } = await config.api.get(
46
+ `/products/draft/${args.id}/${args.id}`
47
+ );
48
+ if (data && Object.keys(data).length === 0) {
49
+ return null;
50
+ }
51
+ return data;
52
+ }
53
+ async existsByReference(args) {
54
+ const { data } = await config.api.get(
55
+ `/products/by-reference/${args.reference}/${args.guildId}`
56
+ );
57
+ return data;
58
+ }
59
+ async getById(id) {
60
+ const { data } = await config.api.get(`/products/${id}`);
61
+ return data;
62
+ }
63
+ async getByReference({
64
+ reference,
65
+ guildId
66
+ }) {
67
+ const { data } = await config.api.get(
68
+ `/products/by-reference/${reference}/${guildId}`
69
+ );
70
+ return data;
71
+ }
72
+ async create(args) {
73
+ const { data } = await config.api.post("/products", args);
74
+ const product = data;
75
+ return product;
76
+ }
77
+ async getByCaching(id) {
78
+ const { data } = await config.api.get(`/products/caching/${id}`);
79
+ return data;
80
+ }
81
+ async getAllByGuild(guildId) {
82
+ const { data } = await config.api.get(`/products/by-guild/${guildId}`);
83
+ return data;
84
+ }
85
+ async update(args) {
86
+ const { data } = await config.api.patch(
87
+ `/products/${args.id}`,
88
+ args.data
89
+ );
90
+ const product = data;
91
+ return product;
92
+ }
93
+ async count(guildId) {
94
+ const { data } = await config.api.get(`/products/count/${guildId}`);
95
+ return data ?? 0;
96
+ }
97
+ async delete(id) {
98
+ await config.api.request({ method: "DELETE", data: {}, url: `/products/${id}` });
99
+ return;
100
+ }
101
+ }
102
+ const ProductService$1 = new ProductService();
103
+
104
+ module.exports = ProductService$1;
@@ -0,0 +1,102 @@
1
+ import { api } from '../config.mjs';
2
+
3
+ let ProductService$1 = class ProductService {
4
+ async setDraft(args) {
5
+ const { data } = await api.put(
6
+ `/products/draft/${args.id}/${args.id}`,
7
+ args.data
8
+ );
9
+ return data;
10
+ }
11
+ async pushStock({
12
+ product,
13
+ amount
14
+ }) {
15
+ const stock = [];
16
+ if (product.stockRepeat && product.stockText) {
17
+ for (let i = 0; i < amount; i++) stock.push(product.stockText);
18
+ product.stockCount = Math.max((product.stockCount ?? amount) - amount, 0);
19
+ await this.update({
20
+ id: product.id,
21
+ data: { stockCount: product.stockCount }
22
+ });
23
+ } else if (product.stockItems && product.stockItems.length > 0) {
24
+ const taken = product.stockItems.splice(0, amount);
25
+ stock.push(...taken);
26
+ product.stockCount = product.stockItems.length;
27
+ await this.update({
28
+ id: product.id,
29
+ data: {
30
+ stockItems: product.stockItems,
31
+ stockCount: product.stockCount
32
+ }
33
+ });
34
+ }
35
+ return stock;
36
+ }
37
+ countStock(product) {
38
+ if (product.stockMode === "AUTOMATIC")
39
+ return product.stockItems?.length ?? 0;
40
+ return product.stockCount ?? 0;
41
+ }
42
+ async getDraft(args) {
43
+ const { data } = await api.get(
44
+ `/products/draft/${args.id}/${args.id}`
45
+ );
46
+ if (data && Object.keys(data).length === 0) {
47
+ return null;
48
+ }
49
+ return data;
50
+ }
51
+ async existsByReference(args) {
52
+ const { data } = await api.get(
53
+ `/products/by-reference/${args.reference}/${args.guildId}`
54
+ );
55
+ return data;
56
+ }
57
+ async getById(id) {
58
+ const { data } = await api.get(`/products/${id}`);
59
+ return data;
60
+ }
61
+ async getByReference({
62
+ reference,
63
+ guildId
64
+ }) {
65
+ const { data } = await api.get(
66
+ `/products/by-reference/${reference}/${guildId}`
67
+ );
68
+ return data;
69
+ }
70
+ async create(args) {
71
+ const { data } = await api.post("/products", args);
72
+ const product = data;
73
+ return product;
74
+ }
75
+ async getByCaching(id) {
76
+ const { data } = await api.get(`/products/caching/${id}`);
77
+ return data;
78
+ }
79
+ async getAllByGuild(guildId) {
80
+ const { data } = await api.get(`/products/by-guild/${guildId}`);
81
+ return data;
82
+ }
83
+ async update(args) {
84
+ const { data } = await api.patch(
85
+ `/products/${args.id}`,
86
+ args.data
87
+ );
88
+ const product = data;
89
+ return product;
90
+ }
91
+ async count(guildId) {
92
+ const { data } = await api.get(`/products/count/${guildId}`);
93
+ return data ?? 0;
94
+ }
95
+ async delete(id) {
96
+ await api.request({ method: "DELETE", data: {}, url: `/products/${id}` });
97
+ return;
98
+ }
99
+ };
100
+ const ProductService = new ProductService$1();
101
+
102
+ export { ProductService as default };
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+ const config = require('../config.cjs');
4
+
5
+ class SaleService {
6
+ async create(args) {
7
+ const { data } = await config.api.post("/sales", args);
8
+ return data;
9
+ }
10
+ async getById(id) {
11
+ const { data } = await config.api.get(`/sales/${id}`);
12
+ return data;
13
+ }
14
+ async getAllByGuild(guildId) {
15
+ const { data } = await config.api.get(`/sales/by-guild/${guildId}`);
16
+ return data;
17
+ }
18
+ async saleProductGet(id) {
19
+ const { data } = await config.api.get(`/sales/product/${id}`);
20
+ return data;
21
+ }
22
+ async delete(id) {
23
+ await config.api.request({ method: "DELETE", data: {}, url: `/sales/${id}` });
24
+ return;
25
+ }
26
+ }
27
+ const SaleService$1 = new SaleService();
28
+
29
+ module.exports = SaleService$1;
@@ -0,0 +1,27 @@
1
+ import { api } from '../config.mjs';
2
+
3
+ let SaleService$1 = class SaleService {
4
+ async create(args) {
5
+ const { data } = await api.post("/sales", args);
6
+ return data;
7
+ }
8
+ async getById(id) {
9
+ const { data } = await api.get(`/sales/${id}`);
10
+ return data;
11
+ }
12
+ async getAllByGuild(guildId) {
13
+ const { data } = await api.get(`/sales/by-guild/${guildId}`);
14
+ return data;
15
+ }
16
+ async saleProductGet(id) {
17
+ const { data } = await api.get(`/sales/product/${id}`);
18
+ return data;
19
+ }
20
+ async delete(id) {
21
+ await api.request({ method: "DELETE", data: {}, url: `/sales/${id}` });
22
+ return;
23
+ }
24
+ };
25
+ const SaleService = new SaleService$1();
26
+
27
+ export { SaleService as default };
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ const config = require('../config.cjs');
4
+
5
+ class TokenService {
6
+ async listUnused() {
7
+ const { data } = await config.api.get("/tokens/unused");
8
+ return data;
9
+ }
10
+ async update(args) {
11
+ const { data } = await config.api.patch("/tokens", args);
12
+ return data;
13
+ }
14
+ }
15
+ const tokenService = new TokenService();
16
+
17
+ module.exports = tokenService;
@@ -0,0 +1,15 @@
1
+ import { api } from '../config.mjs';
2
+
3
+ class TokenService {
4
+ async listUnused() {
5
+ const { data } = await api.get("/tokens/unused");
6
+ return data;
7
+ }
8
+ async update(args) {
9
+ const { data } = await api.patch("/tokens", args);
10
+ return data;
11
+ }
12
+ }
13
+ const tokenService = new TokenService();
14
+
15
+ export { tokenService as default };
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ const config = require('../config.cjs');
4
+
5
+ class UserService {
6
+ async get(userId) {
7
+ const { data } = await config.api.get(`/users/${userId}`);
8
+ return data;
9
+ }
10
+ }
11
+ const usersService = new UserService();
12
+
13
+ module.exports = usersService;
@@ -0,0 +1,11 @@
1
+ import { api } from '../config.mjs';
2
+
3
+ class UserService {
4
+ async get(userId) {
5
+ const { data } = await api.get(`/users/${userId}`);
6
+ return data;
7
+ }
8
+ }
9
+ const usersService = new UserService();
10
+
11
+ export { usersService as default };
@@ -0,0 +1,33 @@
1
+ 'use strict';
2
+
3
+ const config = require('../config.cjs');
4
+
5
+ class WalletService {
6
+ async getOrCreate(userId) {
7
+ const { data } = await config.api.get(`/wallet/${userId}`);
8
+ return data;
9
+ }
10
+ async getByUserId(userId) {
11
+ const { data } = await config.api.get(`/wallet/user/${userId}`);
12
+ return data;
13
+ }
14
+ async getByApiKey(apiKey) {
15
+ const { data } = await config.api.get(`/wallet/by-api/${apiKey}`);
16
+ console.log(data);
17
+ return data;
18
+ }
19
+ async update(args) {
20
+ const { data } = await config.api.patch(
21
+ `/wallet/${args.userId}`,
22
+ args.data
23
+ );
24
+ return data;
25
+ }
26
+ async getByCaching(userId) {
27
+ const { data } = await config.api.get(`/wallet/caching/${userId}`);
28
+ return data;
29
+ }
30
+ }
31
+ const walletService = new WalletService();
32
+
33
+ module.exports = walletService;
@@ -0,0 +1,31 @@
1
+ import { api } from '../config.mjs';
2
+
3
+ class WalletService {
4
+ async getOrCreate(userId) {
5
+ const { data } = await api.get(`/wallet/${userId}`);
6
+ return data;
7
+ }
8
+ async getByUserId(userId) {
9
+ const { data } = await api.get(`/wallet/user/${userId}`);
10
+ return data;
11
+ }
12
+ async getByApiKey(apiKey) {
13
+ const { data } = await api.get(`/wallet/by-api/${apiKey}`);
14
+ console.log(data);
15
+ return data;
16
+ }
17
+ async update(args) {
18
+ const { data } = await api.patch(
19
+ `/wallet/${args.userId}`,
20
+ args.data
21
+ );
22
+ return data;
23
+ }
24
+ async getByCaching(userId) {
25
+ const { data } = await api.get(`/wallet/caching/${userId}`);
26
+ return data;
27
+ }
28
+ }
29
+ const walletService = new WalletService();
30
+
31
+ export { walletService as default };
@@ -0,0 +1,53 @@
1
+ 'use strict';
2
+
3
+ const decimal_js = require('decimal.js');
4
+ const index = require('../api/index.cjs');
5
+ const permission = require('./permission.cjs');
6
+
7
+ async function cartWillExpire(cart) {
8
+ if (cart.expireAt && new Date(cart.expireAt).getTime() - Date.now() < 12e4) {
9
+ await index.db.carts.update({
10
+ id: cart.id,
11
+ data: { expireAt: new Date(new Date(cart.expireAt).getTime() + 12e4) }
12
+ });
13
+ }
14
+ }
15
+ function cartAntiFakeVerify(configs, member) {
16
+ if (!configs.antiFake) return false;
17
+ const joinedAt = member.joinedAt ? new Date(member.joinedAt).getTime() : Date.now();
18
+ const now = Date.now();
19
+ const diffDays = Math.floor((now - joinedAt) / (1e3 * 60 * 60 * 24));
20
+ if (configs.antiFakeRequiredRoleIds && configs.antiFakeRequiredRoleIds.length > 0) {
21
+ const hasRequiredRole = configs.antiFakeRequiredRoleIds.some(
22
+ (roleId) => member.roles.cache.has(roleId)
23
+ );
24
+ if (!hasRequiredRole) return false;
25
+ }
26
+ if (diffDays < (configs.antiFakeDays ?? 0)) {
27
+ return true;
28
+ }
29
+ return false;
30
+ }
31
+ function cartVerifyPermission(cart, member, configs) {
32
+ if (cart.userId === member.id) return true;
33
+ return permission.hasPermission(member, ["manage_carts"], configs);
34
+ }
35
+ function cartCalculeTotal(cart) {
36
+ const products = cart.products ?? [];
37
+ return products.reduce((total, item) => {
38
+ const price = new decimal_js.Decimal(item.product?.price?.valueOf() ?? "0");
39
+ return total.plus(price.mul(item.amount));
40
+ }, new decimal_js.Decimal(0));
41
+ }
42
+ async function cartVerifyAproved(cartId) {
43
+ const cart = await index.db.carts.getById(cartId);
44
+ if (!cart) throw new Error("Cart not Found");
45
+ if (cart?.status === "APPROVED") return true;
46
+ return false;
47
+ }
48
+
49
+ exports.cartAntiFakeVerify = cartAntiFakeVerify;
50
+ exports.cartCalculeTotal = cartCalculeTotal;
51
+ exports.cartVerifyAproved = cartVerifyAproved;
52
+ exports.cartVerifyPermission = cartVerifyPermission;
53
+ exports.cartWillExpire = cartWillExpire;
@@ -0,0 +1,47 @@
1
+ import { Decimal } from 'decimal.js';
2
+ import { db } from '../api/index.mjs';
3
+ import { hasPermission } from './permission.mjs';
4
+
5
+ async function cartWillExpire(cart) {
6
+ if (cart.expireAt && new Date(cart.expireAt).getTime() - Date.now() < 12e4) {
7
+ await db.carts.update({
8
+ id: cart.id,
9
+ data: { expireAt: new Date(new Date(cart.expireAt).getTime() + 12e4) }
10
+ });
11
+ }
12
+ }
13
+ function cartAntiFakeVerify(configs, member) {
14
+ if (!configs.antiFake) return false;
15
+ const joinedAt = member.joinedAt ? new Date(member.joinedAt).getTime() : Date.now();
16
+ const now = Date.now();
17
+ const diffDays = Math.floor((now - joinedAt) / (1e3 * 60 * 60 * 24));
18
+ if (configs.antiFakeRequiredRoleIds && configs.antiFakeRequiredRoleIds.length > 0) {
19
+ const hasRequiredRole = configs.antiFakeRequiredRoleIds.some(
20
+ (roleId) => member.roles.cache.has(roleId)
21
+ );
22
+ if (!hasRequiredRole) return false;
23
+ }
24
+ if (diffDays < (configs.antiFakeDays ?? 0)) {
25
+ return true;
26
+ }
27
+ return false;
28
+ }
29
+ function cartVerifyPermission(cart, member, configs) {
30
+ if (cart.userId === member.id) return true;
31
+ return hasPermission(member, ["manage_carts"], configs);
32
+ }
33
+ function cartCalculeTotal(cart) {
34
+ const products = cart.products ?? [];
35
+ return products.reduce((total, item) => {
36
+ const price = new Decimal(item.product?.price?.valueOf() ?? "0");
37
+ return total.plus(price.mul(item.amount));
38
+ }, new Decimal(0));
39
+ }
40
+ async function cartVerifyAproved(cartId) {
41
+ const cart = await db.carts.getById(cartId);
42
+ if (!cart) throw new Error("Cart not Found");
43
+ if (cart?.status === "APPROVED") return true;
44
+ return false;
45
+ }
46
+
47
+ export { cartAntiFakeVerify, cartCalculeTotal, cartVerifyAproved, cartVerifyPermission, cartWillExpire };
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+
3
+ const decimal_js = require('decimal.js');
4
+
5
+ const formatPrice = (value) => {
6
+ const num = typeof value === "number" ? value : Number(value.toString());
7
+ const priceFormat = num.toFixed(2).replace(".", ",");
8
+ return `R$ ${priceFormat}`;
9
+ };
10
+ const formatDecimalToNumber = (value) => {
11
+ return Number(value.toString());
12
+ };
13
+ const formatNumberToDecimal = (value) => {
14
+ return new decimal_js.Decimal(value);
15
+ };
16
+ function formatRelativeTime(ms) {
17
+ const seconds = Math.floor(ms / 1e3);
18
+ const minutes = Math.floor(seconds / 60);
19
+ const hours = Math.floor(minutes / 60);
20
+ const days = Math.floor(hours / 24);
21
+ if (days >= 1) return `${days} dia${days > 1 ? "s" : ""}`;
22
+ if (hours >= 1) return `${hours} hora${hours > 1 ? "s" : ""}`;
23
+ if (minutes >= 1) return `${minutes} minuto${minutes > 1 ? "s" : ""}`;
24
+ return `${seconds} segundo${seconds !== 1 ? "s" : ""}`;
25
+ }
26
+
27
+ exports.formatDecimalToNumber = formatDecimalToNumber;
28
+ exports.formatNumberToDecimal = formatNumberToDecimal;
29
+ exports.formatPrice = formatPrice;
30
+ exports.formatRelativeTime = formatRelativeTime;
@@ -0,0 +1,25 @@
1
+ import { Decimal } from 'decimal.js';
2
+
3
+ const formatPrice = (value) => {
4
+ const num = typeof value === "number" ? value : Number(value.toString());
5
+ const priceFormat = num.toFixed(2).replace(".", ",");
6
+ return `R$ ${priceFormat}`;
7
+ };
8
+ const formatDecimalToNumber = (value) => {
9
+ return Number(value.toString());
10
+ };
11
+ const formatNumberToDecimal = (value) => {
12
+ return new Decimal(value);
13
+ };
14
+ function formatRelativeTime(ms) {
15
+ const seconds = Math.floor(ms / 1e3);
16
+ const minutes = Math.floor(seconds / 60);
17
+ const hours = Math.floor(minutes / 60);
18
+ const days = Math.floor(hours / 24);
19
+ if (days >= 1) return `${days} dia${days > 1 ? "s" : ""}`;
20
+ if (hours >= 1) return `${hours} hora${hours > 1 ? "s" : ""}`;
21
+ if (minutes >= 1) return `${minutes} minuto${minutes > 1 ? "s" : ""}`;
22
+ return `${seconds} segundo${seconds !== 1 ? "s" : ""}`;
23
+ }
24
+
25
+ export { formatDecimalToNumber, formatNumberToDecimal, formatPrice, formatRelativeTime };