t0n 0.1.4 → 0.1.6

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/dist/index.d.ts CHANGED
@@ -60,6 +60,32 @@ declare class DataBag<T = any> implements Baggable<T> {
60
60
  [Symbol.iterator](): IterableIterator<[string, T]>;
61
61
  }
62
62
 
63
+ type EnumType<T> = T extends string[] ? {
64
+ [K in T[number]]: K;
65
+ } : T extends Record<string, string | number> ? T : never;
66
+ type EnumValue<T> = T extends string[] ? T[number] : T extends Record<string, infer V> ? V : never;
67
+ type EnumStatic<T> = {
68
+ has(search: string | number): boolean;
69
+ key(search: string | number): string | null;
70
+ value(search: string | number): EnumValue<T> | null;
71
+ readonly keys: string[];
72
+ readonly values: Array<EnumValue<T>>;
73
+ toObject(): EnumType<T>;
74
+ } & EnumType<T>;
75
+ declare function Enum<T extends string[] | Record<string, string | number>>(definition: T): EnumStatic<T>;
76
+
77
+ declare class Envir {
78
+ #private;
79
+ static has(key: string): boolean;
80
+ static get<T = any>(key: string, defaultValue?: T): T | undefined;
81
+ static set<T = any>(key: string, value: T): void;
82
+ static remove(key: string): void;
83
+ static add<T = any>(data?: Record<string, T>): void;
84
+ static replace<T = any>(data?: Record<string, T>): void;
85
+ }
86
+
87
+ declare function getLength(item: any, type?: string): number;
88
+
63
89
  declare class Timestamp {
64
90
  static timestamp(date?: number | Date | null): number;
65
91
  static minuteToSecond(date?: number | Date | null): number;
@@ -71,17 +97,6 @@ declare class Timestamp {
71
97
  static addDays(timestamp: number, days: number): number;
72
98
  }
73
99
 
74
- declare class Envir {
75
- private static _memory;
76
- private static memory;
77
- static has(key: string): boolean;
78
- static get<T = any>(key: string, defaultValue?: T): T | undefined;
79
- static set<T = any>(key: string, value: T): void;
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;
83
- }
84
-
85
100
  declare function toInt(data: any[] | string | number): number;
86
101
 
87
- export { Attempt, type Baggable, Base64, DataBag, Envir, Timestamp, UrlSafeBase64, type VALUE, toInt };
102
+ export { Attempt, type Baggable, Base64, DataBag, Enum, type EnumStatic, type EnumType, type EnumValue, Envir, Timestamp, UrlSafeBase64, type VALUE, getLength, toInt };
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 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,e){if(this.memory().has(t))return this.memory().get(t,e);try{let n=process?.env[t];return n!==void 0?n:e}catch{return 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,c as Envir,a as Timestamp,u as UrlSafeBase64,T as toInt};
1
+ var c=class r{static{this.UNDEFINED=Symbol("UNDEFINED");}static resolve(t,e){let s=r.UNDEFINED;try{s=t();}catch{}return new r(s,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 u=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}},l=class{static encode(t){return u.encode(t)?.replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")||""}static decode(t){let e=t.length%4;return e&&(t+="=".repeat(4-e)),u.decode(t.replace(/-/g,"+").replace(/_/g,"/"))}};var a=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]()}};function m(r){let t=Array.isArray(r)?Object.fromEntries(r.map(n=>[n,n])):r,e=new Map,s=new Map;Object.entries(t).forEach(([n,i])=>{e.set(n,i),s.set(String(i),n),typeof i=="number"&&s.set(i.toString(),n);});let o=class{static has(n){return e.has(n)||s.has(String(n))}static key(n){return e.has(n)?n:s.get(String(n))||null}static value(n){return e.has(n)?e.get(n):s.has(String(n))?e.get(s.get(String(n))):null}static get keys(){return Object.keys(t)}static get values(){return Object.values(t)}static toObject(){return {...t}}};return Object.entries(t).forEach(([n,i])=>{o[n]=i;}),o}var g=class{static#t;static{this.#t=new a;}static has(t){try{return this.#t.has(t)||t in process.env}catch{return false}}static get(t,e){if(this.#t.has(t))return this.#t.get(t,e);try{let s=process?.env[t];return s!==void 0?s:e}catch{return e}}static set(t,e){this.#t.set(t,e);}static remove(t){this.#t.remove(t);}static add(t={}){this.#t.add(t);}static replace(t={}){this.#t.replace(t);}};function v(r,t){switch(t||(t=typeof r),t){case "string":return r.length;case "number":case "bigint":return r.toString().length;case "object":return r===null?0:Array.isArray(r)?r.length:Object.keys(r).length;case "undefined":default:return 0}}var b=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}};function w(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{c as Attempt,u as Base64,a as DataBag,m as Enum,g as Envir,b as Timestamp,l as UrlSafeBase64,v as getLength,w 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.4",
4
+ "version": "0.1.6",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",