@sf-kmods/kdataforgejs 0.1.19 → 2026.4.19

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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/index.d.ts +175 -0
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -17,7 +17,7 @@ npm install --save-dev @sf-kmods/kdataforgejs
17
17
  // DataForge/scripts/main.ts
18
18
  import { defineHandler, defineMeta } from "@sf-kmods/kdataforgejs";
19
19
 
20
- export const meta = defineMeta({ capabilities: ["kdf.reflection.read"] }); // optional
20
+ export const meta = defineMeta({ capabilities: ["kdf.items.define"] }); // optional
21
21
  ```
22
22
 
23
23
  This package is **editor tooling only**. Packs never contain `package.json` or `node_modules`; the runtime resolves
package/index.d.ts CHANGED
@@ -164,7 +164,152 @@ declare module "@sf-kmods/kdataforgejs" {
164
164
  export interface BehaviorRegistration { readonly id: string; }
165
165
  export interface BehaviorInstance { readonly __kdfBehaviorInstance: never; }
166
166
  export interface TickSubscription extends Subscription { }
167
+ export interface ModMeta {
168
+ readonly reference: string; readonly name: string; readonly version: string; readonly description: string;
169
+ readonly authors: string; readonly docsUrl: string; readonly supportUrl: string;
170
+ }
171
+ export interface PackMeta { readonly reference: string; readonly name: string; readonly version: string; readonly priority: number; }
167
172
  export interface Conditions { all(conditions: readonly boolean[]): boolean; any(conditions: readonly boolean[]): boolean; }
173
+ export type Comparable = string | number | bigint;
174
+ export type Falsy = false | 0 | 0n | "" | null | undefined;
175
+ export type Truthy<T> = T extends Falsy ? never : T;
176
+ export type OmitKeys<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
177
+ export interface ArrayHelpers {
178
+ chunk<T>(values: readonly T[], size: number): T[][];
179
+ compact<T>(values: readonly T[]): Array<Truthy<T>>;
180
+ unique<T>(values: readonly T[]): T[];
181
+ uniqueBy<T, K>(values: readonly T[], select: (value: T, index: number) => K): T[];
182
+ groupBy<T, K extends PropertyKey>(values: readonly T[], select: (value: T, index: number) => K): Record<K, T[]>;
183
+ keyBy<T, K extends PropertyKey>(values: readonly T[], select: (value: T, index: number) => K): Record<K, T>;
184
+ partition<T>(values: readonly T[], predicate: (value: T, index: number) => unknown): [T[], T[]];
185
+ flatten<T>(values: readonly (T | readonly T[])[]): T[];
186
+ flattenDeep<T>(values: readonly unknown[]): T[];
187
+ first<T>(values: readonly T[]): T | undefined;
188
+ last<T>(values: readonly T[]): T | undefined;
189
+ initial<T>(values: readonly T[]): T[];
190
+ tail<T>(values: readonly T[]): T[];
191
+ take<T>(values: readonly T[], count: number): T[];
192
+ takeRight<T>(values: readonly T[], count: number): T[];
193
+ drop<T>(values: readonly T[], count: number): T[];
194
+ dropRight<T>(values: readonly T[], count: number): T[];
195
+ zip(...values: readonly (readonly unknown[])[]): unknown[][];
196
+ unzip<T>(values: readonly (readonly T[])[]): Array<Array<T | undefined>>;
197
+ rotate<T>(values: readonly T[], amount: number): T[];
198
+ difference<T>(values: readonly T[], excluded: readonly T[]): T[];
199
+ intersection<T>(values: readonly T[], other: readonly T[]): T[];
200
+ union<T>(...values: readonly (readonly T[])[]): T[];
201
+ sortBy<T, K extends Comparable>(values: readonly T[], select: (value: T, index: number) => K): T[];
202
+ minBy<T, K extends Comparable>(values: readonly T[], select: (value: T, index: number) => K): T | undefined;
203
+ maxBy<T, K extends Comparable>(values: readonly T[], select: (value: T, index: number) => K): T | undefined;
204
+ countBy<T, K extends PropertyKey>(values: readonly T[], select: (value: T, index: number) => K): Record<K, number>;
205
+ }
206
+ export interface StringHelpers {
207
+ capitalize(value: string): string; decapitalize(value: string): string; words(value: string): string[];
208
+ camelCase(value: string): string; pascalCase(value: string): string; kebabCase(value: string): string;
209
+ snakeCase(value: string): string; titleCase(value: string): string; slugify(value: string): string;
210
+ truncate(value: string, length: number, suffix?: string): string; padCenter(value: string, length: number, fill?: string): string;
211
+ reverse(value: string): string; countOccurrences(value: string, search: string): number;
212
+ removePrefix(value: string, prefix: string): string; removeSuffix(value: string, suffix: string): string;
213
+ ensurePrefix(value: string, prefix: string): string; ensureSuffix(value: string, suffix: string): string;
214
+ before(value: string, search: string): string; after(value: string, search: string): string;
215
+ between(value: string, start: string, end: string): string; lines(value: string): string[];
216
+ normalizeWhitespace(value: string): string; isBlank(value: string): boolean; escapeRegExp(value: string): string;
217
+ stripIndent(value: string): string;
218
+ }
219
+ export interface NumberHelpers {
220
+ clamp(value: number, minimum: number, maximum: number): number; lerp(start: number, end: number, alpha: number): number;
221
+ inverseLerp(start: number, end: number, value: number): number;
222
+ remap(value: number, sourceStart: number, sourceEnd: number, targetStart: number, targetEnd: number): number;
223
+ wrap(value: number, minimum: number, maximum: number): number; roundTo(value: number, step?: number): number;
224
+ floorTo(value: number, step?: number): number; ceilTo(value: number, step?: number): number;
225
+ sum(values: readonly number[]): number; average(values: readonly number[]): number | undefined;
226
+ median(values: readonly number[]): number | undefined; mode(values: readonly number[]): number | undefined;
227
+ min(values: readonly number[]): number | undefined; max(values: readonly number[]): number | undefined;
228
+ product(values: readonly number[]): number; percentage(value: number, total: number): number;
229
+ percentOf(percent: number, total: number): number; nearlyEqual(left: number, right: number, epsilon?: number): boolean;
230
+ signNonZero(value: number): -1 | 1; inRange(value: number, minimum: number, maximum: number, inclusive?: boolean): boolean;
231
+ }
232
+ export interface ObjectHelpers {
233
+ pick<T extends object, K extends keyof T>(value: T, keys: readonly K[]): Pick<T, K>;
234
+ omit<T extends object, K extends keyof T>(value: T, keys: readonly K[]): OmitKeys<T, K>;
235
+ mapValues<T extends object, R>(value: T, transform: (item: T[keyof T], key: string) => R): Record<string, R>;
236
+ mapKeys<T extends object, K extends PropertyKey>(value: T, transform: (key: string, item: T[keyof T]) => K): Record<K, T[keyof T]>;
237
+ filterEntries<T extends object>(value: T, predicate: (item: T[keyof T], key: string) => unknown): Partial<T>;
238
+ invert(value: Readonly<Record<string, PropertyKey>>): Record<PropertyKey, string>;
239
+ fromPairs<K extends PropertyKey, V>(pairs: Iterable<readonly [K, V]>): Record<K, V>;
240
+ toPairs<T extends object>(value: T): Array<[string, T[keyof T]]>;
241
+ mergeDefined<T extends object>(...values: readonly Partial<T>[]): Partial<T>;
242
+ getPath<T = unknown>(value: unknown, path: readonly PropertyKey[], fallback?: T): T | undefined;
243
+ hasPath(value: unknown, path: readonly PropertyKey[]): boolean;
244
+ setPath<T>(value: T, path: readonly PropertyKey[], nextValue: unknown): T;
245
+ deepFreeze<T>(value: T): Readonly<T>; isEmpty(value: object): boolean;
246
+ entriesSorted<T extends object>(value: T): Array<[string, T[keyof T]]>;
247
+ }
248
+ export interface GuardHelpers {
249
+ isDefined<T>(value: T | undefined): value is T; isNil(value: unknown): value is null | undefined;
250
+ isBoolean(value: unknown): value is boolean; isNumber(value: unknown): value is number;
251
+ isFiniteNumber(value: unknown): value is number; isInteger(value: unknown): value is number;
252
+ isSafeInteger(value: unknown): value is number; isBigInt(value: unknown): value is bigint;
253
+ isString(value: unknown): value is string; isNonEmptyString(value: unknown): value is string;
254
+ isArray(value: unknown): value is unknown[]; isObject(value: unknown): value is object;
255
+ isPlainObject(value: unknown): value is Record<PropertyKey, unknown>; isFunction(value: unknown): value is Function;
256
+ isPromiseLike<T = unknown>(value: unknown): value is PromiseLike<T>; isIterable<T = unknown>(value: unknown): value is Iterable<T>;
257
+ isMap(value: unknown): value is Map<unknown, unknown>; isSet(value: unknown): value is Set<unknown>;
258
+ assertDefined<T>(value: T | null | undefined, message?: string): T; assertNever(value: never, message?: string): never;
259
+ }
260
+ export interface CollectionHelpers {
261
+ getOrCreate<K, V>(map: Map<K, V>, key: K, create: (key: K) => V): V;
262
+ mapMap<K, V, RK, RV>(map: Map<K, V>, transform: (value: V, key: K) => readonly [RK, RV]): Map<RK, RV>;
263
+ filterMap<K, V>(map: Map<K, V>, predicate: (value: V, key: K) => unknown): Map<K, V>;
264
+ mapSet<T, R>(set: Set<T>, transform: (value: T) => R): Set<R>;
265
+ filterSet<T>(set: Set<T>, predicate: (value: T) => unknown): Set<T>;
266
+ toggleSet<T>(set: Set<T>, value: T, force?: boolean): boolean;
267
+ addToMapSet<K, V>(map: Map<K, Set<V>>, key: K, value: V): Set<V>;
268
+ removeFromMapSet<K, V>(map: Map<K, Set<V>>, key: K, value: V): boolean;
269
+ frequency<T>(values: Iterable<T>): Map<T, number>; hasDuplicates<T>(values: Iterable<T>): boolean;
270
+ }
271
+ export interface FunctionHelpers {
272
+ identity<T>(value: T): T; constant<T>(value: T): () => T; noop(): void;
273
+ tap<T>(value: T, effect: (value: T) => void): T; negate<A extends readonly unknown[]>(predicate: (...args: A) => unknown): (...args: A) => boolean;
274
+ once<A extends readonly unknown[], R>(callback: (...args: A) => R): (...args: A) => R;
275
+ memoize<A extends readonly unknown[], K, R>(callback: (...args: A) => R, selectKey?: (...args: A) => K): (...args: A) => R;
276
+ pipe<A, B>(first: (value: A) => B): (value: A) => B;
277
+ pipe<A, B, C>(first: (value: A) => B, second: (value: B) => C): (value: A) => C;
278
+ pipe<A, B, C, D>(first: (value: A) => B, second: (value: B) => C, third: (value: C) => D): (value: A) => D;
279
+ compose<A, B>(first: (value: A) => B): (value: A) => B;
280
+ compose<A, B, C>(second: (value: B) => C, first: (value: A) => B): (value: A) => C;
281
+ compose<A, B, C, D>(third: (value: C) => D, second: (value: B) => C, first: (value: A) => B): (value: A) => D;
282
+ times<T>(count: number, callback: (index: number) => T): T[];
283
+ tryOr<T>(callback: () => T, fallback: T | ((error: unknown) => T)): T;
284
+ }
285
+ export interface SemVer {
286
+ readonly major: number; readonly minor: number; readonly patch: number;
287
+ readonly prerelease: readonly (string | number)[]; readonly build: readonly string[];
288
+ }
289
+ export type SemVerInput = string | SemVer;
290
+ export type SemVerRelease = "major" | "minor" | "patch" | "prerelease";
291
+ /** Semantic Versioning 2.0 with npm-style ranges: `^`, `~`, `>=`, `1.x`, `1.2 - 1.4`, `||`, space for AND. */
292
+ export interface SemVerHelpers {
293
+ parse(value: string): SemVer | null;
294
+ create(major: number, minor?: number, patch?: number, prerelease?: readonly (string | number)[], build?: readonly string[]): SemVer;
295
+ format(version: SemVerInput): string; isValid(value: unknown): boolean; coerce(value: unknown): SemVer | null;
296
+ compare(left: SemVerInput, right: SemVerInput): -1 | 0 | 1;
297
+ eq(left: SemVerInput, right: SemVerInput): boolean; neq(left: SemVerInput, right: SemVerInput): boolean;
298
+ gt(left: SemVerInput, right: SemVerInput): boolean; gte(left: SemVerInput, right: SemVerInput): boolean;
299
+ lt(left: SemVerInput, right: SemVerInput): boolean; lte(left: SemVerInput, right: SemVerInput): boolean;
300
+ satisfies(version: SemVerInput, range: string): boolean;
301
+ maxSatisfying<T extends SemVerInput>(versions: readonly T[], range: string): T | undefined;
302
+ sort<T extends SemVerInput>(versions: readonly T[]): T[];
303
+ inc(version: SemVerInput, release: SemVerRelease): SemVer;
304
+ }
305
+ export const arrays: Readonly<ArrayHelpers>;
306
+ export const strings: Readonly<StringHelpers>;
307
+ export const numbers: Readonly<NumberHelpers>;
308
+ export const objects: Readonly<ObjectHelpers>;
309
+ export const guards: Readonly<GuardHelpers>;
310
+ export const collections: Readonly<CollectionHelpers>;
311
+ export const functions: Readonly<FunctionHelpers>;
312
+ export const semver: Readonly<SemVerHelpers>;
168
313
  /** Canonical descriptor identity. `id` names authored content; `classPath` names an existing soft class path. */
169
314
  export type ItemReference = Readonly<{ id: string }> | Readonly<{ classPath: string }>;
170
315
  export interface LocalizedText { readonly namespace: string; readonly key: string; readonly source: string; }
@@ -244,6 +389,18 @@ declare module "@sf-kmods/kdataforgejs" {
244
389
  /** Frozen context supplied to default main. Every member below is installed by KDFJSRuntime. */
245
390
  export interface Context {
246
391
  readonly catalog: () => Catalog;
392
+ /** Lowercase MD5 digest of UTF-8 text. */
393
+ readonly md5: (text: string) => string;
394
+ /** Lowercase SHA-1 digest of UTF-8 text. */
395
+ readonly sha1: (text: string) => string;
396
+ /** Lowercase SHA-256 digest of UTF-8 text. */
397
+ readonly sha256: (text: string) => string;
398
+ /** Eight-character lowercase CRC-32 digest of UTF-8 text. */
399
+ readonly crc32: (text: string) => string;
400
+ /** Random UUID in lowercase RFC 4122 hyphenated form. */
401
+ readonly uuid: () => string;
402
+ readonly createCleanupBag: () => CleanupBag;
403
+ readonly isValid: (value: Target | null | undefined) => boolean;
247
404
  readonly target: { (): Realm; (name: "realm"): Realm; };
248
405
  readonly getClass: {
249
406
  <C extends Class<UObject>, P extends NativeClassPathFor<C>>(type: C, path: P, options: CheckedLookupOptions): C;
@@ -275,6 +432,17 @@ declare module "@sf-kmods/kdataforgejs" {
275
432
  readonly import: (kind: "text" | "yaml" | "binary" | "image" | "audio", path: string) => StructuredValue;
276
433
  readonly compare: (left: InputValue, operator: CompareOperator, right: InputValue) => boolean;
277
434
  readonly isAuthority: () => boolean;
435
+ /** True when SML loaded the mod. With `range` (same syntax as the `modVersion` condition, e.g. `^3.12.0`) its version must match too. */
436
+ readonly isModLoaded: (reference: string, range?: string) => boolean;
437
+ /** Metadata of a loaded mod, or `null` when it is not loaded. */
438
+ readonly getModMeta: (reference: string) => ModMeta | null;
439
+ readonly listMods: () => readonly ModMeta[];
440
+ /** True when the KDataForge pack takes part in the current load. With `range` its pack.yml version must match too. */
441
+ readonly isPackLoaded: (reference: string, range?: string) => boolean;
442
+ readonly getPackMeta: (reference: string) => PackMeta | null;
443
+ readonly listPacks: () => readonly PackMeta[];
444
+ /** Game build number, the value `gameVersion:` conditions compare. */
445
+ readonly gameVersion: () => number;
278
446
  readonly conditions: Conditions;
279
447
  readonly on: {
280
448
  (target: Target, eventId: string, callback: PositionalEventCallback): Subscription;
@@ -314,8 +482,15 @@ declare module "@sf-kmods/kdataforgejs" {
314
482
  readonly unregisterTick: (key: string) => void;
315
483
  readonly setTimeout: (callback: () => void, seconds: number) => Subscription;
316
484
  readonly clearTimeout: (handle: Subscription) => void;
485
+ readonly setInterval: (callback: () => void, seconds: number) => Subscription;
486
+ readonly clearInterval: (handle: Subscription) => void;
317
487
  readonly log: (...data: readonly unknown[]) => void; readonly info: (...data: readonly unknown[]) => void;
318
488
  readonly warn: (...data: readonly unknown[]) => void; readonly error: (...data: readonly unknown[]) => void;
319
489
  readonly debug: (...data: readonly unknown[]) => void;
320
490
  }
491
+
492
+ export interface CleanupBag {
493
+ readonly add: (cleanup: () => void) => void;
494
+ readonly dispose: () => void;
495
+ }
321
496
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sf-kmods/kdataforgejs",
3
- "version": "0.1.19",
3
+ "version": "2026.4.19",
4
4
  "description": "TypeScript types for KDataForgeJS packs: declarations of the built-in @sf-kmods/kdataforgejs module plus a strict tsconfig base.",
5
5
  "license": "MIT",
6
6
  "author": "Kyri123/Kyrium",