UNPKG

fortify2-js

Version:

MOST POWERFUL JavaScript Security Library! Military-grade cryptography + 19 enhanced object methods + quantum-resistant algorithms + perfect TypeScript support. More powerful than Lodash with built-in security.

225 lines (221 loc) 7.14 kB
'use strict'; var secureArrayCore = require('./core/secure-array-core.js'); var index = require('./types/index.js'); var validation = require('./utils/validation.js'); var metadataManager = require('./metadata/metadata-manager.js'); var idGenerator = require('./utils/id-generator.js'); /*************************************************************************** * FortifyJS - Secure Array Main Export * * This file contains the main exports for the SecureArray module * * @author Nehonix * * @license MIT * * Copyright (c) 2025 Nehonix. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. ***************************************************************************** */ /** * Main export file for SecureArray */ // Import the main SecureArray class /** * Creates a SecureArray with initial data */ function createSecureArray(initialData, options) { return new secureArrayCore.SecureArray(initialData, options); } /** * Creates a SecureArray with maximum security settings */ function createMaximumSecureArray(initialData, customOptions) { const maximumOptions = { readOnly: false, autoDestroy: false, encryptionKey: undefined, maxMemory: 50 * 1024 * 1024, // 50MB gcThreshold: 0.7, enableMemoryTracking: true, autoCleanup: true, maxLength: 100000, enableIndexValidation: true, enableTypeValidation: true, ...customOptions, }; return new secureArrayCore.SecureArray(initialData, maximumOptions); } /** * Creates a read-only SecureArray */ function createReadOnlySecureArray(initialData, options) { const readOnlyOptions = { readOnly: true, enableMemoryTracking: true, enableIndexValidation: true, enableTypeValidation: true, ...options, }; return new secureArrayCore.SecureArray(initialData, readOnlyOptions); } /** * Creates a SecureArray from another array (deep copy) */ function cloneSecureArray(source) { const newArray = new secureArrayCore.SecureArray(); for (let i = 0; i < source.length; i++) { const value = source.get(i); if (value !== undefined) { newArray.push(value); } } return newArray; } /** * Creates a SecureArray from a regular array */ function fromArray(array, options) { return new secureArrayCore.SecureArray(array, options); } /** * Converts a SecureArray to a regular array */ function toArray(secureArray) { const result = []; for (let i = 0; i < secureArray.length; i++) { const value = secureArray.get(i); if (value !== undefined) { result.push(value); } } return result; } /** * Merges multiple SecureArrays into one */ function mergeSecureArrays(...arrays) { const result = new secureArrayCore.SecureArray(); for (const array of arrays) { for (let i = 0; i < array.length; i++) { const value = array.get(i); if (value !== undefined) { result.push(value); } } } return result; } /** * Creates a SecureArray with a specific size and fill value */ function createFilledSecureArray(size, fillValue, options) { const array = new secureArrayCore.SecureArray([], options); for (let i = 0; i < size; i++) { array.push(fillValue); } return array; } /** * Creates a SecureArray from a range of numbers */ function createRangeSecureArray(start, end, step = 1, options) { const array = new secureArrayCore.SecureArray([], options); for (let i = start; i < end; i += step) { array.push(i); } return array; } /** * Version information */ const SECURE_ARRAY_VERSION = "2.0.0-beta"; /** * Module information for debugging */ const MODULE_INFO = { version: SECURE_ARRAY_VERSION, architecture: "modular", components: [ "core/secure-array-core", "metadata/metadata-manager", "utils/id-generator", "utils/validation", "types/index", ], features: [ "Modular architecture", "Type-safe operations", "Event system", "Metadata tracking", "Memory management", "Validation utilities", "Secure storage", "Array operations", ], }; /** * Gets information about the SecureArray module */ function getModuleInfo() { return MODULE_INFO; } /** * Validates if a value can be used in SecureArray */ function validateSecureArrayValue(value) { try { validation.ArrayValidationUtils.validateSecureArrayValue(value); return true; } catch { return false; } } /** * Gets the default options for SecureArray */ function getDefaultOptions() { return { ...index.DEFAULT_SECURE_ARRAY_OPTIONS }; } exports.SecureArray = secureArrayCore.SecureArray; exports.default = secureArrayCore.SecureArray; exports.DEFAULT_FILTER_OPTIONS = index.DEFAULT_FILTER_OPTIONS; exports.DEFAULT_SEARCH_OPTIONS = index.DEFAULT_SEARCH_OPTIONS; exports.DEFAULT_SECURE_ARRAY_OPTIONS = index.DEFAULT_SECURE_ARRAY_OPTIONS; exports.isSecureArray = index.isSecureArray; exports.isSecureArrayValue = index.isSecureArrayValue; exports.ArrayValidationUtils = validation.ArrayValidationUtils; exports.ArrayMetadataManager = metadataManager.ArrayMetadataManager; exports.ArrayIdGenerator = idGenerator.ArrayIdGenerator; exports.MODULE_INFO = MODULE_INFO; exports.SECURE_ARRAY_VERSION = SECURE_ARRAY_VERSION; exports.cloneSecureArray = cloneSecureArray; exports.createFilledSecureArray = createFilledSecureArray; exports.createMaximumSecureArray = createMaximumSecureArray; exports.createRangeSecureArray = createRangeSecureArray; exports.createReadOnlySecureArray = createReadOnlySecureArray; exports.createSecureArray = createSecureArray; exports.fromArray = fromArray; exports.getDefaultOptions = getDefaultOptions; exports.getModuleInfo = getModuleInfo; exports.mergeSecureArrays = mergeSecureArrays; exports.toArray = toArray; exports.validateSecureArrayValue = validateSecureArrayValue; //# sourceMappingURL=index.js.map