t0n 0.1.2 → 0.1.3

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/README.md CHANGED
@@ -11,6 +11,14 @@ To install the package, run:
11
11
  bun i t0n
12
12
  ```
13
13
 
14
+ ## Tests
15
+
16
+ To perform the tests, run:
17
+
18
+ ```bash
19
+ bun test
20
+ ```
21
+
14
22
  ## License
15
23
 
16
24
  This package is licensed under the [MIT license](https://github.com/attla/t0n/blob/main/LICENSE) © [Zunq](https://zunq.com)
package/dist/index.d.ts CHANGED
@@ -78,6 +78,8 @@ declare class Envir {
78
78
  static get<T = any>(key: string, defaultValue?: T): T | undefined;
79
79
  static set<T = any>(key: string, value: T): void;
80
80
  static remove(key: string): void;
81
+ static add<T = any>(data?: Record<string, T>): void;
82
+ static replace<T = any>(data?: Record<string, T>): void;
81
83
  }
82
84
 
83
85
  declare function toInt(data: any[] | string | number): number;
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- var i=class r{static{this.UNDEFINED=Symbol("UNDEFINED");}static resolve(t,e){let n=r.UNDEFINED;try{n=t();}catch{}return new r(n,e)}static defined(t){return !this.undefined(t)&&!this.isUnset(t)}static undefined(t){return t===r.UNDEFINED||this.isUnset(t)}static isUnset(t){return t==null}constructor(t,e){this.value=t,this._default=e;}or(t){return r.defined(this.value)?this:r.resolve(t,this._default)}default(t){return this._default=t,this}tap(t){let e=this.get();return t?.(e),this}get(){return r.undefined(this.value)?this._default:this.value}getOrThrow(t){let e=this.get();if(r.undefined(e))throw t??new Error("Value is null or undefined");return e}};var s=class{static encode(t){let e=typeof t;return t=this.toString(t,e),(t?.byteLength||t.length)<1?"":Buffer.from(t).toString("base64")}static decode(t){if(typeof t!="string")throw new TypeError("Expected input to be a string");if(!/^[A-Za-z0-9+/]*={0,2}$/.test(t))throw new Error("Invalid Base64 string");try{return Buffer.from(t,"base64").toString("utf8")}catch{throw new Error("Invalid base64 characters")}}static toString(t,e){return e??=typeof t,Buffer.isBuffer(t)||e==="string"?t:Array.isArray(t)||["function","symbol"].includes(e)?t.toString():t===null||["number","bigint","boolean","undefined"].includes(e)?String(t):e==="object"&&!(t instanceof Uint8Array)&&!(t instanceof ArrayBuffer)?JSON.stringify(t):t}},u=class{static encode(t){return s.encode(t)?.replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")||""}static decode(t){let e=t.length%4;return e&&(t+="=".repeat(4-e)),s.decode(t.replace(/-/g,"+").replace(/_/g,"/"))}};var o=class{constructor(t={}){this.data={};this.data={...t};}all(){return {...this.data}}has(t){return t in this.data}add(t={}){this.data={...this.data,...t};}replace(t={}){this.data={...t};}get(t,e){return this.has(t)?this.data[t]:e}set(t,e){if(this.has(t)&&typeof e!=typeof this.data[t])throw new TypeError(`Type mismatch for key ${t}. Expected ${typeof this.data[t]}, got ${typeof e}`);this.data[t]=e;}remove(t){delete this.data[t];}clear(){this.data={};}get length(){return this.keys().length}get size(){return this.length}keys(){return Object.keys(this.data)}values(){return Object.values(this.data)}toArray(){return Object.entries(this.data)}jsonSerialize(){return this.all()}toJson(t=0){return JSON.stringify(this.all(),null,t)}[Symbol.iterator](){return Object.entries(this.data)[Symbol.iterator]()}};var a=class r{static timestamp(t=null){return t==null?0:typeof t=="number"?t:t instanceof Date?Math.floor(t.getTime()/1e3):0}static minuteToSecond(t=null){return r.timestamp(t)||Math.floor(Date.now()/1e3)}static strToDate(t){return new Date(t)}static now(){return Math.floor(Date.now()/1e3)}static addSeconds(t,e){return t+e}static addMinutes(t,e){return t+e*60}static addHours(t,e){return t+e*3600}static addDays(t,e){return t+e*86400}};var l=class{static memory(){return this._memory||(this._memory=new o),this._memory}static has(t){return i.UNDEFINED!==this.get(t,i.UNDEFINED)}static get(t,e){if(this.memory().has(t))return this.memory().get(t,e);let n=process.env[t];return n!==void 0?n:e}static set(t,e){this.memory().set(t,e);}static remove(t){this.memory().remove(t);}};function T(r){if(typeof r=="number"&&Number.isInteger(r))return r;let e=JSON.stringify(r).replace(/\D/g,"");return e?parseInt(e.slice(0,16),10):0}
1
+ var i=class r{static{this.UNDEFINED=Symbol("UNDEFINED");}static resolve(t,e){let n=r.UNDEFINED;try{n=t();}catch{}return new r(n,e)}static defined(t){return !this.undefined(t)&&!this.isUnset(t)}static undefined(t){return t===r.UNDEFINED||this.isUnset(t)}static isUnset(t){return t==null}constructor(t,e){this.value=t,this._default=e;}or(t){return r.defined(this.value)?this:r.resolve(t,this._default)}default(t){return this._default=t,this}tap(t){let e=this.get();return t?.(e),this}get(){return r.undefined(this.value)?this._default:this.value}getOrThrow(t){let e=this.get();if(r.undefined(e))throw t??new Error("Value is null or undefined");return e}};var s=class{static encode(t){let e=typeof t;return t=this.toString(t,e),(t?.byteLength||t.length)<1?"":Buffer.from(t).toString("base64")}static decode(t){if(typeof t!="string")throw new TypeError("Expected input to be a string");if(!/^[A-Za-z0-9+/]*={0,2}$/.test(t))throw new Error("Invalid Base64 string");try{return Buffer.from(t,"base64").toString("utf8")}catch{throw new Error("Invalid base64 characters")}}static toString(t,e){return e??=typeof t,Buffer.isBuffer(t)||e==="string"?t:Array.isArray(t)||["function","symbol"].includes(e)?t.toString():t===null||["number","bigint","boolean","undefined"].includes(e)?String(t):e==="object"&&!(t instanceof Uint8Array)&&!(t instanceof ArrayBuffer)?JSON.stringify(t):t}},u=class{static encode(t){return s.encode(t)?.replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")||""}static decode(t){let e=t.length%4;return e&&(t+="=".repeat(4-e)),s.decode(t.replace(/-/g,"+").replace(/_/g,"/"))}};var o=class{constructor(t={}){this.data={};this.data={...t};}all(){return {...this.data}}has(t){return t in this.data}add(t={}){this.data={...this.data,...t};}replace(t={}){this.data={...t};}get(t,e){return this.has(t)?this.data[t]:e}set(t,e){if(this.has(t)&&typeof e!=typeof this.data[t])throw new TypeError(`Type mismatch for key ${t}. Expected ${typeof this.data[t]}, got ${typeof e}`);this.data[t]=e;}remove(t){delete this.data[t];}clear(){this.data={};}get length(){return this.keys().length}get size(){return this.length}keys(){return Object.keys(this.data)}values(){return Object.values(this.data)}toArray(){return Object.entries(this.data)}jsonSerialize(){return this.all()}toJson(t=0){return JSON.stringify(this.all(),null,t)}[Symbol.iterator](){return Object.entries(this.data)[Symbol.iterator]()}};var a=class r{static timestamp(t=null){return t==null?0:typeof t=="number"?t:t instanceof Date?Math.floor(t.getTime()/1e3):0}static minuteToSecond(t=null){return r.timestamp(t)||Math.floor(Date.now()/1e3)}static strToDate(t){return new Date(t)}static now(){return Math.floor(Date.now()/1e3)}static addSeconds(t,e){return t+e}static addMinutes(t,e){return t+e*60}static addHours(t,e){return t+e*3600}static addDays(t,e){return t+e*86400}};var l=class{static memory(){return this._memory||(this._memory=new o),this._memory}static has(t){return i.UNDEFINED!==this.get(t,i.UNDEFINED)}static get(t,e){if(this.memory().has(t))return this.memory().get(t,e);let n=process?.env[t];return n!==void 0?n:e}static set(t,e){this.memory().set(t,e);}static remove(t){this.memory().remove(t);}static add(t={}){this.memory().add(t);}static replace(t={}){this.memory().replace(t);}};function T(r){if(typeof r=="number"&&Number.isInteger(r))return r;let e=JSON.stringify(r).replace(/\D/g,"");return e?parseInt(e.slice(0,16),10):0}
2
2
  export{i as Attempt,s as Base64,o as DataBag,l as Envir,a as Timestamp,u as UrlSafeBase64,T as toInt};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "t0n",
3
3
  "description": "Collection of elegant typescript resources for web artisans",
4
- "version": "0.1.2",
4
+ "version": "0.1.3",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -26,9 +26,6 @@
26
26
  "node": ">=18.0.0"
27
27
  },
28
28
  "files": ["dist"],
29
- "publishConfig": {
30
- "registry": "https://registry.npmjs.org"
31
- },
32
29
  "author": "Zunq <open-source@zunq.com>",
33
30
  "license": "MIT",
34
31
  "homepage": "https://zunq.dev",