@skyra/i18next-backend
Advanced tools
Comparing version 0.1.2 to 1.0.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Backend = void 0; | ||
const node_fs_1 = require("node:fs"); | ||
const promises_1 = require("node:fs/promises"); | ||
const node_url_1 = require("node:url"); | ||
class Backend { | ||
constructor() { | ||
Object.defineProperty(this, "type", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: 'backend' | ||
}); | ||
Object.defineProperty(this, "paths", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: void 0 | ||
}); | ||
Object.defineProperty(this, "i18nextOptions", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: void 0 | ||
}); | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
var __publicField = (obj, key, value) => { | ||
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); | ||
return value; | ||
}; | ||
// src/index.ts | ||
var src_exports = {}; | ||
__export(src_exports, { | ||
Backend: () => Backend | ||
}); | ||
module.exports = __toCommonJS(src_exports); | ||
var import_node_fs = require("fs"); | ||
var import_promises = require("fs/promises"); | ||
var import_node_url = require("url"); | ||
var _Backend = class { | ||
constructor() { | ||
__publicField(this, "type", "backend"); | ||
} | ||
init(_, backendOptions, i18nextOptions) { | ||
this.paths = backendOptions.paths ?? []; | ||
this.i18nextOptions = i18nextOptions; | ||
} | ||
read(language, namespace, callback) { | ||
if (this.paths.length === 0) | ||
return callback(new Error("No files registered"), null); | ||
if (this.i18nextOptions.initImmediate === true) { | ||
try { | ||
return callback(null, this.readPathsSync(language, namespace)); | ||
} catch (error) { | ||
return callback(error, false); | ||
} | ||
} | ||
init(_, backendOptions, i18nextOptions) { | ||
this.paths = backendOptions.paths ?? []; | ||
this.i18nextOptions = i18nextOptions; | ||
this.readPaths(language, namespace).then((data) => callback(null, data)).catch((error) => callback(error, false)); | ||
} | ||
async readPaths(language, namespace) { | ||
if (this.paths.length === 1) | ||
return _Backend.readPath(_Backend.resolvePath(language, namespace, this.paths[0])); | ||
const results = await Promise.allSettled(this.paths.map((path) => _Backend.readPath(_Backend.resolvePath(language, namespace, path)))); | ||
return _Backend.handleResults(results); | ||
} | ||
readPathsSync(language, namespace) { | ||
if (this.paths.length === 1) | ||
return _Backend.readPathSync(_Backend.resolvePath(language, namespace, this.paths[0])); | ||
const results = this.paths.map((path) => { | ||
try { | ||
return { | ||
status: "fulfilled", | ||
value: _Backend.readPathSync(_Backend.resolvePath(language, namespace, path)) | ||
}; | ||
} catch (error) { | ||
return { | ||
status: "rejected", | ||
reason: error | ||
}; | ||
} | ||
}); | ||
return _Backend.handleResults(results); | ||
} | ||
static async readPath(path) { | ||
return JSON.parse(await (0, import_promises.readFile)(path, "utf8")); | ||
} | ||
static readPathSync(path) { | ||
return JSON.parse((0, import_node_fs.readFileSync)(path, "utf8")); | ||
} | ||
static handleResults(results) { | ||
const filtered = results.filter((result) => result.status === "fulfilled"); | ||
if (filtered.length === 0) { | ||
throw new AggregateError(results.map((result) => result.reason), "Could not find the file in any of the registered paths"); | ||
} | ||
read(language, namespace, callback) { | ||
if (this.paths.length === 0) | ||
return callback(new Error('No files registered'), null); | ||
if (this.i18nextOptions.initImmediate === true) { | ||
try { | ||
return callback(null, this.readPathsSync(language, namespace)); | ||
} | ||
catch (error) { | ||
return callback(error, false); | ||
} | ||
} | ||
this.readPaths(language, namespace) | ||
.then((data) => callback(null, data)) | ||
.catch((error) => callback(error, false)); | ||
} | ||
async readPaths(language, namespace) { | ||
if (this.paths.length === 1) | ||
return Backend.readPath(Backend.resolvePath(language, namespace, this.paths[0])); | ||
const results = await Promise.allSettled(this.paths.map((path) => Backend.readPath(Backend.resolvePath(language, namespace, path)))); | ||
return Backend.handleResults(results); | ||
} | ||
readPathsSync(language, namespace) { | ||
if (this.paths.length === 1) | ||
return Backend.readPathSync(Backend.resolvePath(language, namespace, this.paths[0])); | ||
const results = this.paths.map((path) => { | ||
try { | ||
return { status: 'fulfilled', value: Backend.readPathSync(Backend.resolvePath(language, namespace, path)) }; | ||
} | ||
catch (error) { | ||
return { status: 'rejected', reason: error }; | ||
} | ||
}); | ||
return Backend.handleResults(results); | ||
} | ||
static async readPath(path) { | ||
return JSON.parse(await (0, promises_1.readFile)(path, 'utf8')); | ||
} | ||
static readPathSync(path) { | ||
return JSON.parse((0, node_fs_1.readFileSync)(path, 'utf8')); | ||
} | ||
static handleResults(results) { | ||
const filtered = results.filter((result) => result.status === 'fulfilled'); | ||
if (filtered.length === 0) { | ||
throw new AggregateError(results.map((result) => result.reason), 'Could not find the file in any of the registered paths'); | ||
} | ||
return Object.assign({}, ...filtered.map((result) => result.value)); | ||
} | ||
static resolvePath(language, namespace, path) { | ||
if (typeof path === 'function') | ||
return path(language, namespace); | ||
if (typeof path !== 'string') | ||
path = (0, node_url_1.fileURLToPath)(path); | ||
return path.replaceAll(/\{\{(?:lng|ns)\}\}/g, (match) => (match === '{{lng}}' ? language : namespace)); | ||
} | ||
} | ||
exports.Backend = Backend; | ||
Object.defineProperty(Backend, "type", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: 'backend' | ||
return Object.assign({}, ...filtered.map((result) => result.value)); | ||
} | ||
static resolvePath(language, namespace, path) { | ||
if (typeof path === "function") | ||
return path(language, namespace); | ||
if (typeof path !== "string") | ||
path = (0, import_node_url.fileURLToPath)(path); | ||
return path.replaceAll(/\{\{(?:lng|ns)\}\}/g, (match) => match === "{{lng}}" ? language : namespace); | ||
} | ||
}; | ||
var Backend = _Backend; | ||
__name(Backend, "Backend"); | ||
__publicField(Backend, "type", "backend"); | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
Backend | ||
}); | ||
//# sourceMappingURL=index.js.map |
118
package.json
{ | ||
"name": "@skyra/i18next-backend", | ||
"version": "0.1.2", | ||
"description": "A filesystem-based backend for i18next", | ||
"author": "@skyra", | ||
"license": "Apache-2.0", | ||
"main": "dist/index.js", | ||
"module": "dist/index.mjs", | ||
"types": "dist/index.d.ts", | ||
"exports": { | ||
"import": "./dist/index.mjs", | ||
"require": "./dist/index.js", | ||
"types": "./dist/index.d.ts" | ||
}, | ||
"sideEffects": false, | ||
"scripts": { | ||
"build": "tsup && tsc -b src", | ||
"watch": "tsup --watch --onSuccess \"tsc -b src\"", | ||
"watch:types": "tsc -b src -w", | ||
"lint": "eslint src --ext ts --fix -c ../../package.json", | ||
"prepublishOnly": "yarn build", | ||
"bump": "cliff-jumper", | ||
"check-update": "cliff-jumper --dry-run" | ||
}, | ||
"dependencies": { | ||
"tslib": "^2.4.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "*", | ||
"i18next": "^21.6.16" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/skyra-project/archid-components.git", | ||
"directory": "packages/i18next-backend" | ||
}, | ||
"files": [ | ||
"dist/**/*.mjs*", | ||
"dist/**/*.d.ts" | ||
], | ||
"engines": { | ||
"node": ">=16.9.0", | ||
"npm": ">=8.0.0" | ||
}, | ||
"keywords": [ | ||
"discord", | ||
"api", | ||
"http", | ||
"skyra", | ||
"typescript", | ||
"ts", | ||
"yarn" | ||
], | ||
"bugs": { | ||
"url": "https://github.com/skyra-project/archid-components/issues" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} | ||
"name": "@skyra/i18next-backend", | ||
"version": "1.0.0", | ||
"description": "A filesystem-based backend for i18next", | ||
"author": "@skyra", | ||
"license": "Apache-2.0", | ||
"main": "dist/index.js", | ||
"module": "dist/index.mjs", | ||
"types": "dist/index.d.ts", | ||
"exports": { | ||
"import": "./dist/index.mjs", | ||
"require": "./dist/index.js", | ||
"types": "./dist/index.d.ts" | ||
}, | ||
"sideEffects": false, | ||
"scripts": { | ||
"build": "tsup && tsc -b src", | ||
"watch": "tsup --watch --onSuccess \"tsc -b src\"", | ||
"watch:types": "tsc -b src -w", | ||
"lint": "eslint src --ext ts --fix -c ../../package.json", | ||
"prepack": "yarn build", | ||
"bump": "cliff-jumper", | ||
"check-update": "cliff-jumper --dry-run" | ||
}, | ||
"dependencies": { | ||
"tslib": "^2.4.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "*", | ||
"i18next": "^21.7.1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/skyra-project/archid-components.git", | ||
"directory": "packages/i18next-backend" | ||
}, | ||
"files": [ | ||
"dist/**/*.mjs*", | ||
"dist/**/*.d.ts" | ||
], | ||
"engines": { | ||
"node": ">=16.9.0", | ||
"npm": ">=8.0.0" | ||
}, | ||
"keywords": [ | ||
"discord", | ||
"api", | ||
"http", | ||
"skyra", | ||
"typescript", | ||
"ts", | ||
"yarn" | ||
], | ||
"bugs": { | ||
"url": "https://github.com/skyra-project/archid-components/issues" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 2 instances in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
215
0
15495
6
2