UNPKG

node-darts

Version:

Node.js Native Addon for Darts (Double-ARray Trie System)

102 lines 3.22 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.fileExists = fileExists; exports.validateFilePath = validateFilePath; exports.ensureDirectoryExists = ensureDirectoryExists; exports.sortStrings = sortStrings; exports.uniqueArray = uniqueArray; exports.sortAndUniqueStrings = sortAndUniqueStrings; const fs = __importStar(require("fs")); const path = __importStar(require("path")); const errors_1 = require("./errors"); /** * Checks if a file exists * @param filePath file path * @returns true if the file exists, false otherwise */ function fileExists(filePath) { try { return fs.existsSync(filePath); } catch { return false; } } /** * Validates a file path * @param filePath file path * @throws {FileNotFoundError} if the file is not found */ function validateFilePath(filePath) { if (!fileExists(filePath)) { throw new errors_1.FileNotFoundError(filePath); } } /** * Creates a directory if it doesn't exist * @param dirPath directory path */ function ensureDirectoryExists(dirPath) { const dirname = path.dirname(dirPath); if (!fs.existsSync(dirname)) { fs.mkdirSync(dirname, { recursive: true }); } } /** * Sorts an array of strings * @param arr array to sort * @returns a new sorted array */ function sortStrings(arr) { return [...arr].sort((a, b) => a.localeCompare(b)); } /** * Removes duplicates from an array * @param arr array to remove duplicates from * @returns a new array with duplicates removed */ function uniqueArray(arr) { return [...new Set(arr)]; } /** * Sorts an array of strings and removes duplicates * @param arr array to process * @returns a new sorted array with duplicates removed */ function sortAndUniqueStrings(arr) { return uniqueArray(sortStrings(arr)); } //# sourceMappingURL=utils.js.map