t0n 0.20260804.0 → 0.20260913.0

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/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.20260804.0",
4
+ "version": "0.20260913.0",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
7
7
  "files": ["src"],
@@ -20,11 +20,11 @@
20
20
  "chokidar": "^3.5.2",
21
21
  "citty": "^0.2.2",
22
22
  "consola": "^3.4.2",
23
- "hono": "^4.12.8",
23
+ "hono": "^4.13.7",
24
24
  "pathe": "^2.0"
25
25
  },
26
26
  "devDependencies": {
27
- "bun-types": "^1.3.14",
27
+ "bun-types": "^1.4.0",
28
28
  "tsx": "^4.19.4",
29
29
  "typescript": "^5.9.3"
30
30
  },
package/src/cli.ts CHANGED
@@ -112,15 +112,17 @@ export const killProcess = async (proc: Bun.Subprocess | null) => {
112
112
 
113
113
  import { isColorSupported, dim } from './color'
114
114
  import { defineCommand, runMain, renderUsage } from 'citty'
115
- import type { ArgsDef, CommandDef } from 'citty'
115
+ import type { ArgsDef, CommandContext, CommandDef } from 'citty'
116
116
  import { createConsola } from 'consola'
117
117
 
118
118
  export { defineCommand as command }
119
- export function cli({ name, description, version, commands }: {
119
+ export function cli({ name, description, version, commands, setup, cleanup }: {
120
120
  name: string,
121
121
  description?: string,
122
122
  version: string,
123
123
  commands: Record<string, string>,
124
+ setup?: ((context: CommandContext) => any | Promise<any>),
125
+ cleanup?: ((context: CommandContext) => any | Promise<any>)
124
126
  }) {
125
127
  const _cli = description || name.toUpperCase()
126
128
  const v = [_cli, isColorSupported ? dim('v'+version) : version].join(' ')
@@ -150,5 +152,6 @@ export function cli({ name, description, version, commands }: {
150
152
  description: _cli,
151
153
  },
152
154
  subCommands: Object.fromEntries(Object.entries(commands).map(([key, path]) => [key, () => import(path).then(r => r.default)])),
155
+ setup, cleanup,
153
156
  }), { rawArgs: length ? undefined : ['-h'], showUsage })
154
157
  }
package/src/id.ts CHANGED
@@ -17,6 +17,7 @@ export function newID() {
17
17
 
18
18
  if (idCache.has(id))
19
19
  id = id.slice(0, 5) + Date.now().toString(36).slice(-3)
20
+ // Math.random().toString(36).substring(2)
20
21
 
21
22
  return id.replace(/[-_]/g, '')
22
23
  }
package/src/string.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  const normalize = (text: string, sep: string) =>
2
2
  text.replace(/([a-z])([A-Z])/g, `$1${sep}$2`)
3
- .replace(/[\s\-_]+/g, sep)
3
+ .replace(/[\s\.\-_\/\\]+/g, sep)
4
4
  .toLowerCase()
5
5
  .replace(new RegExp(`[^\\w${sep}]+`, 'g'), '')
6
6
  .replace(new RegExp(`${sep}{2,}`, 'g'), sep)
package/src/timestamp.ts CHANGED
@@ -8,7 +8,7 @@ export class Timestamp {
8
8
  return Math.floor(date.getTime() / 1000)
9
9
  }
10
10
 
11
- return 0
11
+ return Number(date) || 0
12
12
  }
13
13
 
14
14
  static minuteToSecond(date: number | Date | null = null): number {
package/src/toint.ts CHANGED
@@ -1,8 +1,10 @@
1
- export function toInt(data: any[] | string | number): number {
2
- if (typeof data === 'number' && Number.isInteger(data))
3
- return data
1
+ export function toInt(val: any[] | string | number): number {
2
+ if (typeof val === 'number')
3
+ return Math.abs(val)
4
+ // if (typeof data === 'number' && Number.isInteger(data))
5
+ // return data
4
6
 
5
- const jsonString = JSON.stringify(data)
7
+ const jsonString = JSON.stringify(val)
6
8
  // Simplified implementation without MD5 (less accurate than the original)
7
9
  // TODO: add o md5 and stable-hash
8
10
  const numericString = jsonString.replace(/\D/g, '')