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.
163 lines (159 loc) • 5.69 kB
JavaScript
;
var types = require('./types.js');
var referenceTracker = require('./reference-tracker.js');
var memoryManager$1 = require('./memory-manager.js');
/***************************************************************************
* FortifyJS - Secure Array Types
*
* This file contains type definitions for the SecureArray modular architecture
*
* @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.
***************************************************************************** */
/**
* Memory Management Module for FortifyJS
*
* This module provides advanced memory management capabilities including:
* - Object reference tracking with leak detection
* - Configurable memory pools with multiple strategies
* - Event-driven memory monitoring
* - Cross-platform compatibility (Node.js & Browser)
* - Comprehensive performance metrics
*/
// Export all types
/**
* Global memory manager instance
*
* This is the main entry point for memory management in FortifyJS.
* It provides a singleton instance that can be used throughout the application.
*/
const memoryManager = memoryManager$1.AdvancedMemoryManager.getInstance();
/**
* Utility functions for memory management
*/
const MemoryUtils = {
/**
* Format bytes to human-readable string
*/
formatBytes(bytes) {
const units = ["B", "KB", "MB", "GB"];
let size = bytes;
let unitIndex = 0;
while (size >= 1024 && unitIndex < units.length - 1) {
size /= 1024;
unitIndex++;
}
return `${size.toFixed(2)} ${units[unitIndex]}`;
},
/**
* Format duration to human-readable string
*/
formatDuration(ms) {
const seconds = Math.floor(ms / 1000);
const minutes = Math.floor(seconds / 60);
const hours = Math.floor(minutes / 60);
const days = Math.floor(hours / 24);
if (days > 0)
return `${days}d ${hours % 24}h ${minutes % 60}m`;
if (hours > 0)
return `${hours}h ${minutes % 60}m ${seconds % 60}s`;
if (minutes > 0)
return `${minutes}m ${seconds % 60}s`;
return `${seconds}s`;
},
/**
* Estimate object size in bytes
*/
estimateObjectSize(obj) {
if (obj === null || obj === undefined)
return 0;
const type = typeof obj;
switch (type) {
case "boolean":
return 4;
case "number":
return 8;
case "string":
return obj.length * 2; // UTF-16
case "object":
if (obj instanceof ArrayBuffer)
return obj.byteLength;
if (obj instanceof Uint8Array)
return obj.byteLength;
if (Array.isArray(obj)) {
return obj.reduce((sum, item) => sum + MemoryUtils.estimateObjectSize(item), 0);
}
return Object.keys(obj).length * 64; // Rough estimate
default:
return 64; // Default estimate
}
},
/**
* Check if current environment supports advanced memory features
*/
supportsAdvancedFeatures() {
return (typeof WeakRef !== "undefined" &&
typeof FinalizationRegistry !== "undefined");
},
/**
* Get current memory usage (Node.js only)
*/
getCurrentMemoryUsage() {
if (typeof process !== "undefined" && process.memoryUsage) {
return process.memoryUsage();
}
return null;
},
/**
* Force garbage collection if available
*/
forceGC() {
if (typeof global !== "undefined" && global.gc) {
global.gc();
return true;
}
return false;
},
};
Object.defineProperty(exports, 'MemoryErrorType', {
enumerable: true,
get: function () { return types.MemoryErrorType; }
});
Object.defineProperty(exports, 'MemoryEventType', {
enumerable: true,
get: function () { return types.MemoryEventType; }
});
Object.defineProperty(exports, 'MemoryPressureLevel', {
enumerable: true,
get: function () { return types.MemoryPressureLevel; }
});
Object.defineProperty(exports, 'PoolStrategy', {
enumerable: true,
get: function () { return types.PoolStrategy; }
});
exports.AdvancedReferenceTracker = referenceTracker.AdvancedReferenceTracker;
exports.AdvancedMemoryManager = memoryManager$1.AdvancedMemoryManager;
exports.MemoryUtils = MemoryUtils;
exports.memoryManager = memoryManager;
//# sourceMappingURL=index.js.map