mirror of
https://github.com/transloadit/uppy.git
synced 2026-07-28 12:37:00 +00:00
40 lines
940 B
JavaScript
40 lines
940 B
JavaScript
import path from 'node:path'
|
|
import { pathToFileURL } from 'node:url'
|
|
|
|
import glob from 'glob'
|
|
|
|
export function getPaths(globPath) {
|
|
return new Promise((resolve, reject) => {
|
|
glob(globPath, (error, paths) => {
|
|
if (error) reject(error)
|
|
else resolve(paths)
|
|
})
|
|
})
|
|
}
|
|
|
|
export function sortObjectAlphabetically(obj) {
|
|
return Object.fromEntries(
|
|
Object.entries(obj).sort(([keyA], [keyB]) => keyA.localeCompare(keyB)),
|
|
)
|
|
}
|
|
|
|
export function omit(object, key) {
|
|
const copy = { ...object }
|
|
delete copy[key]
|
|
return copy
|
|
}
|
|
|
|
export async function getLocales(pathPattern) {
|
|
const paths = await getPaths(pathPattern)
|
|
|
|
return Object.fromEntries(
|
|
await Promise.all(
|
|
paths.map(async (filePath) => {
|
|
const pluginName = path.basename(path.join(filePath, '..', '..'))
|
|
const { default: locale } = await import(pathToFileURL(filePath))
|
|
|
|
return [pluginName, locale]
|
|
}),
|
|
),
|
|
)
|
|
}
|