UNPKG

xypriss-security

Version:

XyPriss Security is an advanced JavaScript security library designed for enterprise applications. It provides military-grade encryption, secure data structures, quantum-resistant cryptography, and comprehensive security utilities for modern web applicatio

65 lines (61 loc) 1.77 kB
'use strict'; var nehoid = require('nehoid'); /** * ID Generator Utility * Generates unique IDs for SecureObject instances */ /** * Generates unique IDs for SecureObject instances */ class IdGenerator { /** * Generates a unique ID for a SecureObject instance */ static generate() { return nehoid.NehoID.generate({ prefix: "sobj", size: 16 }); } /** * Generates a unique ID with custom prefix */ static generateWithPrefix(prefix) { return nehoid.NehoID.generate({ prefix, size: 16 }); } /** * Generates a unique ID with custom size */ static generateWithSize(size) { return nehoid.NehoID.generate({ prefix: "sobj", size }); } /** * Generates a unique ID with custom prefix and size */ static generateCustom(prefix, size) { return nehoid.NehoID.generate({ prefix, size }); } /** * Validates if a string looks like a valid SecureObject ID */ static isValidId(id) { // Basic validation - starts with sobj_ and has reasonable length return typeof id === "string" && id.startsWith("sobj_") && id.length > 10 && id.length < 50; } /** * Extracts the prefix from an ID */ static extractPrefix(id) { const underscoreIndex = id.indexOf("_"); return underscoreIndex > 0 ? id.substring(0, underscoreIndex) : null; } /** * Extracts the unique part from an ID (without prefix) */ static extractUniquePart(id) { const underscoreIndex = id.indexOf("_"); return underscoreIndex > 0 ? id.substring(underscoreIndex + 1) : null; } } exports.IdGenerator = IdGenerator; //# sourceMappingURL=id-generator.js.map