@agiflowai/aicode-utils 1.0.5 → 1.0.7

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.cjs CHANGED
@@ -748,6 +748,36 @@ var ScaffoldProcessingService = class {
748
748
  }
749
749
  };
750
750
 
751
+ //#endregion
752
+ //#region src/utils/generateStableId.ts
753
+ /**
754
+ * Generate a stable, random ID string
755
+ *
756
+ * @param length - Length of the ID to generate (default: 8)
757
+ * @returns A random alphanumeric ID string (lowercase)
758
+ *
759
+ * @remarks
760
+ * Negative or non-integer lengths are normalized (floored and clamped to 0).
761
+ * Returns empty string for length <= 0.
762
+ *
763
+ * @example
764
+ * ```typescript
765
+ * const id = generateStableId(6); // Returns something like "a3f9k2"
766
+ * ```
767
+ */
768
+ function generateStableId(length = 8) {
769
+ const chars = "abcdefghijklmnopqrstuvwxyz0123456789";
770
+ let result = "";
771
+ const normalizedLength = Math.max(0, Math.floor(length));
772
+ if (normalizedLength === 0) return "";
773
+ if (typeof crypto !== "undefined" && crypto.getRandomValues) {
774
+ const values = new Uint8Array(normalizedLength);
775
+ crypto.getRandomValues(values);
776
+ for (let i = 0; i < normalizedLength; i++) result += chars[values[i] % 36];
777
+ } else for (let i = 0; i < normalizedLength; i++) result += chars[Math.floor(Math.random() * 36)];
778
+ return result;
779
+ }
780
+
751
781
  //#endregion
752
782
  //#region src/utils/print.ts
753
783
  /**
@@ -995,6 +1025,7 @@ Object.defineProperty(exports, 'fs', {
995
1025
  return node_fs_promises;
996
1026
  }
997
1027
  });
1028
+ exports.generateStableId = generateStableId;
998
1029
  exports.icons = icons;
999
1030
  exports.isMonolith = isMonolith;
1000
1031
  exports.isMonorepo = isMonorepo;
package/dist/index.d.cts CHANGED
@@ -403,6 +403,24 @@ declare const rename: typeof fs.rename;
403
403
  declare const rm: typeof fs.rm;
404
404
  declare const cp: typeof fs.cp;
405
405
  //#endregion
406
+ //#region src/utils/generateStableId.d.ts
407
+ /**
408
+ * Generate a stable, random ID string
409
+ *
410
+ * @param length - Length of the ID to generate (default: 8)
411
+ * @returns A random alphanumeric ID string (lowercase)
412
+ *
413
+ * @remarks
414
+ * Negative or non-integer lengths are normalized (floored and clamped to 0).
415
+ * Returns empty string for length <= 0.
416
+ *
417
+ * @example
418
+ * ```typescript
419
+ * const id = generateStableId(6); // Returns something like "a3f9k2"
420
+ * ```
421
+ */
422
+ declare function generateStableId(length?: number): string;
423
+ //#endregion
406
424
  //#region src/utils/logger.d.ts
407
425
  declare const logger: pino.Logger<never, boolean>;
408
426
  declare const log: {
@@ -580,4 +598,4 @@ declare function isMonorepo(workspaceRoot: string): Promise<boolean>;
580
598
  */
581
599
  declare function isMonolith(workspaceRoot: string): Promise<boolean>;
582
600
  //#endregion
583
- export { ConfigSource, GeneratorContext, GeneratorFunction, IFileSystemService, IVariableReplacementService, NxProjectJson, ParsedInclude, ProjectConfig, ProjectConfigResolver, ProjectConfigResult, ProjectFinderService, ProjectType, ProjectTypeDetectionResult, ScaffoldProcessingService, ScaffoldResult, TemplatesManagerService, ToolkitConfig, accessSync, copy, cp, detectProjectType, ensureDir, ensureDirSync, fs, icons, isMonolith, isMonorepo, log, logger, messages, mkdir, mkdirSync, move, outputFile, pathExists, pathExistsSync, print, readFile, readFileSync, readJson, readJsonSync, readdir, remove, rename, rm, sections, stat, statSync, unlink, writeFile, writeFileSync, writeJson, writeJsonSync };
601
+ export { ConfigSource, GeneratorContext, GeneratorFunction, IFileSystemService, IVariableReplacementService, NxProjectJson, ParsedInclude, ProjectConfig, ProjectConfigResolver, ProjectConfigResult, ProjectFinderService, ProjectType, ProjectTypeDetectionResult, ScaffoldProcessingService, ScaffoldResult, TemplatesManagerService, ToolkitConfig, accessSync, copy, cp, detectProjectType, ensureDir, ensureDirSync, fs, generateStableId, icons, isMonolith, isMonorepo, log, logger, messages, mkdir, mkdirSync, move, outputFile, pathExists, pathExistsSync, print, readFile, readFileSync, readJson, readJsonSync, readdir, remove, rename, rm, sections, stat, statSync, unlink, writeFile, writeFileSync, writeJson, writeJsonSync };
package/dist/index.d.mts CHANGED
@@ -403,6 +403,24 @@ declare const rename: typeof fs.rename;
403
403
  declare const rm: typeof fs.rm;
404
404
  declare const cp: typeof fs.cp;
405
405
  //#endregion
406
+ //#region src/utils/generateStableId.d.ts
407
+ /**
408
+ * Generate a stable, random ID string
409
+ *
410
+ * @param length - Length of the ID to generate (default: 8)
411
+ * @returns A random alphanumeric ID string (lowercase)
412
+ *
413
+ * @remarks
414
+ * Negative or non-integer lengths are normalized (floored and clamped to 0).
415
+ * Returns empty string for length <= 0.
416
+ *
417
+ * @example
418
+ * ```typescript
419
+ * const id = generateStableId(6); // Returns something like "a3f9k2"
420
+ * ```
421
+ */
422
+ declare function generateStableId(length?: number): string;
423
+ //#endregion
406
424
  //#region src/utils/logger.d.ts
407
425
  declare const logger: pino.Logger<never, boolean>;
408
426
  declare const log: {
@@ -580,4 +598,4 @@ declare function isMonorepo(workspaceRoot: string): Promise<boolean>;
580
598
  */
581
599
  declare function isMonolith(workspaceRoot: string): Promise<boolean>;
582
600
  //#endregion
583
- export { ConfigSource, GeneratorContext, GeneratorFunction, IFileSystemService, IVariableReplacementService, NxProjectJson, ParsedInclude, ProjectConfig, ProjectConfigResolver, ProjectConfigResult, ProjectFinderService, ProjectType, ProjectTypeDetectionResult, ScaffoldProcessingService, ScaffoldResult, TemplatesManagerService, ToolkitConfig, accessSync, copy, cp, detectProjectType, ensureDir, ensureDirSync, fs, icons, isMonolith, isMonorepo, log, logger, messages, mkdir, mkdirSync, move, outputFile, pathExists, pathExistsSync, print, readFile, readFileSync, readJson, readJsonSync, readdir, remove, rename, rm, sections, stat, statSync, unlink, writeFile, writeFileSync, writeJson, writeJsonSync };
601
+ export { ConfigSource, GeneratorContext, GeneratorFunction, IFileSystemService, IVariableReplacementService, NxProjectJson, ParsedInclude, ProjectConfig, ProjectConfigResolver, ProjectConfigResult, ProjectFinderService, ProjectType, ProjectTypeDetectionResult, ScaffoldProcessingService, ScaffoldResult, TemplatesManagerService, ToolkitConfig, accessSync, copy, cp, detectProjectType, ensureDir, ensureDirSync, fs, generateStableId, icons, isMonolith, isMonorepo, log, logger, messages, mkdir, mkdirSync, move, outputFile, pathExists, pathExistsSync, print, readFile, readFileSync, readJson, readJsonSync, readdir, remove, rename, rm, sections, stat, statSync, unlink, writeFile, writeFileSync, writeJson, writeJsonSync };
package/dist/index.mjs CHANGED
@@ -725,6 +725,36 @@ var ScaffoldProcessingService = class {
725
725
  }
726
726
  };
727
727
 
728
+ //#endregion
729
+ //#region src/utils/generateStableId.ts
730
+ /**
731
+ * Generate a stable, random ID string
732
+ *
733
+ * @param length - Length of the ID to generate (default: 8)
734
+ * @returns A random alphanumeric ID string (lowercase)
735
+ *
736
+ * @remarks
737
+ * Negative or non-integer lengths are normalized (floored and clamped to 0).
738
+ * Returns empty string for length <= 0.
739
+ *
740
+ * @example
741
+ * ```typescript
742
+ * const id = generateStableId(6); // Returns something like "a3f9k2"
743
+ * ```
744
+ */
745
+ function generateStableId(length = 8) {
746
+ const chars = "abcdefghijklmnopqrstuvwxyz0123456789";
747
+ let result = "";
748
+ const normalizedLength = Math.max(0, Math.floor(length));
749
+ if (normalizedLength === 0) return "";
750
+ if (typeof crypto !== "undefined" && crypto.getRandomValues) {
751
+ const values = new Uint8Array(normalizedLength);
752
+ crypto.getRandomValues(values);
753
+ for (let i = 0; i < normalizedLength; i++) result += chars[values[i] % 36];
754
+ } else for (let i = 0; i < normalizedLength; i++) result += chars[Math.floor(Math.random() * 36)];
755
+ return result;
756
+ }
757
+
728
758
  //#endregion
729
759
  //#region src/utils/print.ts
730
760
  /**
@@ -954,4 +984,4 @@ async function isMonolith(workspaceRoot) {
954
984
  }
955
985
 
956
986
  //#endregion
957
- export { ConfigSource, ProjectConfigResolver, ProjectFinderService, ProjectType, ScaffoldProcessingService, TemplatesManagerService, accessSync, copy, cp, detectProjectType, ensureDir, ensureDirSync, fs, icons, isMonolith, isMonorepo, log, logger, messages, mkdir, mkdirSync, move, outputFile, pathExists, pathExistsSync, print, readFile, readFileSync, readJson, readJsonSync, readdir, remove, rename, rm, sections, stat, statSync, unlink, writeFile, writeFileSync, writeJson, writeJsonSync };
987
+ export { ConfigSource, ProjectConfigResolver, ProjectFinderService, ProjectType, ScaffoldProcessingService, TemplatesManagerService, accessSync, copy, cp, detectProjectType, ensureDir, ensureDirSync, fs, generateStableId, icons, isMonolith, isMonorepo, log, logger, messages, mkdir, mkdirSync, move, outputFile, pathExists, pathExistsSync, print, readFile, readFileSync, readJson, readJsonSync, readdir, remove, rename, rm, sections, stat, statSync, unlink, writeFile, writeFileSync, writeJson, writeJsonSync };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@agiflowai/aicode-utils",
3
3
  "description": "Shared utilities and types for AI-powered code generation, scaffolding, and analysis",
4
- "version": "1.0.5",
4
+ "version": "1.0.7",
5
5
  "license": "AGPL-3.0",
6
6
  "author": "AgiflowIO",
7
7
  "repository": {
@@ -40,6 +40,7 @@
40
40
  "@types/node": "^22.0.0",
41
41
  "@types/ora": "^3.2.0",
42
42
  "@vitest/coverage-v8": "^3.0.0",
43
+ "chance": "^1.1.13",
43
44
  "tsdown": "^0.16.4",
44
45
  "typescript": "5.9.3",
45
46
  "vitest": "^3.0.0"