@aomex/utility
Advanced tools
Comparing version 0.0.4 to 0.0.5
# @aomex/utility | ||
## 0.0.5 | ||
### Patch Changes | ||
- [`fbb7ab2`](https://github.com/aomex/aomex/commit/fbb7ab2e6ec2a18e7ad8f018788523952049b6fd) Thanks [@geekact](https://github.com/geekact)! - refactor(utility): move file-parser to utility | ||
## 0.0.4 | ||
@@ -4,0 +10,0 @@ |
@@ -14,2 +14,12 @@ export { default as chalk } from 'chalk'; | ||
export { NonReadonly, Union2Intersection, sleep, toArray }; | ||
interface Options { | ||
pattern: string[]; | ||
ignore?: string[]; | ||
dot?: boolean; | ||
} | ||
type PathToFileOptions = string | string[] | Options | Options[]; | ||
declare const pathToFiles: (paths: PathToFileOptions) => Promise<string[]>; | ||
declare const fileToModules: <T extends unknown>(files: string[], filter?: ((item?: T | undefined) => boolean) | undefined) => Promise<T[]>; | ||
export { NonReadonly, PathToFileOptions, Union2Intersection, fileToModules, pathToFiles, sleep, toArray }; |
@@ -11,2 +11,64 @@ // src/to-array.ts | ||
// src/file-parser/path-to-files.ts | ||
import path from "node:path"; | ||
import { stat } from "node:fs/promises"; | ||
import { glob, hasMagic } from "glob"; | ||
var pathToFiles = async (paths) => { | ||
const opts = normalizeSearchPath(paths); | ||
const files = await Promise.all( | ||
opts.map((opt) => { | ||
const { dot, pattern: patterns } = opt; | ||
const options = { | ||
nodir: true, | ||
dot, | ||
ignore: (opt.ignore || []).concat("**/*.d.{ts,mts,cts}"), | ||
withFileTypes: false | ||
}; | ||
return Promise.all( | ||
patterns.map(async (pattern) => { | ||
pattern = path.posix.resolve(pattern); | ||
if (!hasMagic(pattern, { magicalBraces: true })) { | ||
const stats = await stat(pattern); | ||
if (!stats.isFile()) { | ||
pattern = path.posix.resolve( | ||
pattern, | ||
`./**/*.{ts,js,mts,mjs,cts,cjs}` | ||
); | ||
} | ||
} | ||
return glob(pattern, options); | ||
}) | ||
); | ||
}) | ||
); | ||
return [...new Set(files.flat(2))].sort(); | ||
}; | ||
var normalizeSearchPath = (paths) => { | ||
if (typeof paths === "string") { | ||
return [{ pattern: [paths] }]; | ||
} | ||
if (Array.isArray(paths)) { | ||
if (!paths.length) | ||
return []; | ||
return isStringArray(paths) ? [{ pattern: paths }] : paths; | ||
} | ||
return [paths]; | ||
}; | ||
var isStringArray = (data) => { | ||
return typeof data[0] === "string"; | ||
}; | ||
// src/file-parser/file-to-modules.ts | ||
import { pathToFileURL } from "node:url"; | ||
var fileToModules = async (files, filter) => { | ||
const result = await Promise.all( | ||
files.map(async (file) => { | ||
const modules2 = await import(pathToFileURL(file).toString()); | ||
return typeof modules2 === "object" ? Object.values(modules2) : []; | ||
}) | ||
); | ||
const modules = [...new Set(result.flat())]; | ||
return filter ? modules.filter(filter) : modules; | ||
}; | ||
// src/index.ts | ||
@@ -18,2 +80,4 @@ import { default as default2 } from "chalk"; | ||
default2 as chalk, | ||
fileToModules, | ||
pathToFiles, | ||
sleep, | ||
@@ -20,0 +84,0 @@ toArray |
{ | ||
"name": "@aomex/utility", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "", | ||
@@ -31,5 +31,6 @@ "type": "module", | ||
"bytes": "^3.1.2", | ||
"chalk": "^5.2.0" | ||
"chalk": "^5.2.0", | ||
"glob": "^9.2.1" | ||
}, | ||
"scripts": {} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10841
97
4
+ Addedglob@^9.2.1
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@2.0.1(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedglob@9.3.5(transitive)
+ Addedlru-cache@10.4.3(transitive)
+ Addedminimatch@8.0.4(transitive)
+ Addedminipass@4.2.87.1.2(transitive)
+ Addedpath-scurry@1.11.1(transitive)