t0n 0.1.1 → 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,31 +78,10 @@ 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
- type BinaryToTextEncoding = 'base64' | 'base64url' | 'hex' | 'binary' | null;
84
- type Encoding = BinaryToTextEncoding | 'buffer';
85
- declare function md5(str: string): string;
86
- declare function md5(str: Buffer): Buffer;
87
- declare function md5(str: Buffer, encoding: 'buffer'): Buffer;
88
- declare function md5(str: string, encoding: 'buffer' | null | undefined): Buffer;
89
- declare function md5(str: string, encoding: Encoding): string;
90
- declare function sha1(str: string): string;
91
- declare function sha1(str: Buffer): Buffer;
92
- declare function sha1(str: Buffer, encoding: 'buffer'): Buffer;
93
- declare function sha1(str: string, encoding: 'buffer' | null | undefined): Buffer;
94
- declare function sha1(str: string, encoding: Encoding): string;
95
- declare function sha256(str: string): string;
96
- declare function sha256(str: Buffer): Buffer;
97
- declare function sha256(str: Buffer, encoding: 'buffer'): Buffer;
98
- declare function sha256(str: string, encoding: 'buffer' | null | undefined): Buffer;
99
- declare function sha256(str: string, encoding: Encoding): string;
100
- declare function sha512(str: string): string;
101
- declare function sha512(str: Buffer): Buffer;
102
- declare function sha512(str: Buffer, encoding: 'buffer'): Buffer;
103
- declare function sha512(str: string, encoding: 'buffer' | null | undefined): Buffer;
104
- declare function sha512(str: string, encoding: Encoding): string;
105
-
106
85
  declare function toInt(data: any[] | string | number): number;
107
86
 
108
- export { Attempt, type Baggable, Base64, DataBag, Envir, Timestamp, UrlSafeBase64, type VALUE, md5, sha1, sha256, sha512, toInt };
87
+ export { Attempt, type Baggable, Base64, DataBag, Envir, Timestamp, UrlSafeBase64, type VALUE, toInt };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import {createHash}from'crypto';var i=class e{static{this.UNDEFINED=Symbol("UNDEFINED");}static resolve(t,r){let n=e.UNDEFINED;try{n=t();}catch{}return new e(n,r)}static defined(t){return !this.undefined(t)&&!this.isUnset(t)}static undefined(t){return t===e.UNDEFINED||this.isUnset(t)}static isUnset(t){return t==null}constructor(t,r){this.value=t,this._default=r;}or(t){return e.defined(this.value)?this:e.resolve(t,this._default)}default(t){return this._default=t,this}tap(t){let r=this.get();return t?.(r),this}get(){return e.undefined(this.value)?this._default:this.value}getOrThrow(t){let r=this.get();if(e.undefined(r))throw t??new Error("Value is null or undefined");return r}};var s=class{static encode(t){let r=typeof t;return t=this.toString(t,r),(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,r){return r??=typeof t,Buffer.isBuffer(t)||r==="string"?t:Array.isArray(t)||["function","symbol"].includes(r)?t.toString():t===null||["number","bigint","boolean","undefined"].includes(r)?String(t):r==="object"&&!(t instanceof Uint8Array)&&!(t instanceof ArrayBuffer)?JSON.stringify(t):t}},f=class{static encode(t){return s.encode(t)?.replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")||""}static decode(t){let r=t.length%4;return r&&(t+="=".repeat(4-r)),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,r){return this.has(t)?this.data[t]:r}set(t,r){if(this.has(t)&&typeof r!=typeof this.data[t])throw new TypeError(`Type mismatch for key ${t}. Expected ${typeof this.data[t]}, got ${typeof r}`);this.data[t]=r;}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 e{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 e.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,r){return t+r}static addMinutes(t,r){return t+r*60}static addHours(t,r){return t+r*3600}static addDays(t,r){return t+r*86400}};var c=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,r){if(this.memory().has(t))return this.memory().get(t,r);let n=process.env[t];return n!==void 0?n:r}static set(t,r){this.memory().set(t,r);}static remove(t){this.memory().remove(t);}};function u(e,t,r){let n=createHash(t);return typeof e=="string"?n.update(e,"utf8"):n.update(e),!r||r==="buffer"?n.digest():n.digest(r)}function B(e,t="hex"){return u(e,"md5",t)}function E(e,t="hex"){return u(e,"sha1",t)}function v(e,t="hex"){return u(e,"sha256",t)}function D(e,t="hex"){return u(e,"sha512",t)}function w(e){if(typeof e=="number"&&Number.isInteger(e))return e;let r=JSON.stringify(e).replace(/\D/g,"");return r?parseInt(r.slice(0,16),10):0}
2
- export{i as Attempt,s as Base64,o as DataBag,c as Envir,a as Timestamp,f as UrlSafeBase64,B as md5,E as sha1,v as sha256,D as sha512,w as toInt};
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
+ 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.1",
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",