Fixed path events casing issue
This commit is contained in:
parent
e3bbd13ed8
commit
4ed23e1502
14
index.html
14
index.html
@ -1,19 +1,9 @@
|
||||
<html>
|
||||
<body>
|
||||
<script type="module">
|
||||
import {Cache, Database} from './dist/index.mjs';
|
||||
import {PES} from './dist/index.mjs';
|
||||
|
||||
const db = new Database('test');
|
||||
db.connection.then(() => {
|
||||
console.log(db.tables);
|
||||
});
|
||||
|
||||
const table = window.table = await db.createTable('test2');
|
||||
table.add({ name: 'Alice', age: 30 });
|
||||
table.add({ name: 'Bob', age: 24 });
|
||||
table.add({ name: 'Carol', age: 30 });
|
||||
|
||||
console.log(db.tables);
|
||||
console.log(PES`storage${'Test/Test'}:d`);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ztimson/utils",
|
||||
"version": "0.25.10",
|
||||
"version": "0.25.12",
|
||||
"description": "Utility library",
|
||||
"author": "Zak Timson",
|
||||
"license": "MIT",
|
||||
|
@ -48,7 +48,7 @@ export function PES(str: TemplateStringsArray, ...args: any[]) {
|
||||
if(str[i]) combined.push(str[i]);
|
||||
if(args[i]) combined.push(args[i]);
|
||||
}
|
||||
const [paths, methods] = combined.join('').split(':');
|
||||
const [paths, methods] = combined.join('/').split(':');
|
||||
return PathEvent.toString(paths, <any>methods?.split(''));
|
||||
}
|
||||
|
||||
@ -254,8 +254,8 @@ export class PathEventEmitter implements IPathEventEmitter{
|
||||
constructor(public readonly prefix: string = '') { }
|
||||
|
||||
emit(event: Event, ...args: any[]) {
|
||||
const parsed = new PathEvent(`${this.prefix}/${new PathEvent(event).toString()}`);
|
||||
this.listeners.filter(l => PathEvent.has(l[0], `${this.prefix}/${event}`))
|
||||
const parsed = PE`${this.prefix}/${event}`;
|
||||
this.listeners.filter(l => PathEvent.has(l[0], parsed))
|
||||
.forEach(async l => l[1](parsed, ...args));
|
||||
};
|
||||
|
||||
|
32
src/time.ts
32
src/time.ts
@ -190,3 +190,35 @@ export async function sleepWhile(fn : () => boolean | Promise<boolean>, checkInt
|
||||
export function timeUntil(date: Date | number): number {
|
||||
return (date instanceof Date ? date.getTime() : date) - (new Date()).getTime();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert a timezone string (e.g., "America/Toronto") to its current UTC offset in minutes.
|
||||
* @param {string} tz - Timezone string, e.g. "America/Toronto"
|
||||
* @param {Date} [date=new Date()] - The date for which you want the offset (default is now)
|
||||
* @returns {number} - Offset in minutes (e.g., -240)
|
||||
*/
|
||||
export function timezoneOffset(tz: string, date: Date = new Date()): number {
|
||||
const dtf = new Intl.DateTimeFormat('en-US', {
|
||||
timeZone: tz,
|
||||
hour12: false,
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
second: '2-digit',
|
||||
});
|
||||
const parts = dtf.formatToParts(date);
|
||||
const get = (type: string) => Number(parts.find(v => v.type === type)?.value);
|
||||
const y = get('year');
|
||||
const mo = get('month');
|
||||
const d = get('day');
|
||||
const h = get('hour');
|
||||
const m = get('minute');
|
||||
const s = get('second');
|
||||
|
||||
const asUTC = Date.UTC(y, mo - 1, d, h, m, s);
|
||||
const asLocal = date.getTime();
|
||||
return Math.round((asLocal - asUTC) / 60000);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user