@coinbase/cdp-core 0.0.23 → 0.0.24

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.
@@ -1,93 +1,99 @@
1
- import { Provider as h } from "ox";
1
+ import { Provider as d } from "ox";
2
2
  import { http as p } from "viem";
3
- import { create as l } from "zustand";
4
- import { subscribeWithSelector as f, persist as g } from "./index17.js";
5
- import { validateRequest as w, EIP1193ProviderError as I, STANDARD_ERROR_CODES as S } from "./index4.js";
6
- import { EventEmitter as b } from "./index18.js";
3
+ import { create as m } from "zustand";
4
+ import { subscribeWithSelector as f, persist as g } from "./index21.js";
5
+ import { validateRequest as w, EIP1193ProviderError as C, STANDARD_ERROR_CODES as S } from "./index4.js";
6
+ import { EventEmitter as b } from "./index22.js";
7
7
  import "@coinbase/cdp-api-client";
8
- import { handleChainId as A, handleSignTypedData as C, handleEthSign as _, handleSwitchEthereumChain as v, handleDisconnect as D, handleSendTransaction as E, handlePersonalSign as P, handleRequestAccounts as R, handleAccounts as y } from "./index19.js";
9
- import { onAuthStateChange as T } from "./index2.js";
10
- import { baseSepolia as d } from "./index20.js";
11
- function q(r, e, a) {
12
- e.subscribe(
13
- (t) => t.chainId,
14
- (t, n) => {
15
- t !== n && r.emit("chainChanged", t);
8
+ import { handleGetCapabilities as I, handleGetCallsStatus as _, handleSendCalls as A, handleChainId as v, handleSignTypedData as D, handleEthSign as E, handleSwitchEthereumChain as P, handleDisconnect as R, handleSendTransaction as y, handlePersonalSign as T, handleRequestAccounts as q, handleAccounts as G } from "./index23.js";
9
+ import { onAuthStateChange as L } from "./index2.js";
10
+ import { baseSepolia as h } from "./index24.js";
11
+ function M(a, n, r) {
12
+ n.subscribe(
13
+ (e) => e.chainId,
14
+ (e, t) => {
15
+ e !== t && a.emit("chainChanged", e);
16
16
  }
17
- ), e.subscribe(
18
- (t) => t.user,
19
- (t, n) => {
20
- if (!(t?.userId === n?.userId && t?.evmAccounts?.length === n?.evmAccounts?.length)) {
21
- if (!t && n) {
22
- r.emit("disconnect", new h.DisconnectedError());
17
+ ), n.subscribe(
18
+ (e) => e.user,
19
+ (e, t) => {
20
+ if (!(e?.userId === t?.userId && e?.evmAccounts?.length === t?.evmAccounts?.length)) {
21
+ if (!e && t) {
22
+ a.emit("disconnect", new d.DisconnectedError());
23
23
  return;
24
24
  }
25
- if (t && t.evmAccounts?.length && (!n || n.evmAccounts?.length === 0)) {
26
- const m = e.getState().chainId;
27
- r.emit("connect", { chainId: m });
25
+ if (e && e.evmAccounts?.length && (!t || t.evmAccounts?.length === 0)) {
26
+ const u = n.getState().chainId;
27
+ a.emit("connect", { chainId: u });
28
28
  return;
29
29
  }
30
30
  }
31
31
  }
32
32
  );
33
- const { chainId: i, setChainId: o } = e.getState(), c = i || a.chains[0].id;
34
- return i || o(c), h.from({
35
- request: async (t) => {
36
- w(t, a);
37
- const n = t;
38
- switch (n.method) {
33
+ const { chainId: o, setChainId: s } = n.getState(), c = o || r.chains[0].id;
34
+ return o || s(c), d.from({
35
+ request: async (e) => {
36
+ w(e, r);
37
+ const t = e;
38
+ switch (t.method) {
39
39
  case "eth_accounts":
40
- return y();
40
+ return G();
41
41
  case "eth_requestAccounts":
42
- return R(r, e);
42
+ return q(a, n);
43
43
  case "personal_sign":
44
- return P(n.params);
44
+ return T(t.params);
45
45
  case "eth_sendTransaction":
46
- return E(n.params, e, a.transports);
46
+ return y(t.params, n, r.transports);
47
47
  case "wallet_disconnect":
48
- return D();
48
+ return R();
49
49
  case "wallet_switchEthereumChain":
50
- return v(n.params, e);
50
+ return P(t.params, n);
51
51
  case "eth_sign":
52
- return _(n.params);
52
+ return E(t.params);
53
53
  case "eth_signTypedData_v4":
54
- return C(n.params);
54
+ return D(t.params);
55
55
  case "eth_chainId":
56
- return A(e);
56
+ return v(n);
57
+ case "wallet_sendCalls":
58
+ return A(t.params, n);
59
+ case "wallet_getCallsStatus":
60
+ return _(t.params, n);
61
+ case "wallet_getCapabilities":
62
+ return I();
57
63
  // Catch-all for any unknown method
58
64
  default:
59
- throw new I(
65
+ throw new C(
60
66
  S.provider.unsupportedMethod,
61
- `Method ${n.method} not supported`
67
+ `Method ${t.method} not supported`
62
68
  );
63
69
  }
64
70
  },
65
71
  // Event emitter methods - only the ones required by the interface
66
- on: r.on.bind(r),
67
- removeListener: r.removeListener.bind(r)
72
+ on: a.on.bind(a),
73
+ removeListener: a.removeListener.bind(a)
68
74
  });
69
75
  }
70
- const u = {
71
- chains: [d],
76
+ const l = {
77
+ chains: [h],
72
78
  transports: {
73
- [d.id]: p()
79
+ [h.id]: p()
74
80
  }
75
81
  };
76
- function B(r) {
77
- if (r?.chains.length === 0)
82
+ function H(a) {
83
+ if (a?.chains.length === 0)
78
84
  throw new Error("At least one chain must be configured");
79
- const e = r?.chains ?? u.chains, a = r?.transports ?? u.transports;
80
- if (e.length === 0)
85
+ const n = a?.chains ?? l.chains, r = a?.transports ?? l.transports;
86
+ if (n.length === 0)
81
87
  throw new Error("No chains found in configuration");
82
- const i = new b(), o = l()(
88
+ const o = new b(), s = m()(
83
89
  f(
84
90
  g(
85
- (s) => ({
86
- chainId: e[0].id,
87
- setChainId: (t) => s({ chainId: t }),
88
- chains: e,
91
+ (i) => ({
92
+ chainId: n[0].id,
93
+ setChainId: (e) => i({ chainId: e }),
94
+ chains: n,
89
95
  user: null,
90
- setUser: (t) => s({ user: t })
96
+ setUser: (e) => i({ user: e })
91
97
  }),
92
98
  {
93
99
  name: "cdp-provider-store"
@@ -96,15 +102,15 @@ function B(r) {
96
102
  )
97
103
  )
98
104
  );
99
- return o.persist.rehydrate(), T((s) => {
100
- o.getState().setUser(s);
105
+ return s.persist.rehydrate(), L((i) => {
106
+ s.getState().setUser(i);
101
107
  }), {
102
- provider: q(i, o, {
103
- chains: e,
104
- transports: a
108
+ provider: M(o, s, {
109
+ chains: n,
110
+ transports: r
105
111
  })
106
112
  };
107
113
  }
108
114
  export {
109
- B as createCDPEmbeddedWallet
115
+ H as createCDPEmbeddedWallet
110
116
  };
@@ -4,7 +4,7 @@ import "zustand";
4
4
  import "@coinbase/cdp-api-client";
5
5
  import { getCurrentUser as u } from "./index2.js";
6
6
  import "./index3.js";
7
- const n = {
7
+ const r = {
8
8
  rpc: {
9
9
  invalidInput: -32e3,
10
10
  resourceNotFound: -32001,
@@ -38,11 +38,11 @@ class o extends Error {
38
38
  * @param code - The error code from EIP1193ErrorCode enum.
39
39
  * @param message - The error message.
40
40
  */
41
- constructor(t, r) {
42
- super(r), this.code = t;
41
+ constructor(t, n) {
42
+ super(n), this.code = t;
43
43
  }
44
44
  }
45
- class a extends Error {
45
+ class c extends Error {
46
46
  /**
47
47
  * The error code from RPCErrorCode type.
48
48
  */
@@ -53,8 +53,8 @@ class a extends Error {
53
53
  * @param code - The error code from RPCErrorCode type.
54
54
  * @param message - The error message.
55
55
  */
56
- constructor(t, r) {
57
- super(r), this.code = t;
56
+ constructor(t, n) {
57
+ super(n), this.code = t;
58
58
  }
59
59
  }
60
60
  const p = /* @__PURE__ */ new Set([
@@ -66,65 +66,78 @@ const p = /* @__PURE__ */ new Set([
66
66
  "eth_chainId",
67
67
  "eth_sign",
68
68
  "wallet_disconnect",
69
- "wallet_switchEthereumChain"
69
+ "wallet_switchEthereumChain",
70
+ "wallet_sendCalls",
71
+ "wallet_getCallsStatus",
72
+ "wallet_getCapabilities"
70
73
  ]);
71
- function E(e, { chains: t }) {
72
- const { method: r, params: s } = e;
73
- if (typeof r != "string" || r.length === 0)
74
- throw new a(
75
- n.rpc.invalidParams,
74
+ function _(e, { chains: t }) {
75
+ const { method: n, params: a } = e;
76
+ if (typeof n != "string" || n.length === 0)
77
+ throw new c(
78
+ r.rpc.invalidParams,
76
79
  "'method' must be a non-empty string."
77
80
  );
78
- const i = (s ?? [])[0]?.chainId;
79
- if (typeof i == "string" && !t.some((c) => c.id === Number.parseInt(i, 16)))
81
+ const s = (a ?? [])[0]?.chainId;
82
+ if (typeof s == "string" && !t.some((d) => d.id === Number.parseInt(s, 16)))
80
83
  throw new o(
81
- n.provider.unsupportedChain,
82
- `Chain ${i} not supported - make sure the provider is configured with the correct chains.`
84
+ r.provider.unsupportedChain,
85
+ `Chain ${s} not supported - make sure the provider is configured with the correct chains.`
83
86
  );
84
- if (s !== void 0 && !Array.isArray(s))
85
- throw new a(
86
- n.rpc.invalidParams,
87
+ if (a !== void 0 && !Array.isArray(a))
88
+ throw new c(
89
+ r.rpc.invalidParams,
87
90
  "'params' must be an array if provided."
88
91
  );
89
- if (!p.has(r))
92
+ if (!p.has(n))
90
93
  throw new o(
91
- n.provider.unsupportedMethod,
94
+ r.provider.unsupportedMethod,
92
95
  `Method ${e.method} not supported`
93
96
  );
94
97
  }
95
- async function d() {
98
+ async function i() {
96
99
  const e = await u();
97
100
  if (!e)
98
101
  throw new o(
99
- n.provider.unauthorized,
102
+ r.provider.unauthorized,
100
103
  "User not connected"
101
104
  );
102
105
  return e;
103
106
  }
104
- async function _(e) {
105
- const t = await d();
107
+ async function E(e) {
108
+ const t = await i();
106
109
  if (!t.evmAccounts?.includes(e))
107
110
  throw new o(
108
- n.provider.unauthorized,
111
+ r.provider.unauthorized,
109
112
  "Address not owned by user"
110
113
  );
111
114
  return t;
112
115
  }
113
- async function R() {
114
- const e = await d();
116
+ async function y() {
117
+ const e = await i();
115
118
  if (!e.evmAccounts?.[0])
116
119
  throw new o(
117
- n.provider.unauthorized,
120
+ r.provider.unauthorized,
118
121
  "No EVM accounts available"
119
122
  );
120
123
  return e;
121
124
  }
125
+ async function A() {
126
+ const e = await i();
127
+ if (!e.evmSmartAccounts?.[0])
128
+ throw new o(
129
+ r.provider.unauthorized,
130
+ "No EVM smart accounts available"
131
+ );
132
+ return e;
133
+ }
122
134
  export {
123
135
  o as EIP1193ProviderError,
124
- a as RPCRequestError,
125
- n as STANDARD_ERROR_CODES,
126
- E as validateRequest,
127
- d as validateUserConnected,
128
- R as validateUserHasEvmAccount,
129
- _ as validateUserOwnsAddress
136
+ c as RPCRequestError,
137
+ r as STANDARD_ERROR_CODES,
138
+ _ as validateRequest,
139
+ i as validateUserConnected,
140
+ y as validateUserHasEvmAccount,
141
+ A as validateUserHasEvmSmartAccount,
142
+ E as validateUserOwnsAddress
130
143
  };
@@ -1,10 +1,10 @@
1
1
  import { logOutEndUser as h, refreshAccessToken as l, registerTemporaryWalletSecret as c } from "@coinbase/cdp-api-client";
2
- import { SignJWT as o } from "./index21.js";
2
+ import { SignJWT as o } from "./index17.js";
3
3
  import "viem";
4
4
  import { toAuthState as u } from "./index7.js";
5
- import { createKeyPair as S } from "./index22.js";
6
- import { generateRandomId as i } from "./index23.js";
7
- import { hash as w } from "./index24.js";
5
+ import { createKeyPair as S } from "./index18.js";
6
+ import { generateRandomId as i } from "./index19.js";
7
+ import { hash as w } from "./index20.js";
8
8
  import { sortKeys as f } from "./index13.js";
9
9
  const n = 60 * 1e3;
10
10
  class C {
@@ -1,4 +1,4 @@
1
- import { FlattenedSign as n } from "./index82.js";
1
+ import { FlattenedSign as n } from "./index80.js";
2
2
  class o {
3
3
  #e;
4
4
  constructor(e) {
@@ -1,7 +1,7 @@
1
- import { encoder as n } from "./index83.js";
2
- import e from "./index84.js";
3
- import i from "./index85.js";
4
- import o from "./index86.js";
1
+ import { encoder as n } from "./index81.js";
2
+ import e from "./index82.js";
3
+ import i from "./index83.js";
4
+ import o from "./index84.js";
5
5
  function s(r, t) {
6
6
  if (!Number.isFinite(t))
7
7
  throw new TypeError(`Invalid ${r} input`);
@@ -1,4 +1,4 @@
1
- import { HashMD as D, SHA256_IV as b, Chi as g, Maj as p } from "./index80.js";
1
+ import { HashMD as D, SHA256_IV as b, Chi as g, Maj as p } from "./index86.js";
2
2
  import { createHasher as u, clean as C, rotr as i } from "./index76.js";
3
3
  const B = /* @__PURE__ */ Uint32Array.from([
4
4
  1116352408,
@@ -1,81 +1,57 @@
1
- import { Hash as g, createView as l, aexists as b, toBytes as a, abytes as d, aoutput as x, clean as w } from "./index76.js";
2
- function y(o, t, s, n) {
3
- if (typeof o.setBigUint64 == "function")
4
- return o.setBigUint64(t, s, n);
5
- const i = BigInt(32), h = BigInt(4294967295), e = Number(s >> i & h), r = Number(s & h), c = n ? 4 : 0, u = n ? 0 : 4;
6
- o.setUint32(t + c, e, n), o.setUint32(t + u, r, n);
7
- }
8
- function U(o, t, s) {
9
- return o & t ^ ~o & s;
10
- }
11
- function _(o, t, s) {
12
- return o & t ^ o & s ^ t & s;
13
- }
14
- class m extends g {
15
- constructor(t, s, n, i) {
16
- super(), this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.blockLen = t, this.outputLen = s, this.padOffset = n, this.isLE = i, this.buffer = new Uint8Array(t), this.view = l(this.buffer);
17
- }
18
- update(t) {
19
- b(this), t = a(t), d(t);
20
- const { view: s, buffer: n, blockLen: i } = this, h = t.length;
21
- for (let e = 0; e < h; ) {
22
- const r = Math.min(i - this.pos, h - e);
23
- if (r === i) {
24
- const c = l(t);
25
- for (; i <= h - e; e += i)
26
- this.process(c, e);
27
- continue;
28
- }
29
- n.set(t.subarray(e, e + r), this.pos), this.pos += r, e += r, this.pos === i && (this.process(s, 0), this.pos = 0);
30
- }
31
- return this.length += t.length, this.roundClean(), this;
32
- }
33
- digestInto(t) {
34
- b(this), x(t, this), this.finished = !0;
35
- const { buffer: s, view: n, blockLen: i, isLE: h } = this;
36
- let { pos: e } = this;
37
- s[e++] = 128, w(this.buffer.subarray(e)), this.padOffset > i - e && (this.process(n, 0), e = 0);
38
- for (let f = e; f < i; f++)
39
- s[f] = 0;
40
- y(n, i - 8, BigInt(this.length * 8), h), this.process(n, 0);
41
- const r = l(t), c = this.outputLen;
42
- if (c % 4)
43
- throw new Error("_sha2: outputLen should be aligned to 32bit");
44
- const u = c / 4, p = this.get();
45
- if (u > p.length)
46
- throw new Error("_sha2: outputLen bigger than state");
47
- for (let f = 0; f < u; f++)
48
- r.setUint32(4 * f, p[f], h);
1
+ import { encode as d } from "./index88.js";
2
+ import y from "./index89.js";
3
+ import b from "./index90.js";
4
+ import { JWSInvalid as r } from "./index71.js";
5
+ import { encoder as s, concat as u, decoder as h } from "./index81.js";
6
+ import g from "./index91.js";
7
+ import H from "./index92.js";
8
+ import P from "./index93.js";
9
+ class x {
10
+ #r;
11
+ #e;
12
+ #t;
13
+ constructor(e) {
14
+ if (!(e instanceof Uint8Array))
15
+ throw new TypeError("payload must be an instance of Uint8Array");
16
+ this.#r = e;
49
17
  }
50
- digest() {
51
- const { buffer: t, outputLen: s } = this;
52
- this.digestInto(t);
53
- const n = t.slice(0, s);
54
- return this.destroy(), n;
18
+ setProtectedHeader(e) {
19
+ if (this.#e)
20
+ throw new TypeError("setProtectedHeader can only be called once");
21
+ return this.#e = e, this;
55
22
  }
56
- _cloneInto(t) {
57
- t || (t = new this.constructor()), t.set(...this.get());
58
- const { blockLen: s, buffer: n, length: i, finished: h, destroyed: e, pos: r } = this;
59
- return t.destroyed = e, t.finished = h, t.length = i, t.pos = r, i % s && t.buffer.set(n), t;
23
+ setUnprotectedHeader(e) {
24
+ if (this.#t)
25
+ throw new TypeError("setUnprotectedHeader can only be called once");
26
+ return this.#t = e, this;
60
27
  }
61
- clone() {
62
- return this._cloneInto();
28
+ async sign(e, l) {
29
+ if (!this.#e && !this.#t)
30
+ throw new r("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");
31
+ if (!b(this.#e, this.#t))
32
+ throw new r("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
33
+ const c = {
34
+ ...this.#e,
35
+ ...this.#t
36
+ }, p = H(r, /* @__PURE__ */ new Map([["b64", !0]]), l?.crit, this.#e, c);
37
+ let o = !0;
38
+ if (p.has("b64") && (o = this.#e.b64, typeof o != "boolean"))
39
+ throw new r('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
40
+ const { alg: t } = c;
41
+ if (typeof t != "string" || !t)
42
+ throw new r('JWS "alg" (Algorithm) Header Parameter missing or invalid');
43
+ g(t, e, "sign");
44
+ let i = this.#r;
45
+ o && (i = s.encode(d(i)));
46
+ let n;
47
+ this.#e ? n = s.encode(d(JSON.stringify(this.#e))) : n = s.encode("");
48
+ const f = u(n, s.encode("."), i), m = await P(e, t), w = await y(t, m, f), a = {
49
+ signature: d(w),
50
+ payload: ""
51
+ };
52
+ return o && (a.payload = h.decode(i)), this.#t && (a.header = this.#t), this.#e && (a.protected = h.decode(n)), a;
63
53
  }
64
54
  }
65
- const B = /* @__PURE__ */ Uint32Array.from([
66
- 1779033703,
67
- 3144134277,
68
- 1013904242,
69
- 2773480762,
70
- 1359893119,
71
- 2600822924,
72
- 528734635,
73
- 1541459225
74
- ]);
75
55
  export {
76
- U as Chi,
77
- m as HashMD,
78
- _ as Maj,
79
- B as SHA256_IV,
80
- y as setBigUint64
56
+ x as FlattenedSign
81
57
  };
@@ -1,12 +1,13 @@
1
- import { contracts as o } from "./index88.js";
2
- import { formatters as r } from "./index89.js";
3
- import { serializers as t } from "./index90.js";
4
- const e = {
5
- blockTime: 2e3,
6
- contracts: o,
7
- formatters: r,
8
- serializers: t
9
- };
1
+ const d = new TextEncoder(), s = new TextDecoder();
2
+ function f(...n) {
3
+ const c = n.reduce((e, { length: r }) => e + r, 0), t = new Uint8Array(c);
4
+ let o = 0;
5
+ for (const e of n)
6
+ t.set(e, o), o += e.length;
7
+ return t;
8
+ }
10
9
  export {
11
- e as chainConfig
10
+ f as concat,
11
+ s as decoder,
12
+ d as encoder
12
13
  };
@@ -1,57 +1,4 @@
1
- import { encode as d } from "./index91.js";
2
- import y from "./index92.js";
3
- import b from "./index93.js";
4
- import { JWSInvalid as r } from "./index71.js";
5
- import { encoder as s, concat as u, decoder as h } from "./index83.js";
6
- import g from "./index94.js";
7
- import H from "./index95.js";
8
- import P from "./index96.js";
9
- class x {
10
- #r;
11
- #e;
12
- #t;
13
- constructor(e) {
14
- if (!(e instanceof Uint8Array))
15
- throw new TypeError("payload must be an instance of Uint8Array");
16
- this.#r = e;
17
- }
18
- setProtectedHeader(e) {
19
- if (this.#e)
20
- throw new TypeError("setProtectedHeader can only be called once");
21
- return this.#e = e, this;
22
- }
23
- setUnprotectedHeader(e) {
24
- if (this.#t)
25
- throw new TypeError("setUnprotectedHeader can only be called once");
26
- return this.#t = e, this;
27
- }
28
- async sign(e, l) {
29
- if (!this.#e && !this.#t)
30
- throw new r("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");
31
- if (!b(this.#e, this.#t))
32
- throw new r("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
33
- const c = {
34
- ...this.#e,
35
- ...this.#t
36
- }, p = H(r, /* @__PURE__ */ new Map([["b64", !0]]), l?.crit, this.#e, c);
37
- let o = !0;
38
- if (p.has("b64") && (o = this.#e.b64, typeof o != "boolean"))
39
- throw new r('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
40
- const { alg: t } = c;
41
- if (typeof t != "string" || !t)
42
- throw new r('JWS "alg" (Algorithm) Header Parameter missing or invalid');
43
- g(t, e, "sign");
44
- let i = this.#r;
45
- o && (i = s.encode(d(i)));
46
- let n;
47
- this.#e ? n = s.encode(d(JSON.stringify(this.#e))) : n = s.encode("");
48
- const f = u(n, s.encode("."), i), m = await P(e, t), w = await y(t, m, f), a = {
49
- signature: d(w),
50
- payload: ""
51
- };
52
- return o && (a.payload = h.decode(i)), this.#t && (a.header = this.#t), this.#e && (a.protected = h.decode(n)), a;
53
- }
54
- }
1
+ const o = (e) => Math.floor(e.getTime() / 1e3);
55
2
  export {
56
- x as FlattenedSign
3
+ o as default
57
4
  };
@@ -1,13 +1,47 @@
1
- const d = new TextEncoder(), s = new TextDecoder();
2
- function f(...n) {
3
- const c = n.reduce((e, { length: r }) => e + r, 0), t = new Uint8Array(c);
4
- let o = 0;
5
- for (const e of n)
6
- t.set(e, o), o += e.length;
7
- return t;
8
- }
1
+ const o = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i, t = (c) => {
2
+ const s = o.exec(c);
3
+ if (!s || s[4] && s[1])
4
+ throw new TypeError("Invalid time period format");
5
+ const a = parseFloat(s[2]), r = s[3].toLowerCase();
6
+ let e;
7
+ switch (r) {
8
+ case "sec":
9
+ case "secs":
10
+ case "second":
11
+ case "seconds":
12
+ case "s":
13
+ e = Math.round(a);
14
+ break;
15
+ case "minute":
16
+ case "minutes":
17
+ case "min":
18
+ case "mins":
19
+ case "m":
20
+ e = Math.round(a * 60);
21
+ break;
22
+ case "hour":
23
+ case "hours":
24
+ case "hr":
25
+ case "hrs":
26
+ case "h":
27
+ e = Math.round(a * 3600);
28
+ break;
29
+ case "day":
30
+ case "days":
31
+ case "d":
32
+ e = Math.round(a * 86400);
33
+ break;
34
+ case "week":
35
+ case "weeks":
36
+ case "w":
37
+ e = Math.round(a * 604800);
38
+ break;
39
+ default:
40
+ e = Math.round(a * 31557600);
41
+ break;
42
+ }
43
+ return s[1] === "-" || s[4] === "ago" ? -e : e;
44
+ };
9
45
  export {
10
- f as concat,
11
- s as decoder,
12
- d as encoder
46
+ t as default
13
47
  };
@@ -1,4 +1,16 @@
1
- const o = (e) => Math.floor(e.getTime() / 1e3);
1
+ function o(t) {
2
+ return typeof t == "object" && t !== null;
3
+ }
4
+ const r = (t) => {
5
+ if (!o(t) || Object.prototype.toString.call(t) !== "[object Object]")
6
+ return !1;
7
+ if (Object.getPrototypeOf(t) === null)
8
+ return !0;
9
+ let e = t;
10
+ for (; Object.getPrototypeOf(e) !== null; )
11
+ e = Object.getPrototypeOf(e);
12
+ return Object.getPrototypeOf(t) === e;
13
+ };
2
14
  export {
3
- o as default
15
+ r as default
4
16
  };