t0n 0.1.0 → 0.1.1

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,17 @@ declare class DataBag<T = any> implements Baggable<T> {
60
60
  [Symbol.iterator](): IterableIterator<[string, T]>;
61
61
  }
62
62
 
63
+ declare class Timestamp {
64
+ static timestamp(date?: number | Date | null): number;
65
+ static minuteToSecond(date?: number | Date | null): number;
66
+ static strToDate(str: string): Date;
67
+ static now(): number;
68
+ static addSeconds(timestamp: number, seconds: number): number;
69
+ static addMinutes(timestamp: number, minutes: number): number;
70
+ static addHours(timestamp: number, hours: number): number;
71
+ static addDays(timestamp: number, days: number): number;
72
+ }
73
+
63
74
  declare class Envir {
64
75
  private static _memory;
65
76
  private static memory;
@@ -94,4 +105,4 @@ declare function sha512(str: string, encoding: Encoding): string;
94
105
 
95
106
  declare function toInt(data: any[] | string | number): number;
96
107
 
97
- export { Attempt, type Baggable, Base64, DataBag, Envir, UrlSafeBase64, type VALUE, md5, sha1, sha256, sha512, toInt };
108
+ export { Attempt, type Baggable, Base64, DataBag, Envir, Timestamp, UrlSafeBase64, type VALUE, md5, sha1, sha256, sha512, 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{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 T(e,t="hex"){return u(e,"md5",t)}function x(e,t="hex"){return u(e,"sha1",t)}function B(e,t="hex"){return u(e,"sha256",t)}function E(e,t="hex"){return u(e,"sha512",t)}function A(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,a as Envir,f as UrlSafeBase64,T as md5,x as sha1,B as sha256,E as sha512,A as toInt};
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};
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.0",
4
+ "version": "0.1.1",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",