admin felület fejlesztése garázs, előfizeztési csomagok

This commit is contained in:
Roo
2026-06-25 01:58:04 +00:00
parent 80a5d67f79
commit 52011606ff
334 changed files with 46636 additions and 1606 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,78 @@
{
"name": "@intlify/core-base",
"version": "11.4.2",
"description": "@intlify/core-base",
"keywords": [
"core",
"fundamental",
"i18n",
"internationalization",
"intlify"
],
"license": "MIT",
"author": {
"name": "kazuya kawaguchi",
"email": "kawakazu80@gmail.com"
},
"homepage": "https://github.com/intlify/vue-i18n/tree/master/packages/core-base#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/intlify/vue-i18n.git",
"directory": "packages/core"
},
"bugs": {
"url": "https://github.com/intlify/vue-i18n/issues"
},
"files": [
"index.js",
"dist"
],
"main": "index.js",
"module": "dist/core-base.mjs",
"unpkg": "dist/core-base.global.js",
"jsdelivr": "dist/core-base.global.js",
"types": "dist/core-base.d.ts",
"dependencies": {
"@intlify/devtools-types": "11.4.2",
"@intlify/message-compiler": "11.4.2",
"@intlify/shared": "11.4.2"
},
"engines": {
"node": ">= 16"
},
"buildOptions": {
"name": "IntlifyCoreBase",
"formats": [
"mjs",
"browser",
"cjs",
"global"
]
},
"exports": {
".": {
"types": "./dist/core-base.d.ts",
"import": "./dist/core-base.mjs",
"browser": "./dist/core-base.esm-browser.js",
"node": {
"import": {
"production": "./dist/core-base.prod.cjs",
"development": "./dist/core-base.mjs",
"default": "./dist/core-base.prod.cjs"
},
"require": {
"production": "./dist/core-base.prod.cjs",
"development": "./dist/core-base.cjs",
"default": "./dist/core-base.prod.cjs"
}
}
},
"./dist/*": "./dist/*",
"./package.json": "./package.json"
},
"funding": "https://github.com/sponsors/kazupon",
"publishConfig": {
"access": "public"
},
"sideEffects": false
}

View File

@@ -0,0 +1,31 @@
/*!
* core v11.4.2
* (c) 2026 kazuya kawaguchi
* Released under the MIT License.
*/
import { registerMessageCompiler, compile, registerMessageResolver, resolveValue, registerLocaleFallbacker, fallbackWithLocaleChain } from '@intlify/core-base';
export * from '@intlify/core-base';
import { getGlobalThis } from '@intlify/shared';
/**
* This is only called in esm-bundler builds.
* istanbul-ignore-next
*/
function initFeatureFlags() {
if (typeof __INTLIFY_PROD_DEVTOOLS__ !== 'boolean') {
getGlobalThis().__INTLIFY_PROD_DEVTOOLS__ = false;
}
if (typeof __INTLIFY_DROP_MESSAGE_COMPILER__ !== 'boolean') {
getGlobalThis().__INTLIFY_DROP_MESSAGE_COMPILER__ = false;
}
}
{
initFeatureFlags();
}
// register message compiler at @intlify/core
registerMessageCompiler(compile);
// register message resolver at @intlify/core
registerMessageResolver(resolveValue);
// register fallback locale at @intlify/core
registerLocaleFallbacker(fallbackWithLocaleChain);

View File

@@ -0,0 +1,82 @@
{
"name": "@intlify/core",
"version": "11.4.2",
"description": "@intlify/core",
"keywords": [
"core",
"fundamental",
"i18n",
"internationalization",
"intlify"
],
"license": "MIT",
"author": {
"name": "kazuya kawaguchi",
"email": "kawakazu80@gmail.com"
},
"homepage": "https://github.com/intlify/vue-i18n/tree/master/packages/core#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/intlify/vue-i18n.git",
"directory": "packages/core"
},
"bugs": {
"url": "https://github.com/intlify/vue-i18n/issues"
},
"files": [
"index.js",
"dist"
],
"main": "index.js",
"module": "dist/core.mjs",
"unpkg": "dist/core.global.js",
"jsdelivr": "dist/core.global.js",
"types": "dist/core.d.ts",
"dependencies": {
"@intlify/core-base": "11.4.2",
"@intlify/shared": "11.4.2"
},
"engines": {
"node": ">= 16"
},
"buildOptions": {
"name": "IntlifyCore",
"formats": [
"mjs",
"mjs-node",
"mjs-runtime",
"mjs-node-runtime",
"browser",
"browser-runtime",
"cjs",
"global",
"global-runtime"
]
},
"exports": {
".": {
"types": "./dist/core.d.ts",
"import": "./dist/core.mjs",
"browser": "./dist/core.esm-browser.js",
"node": {
"import": {
"production": "./dist/core.prod.node.mjs",
"development": "./dist/core.node.mjs",
"default": "./dist/core.prod.node.mjs"
},
"require": {
"production": "./dist/core.prod.cjs",
"development": "./dist/core.cjs",
"default": "./dist/core.prod.cjs"
}
}
},
"./dist/*": "./dist/*",
"./package.json": "./package.json"
},
"funding": "https://github.com/sponsors/kazupon",
"publishConfig": {
"access": "public"
},
"sideEffects": true
}

View File

@@ -0,0 +1,65 @@
import { createCoreContext, parseTranslateArgs, translate, NOT_REOSLVED } from '@intlify/core';
import { getHeaderLocale } from '@intlify/utils/h3';
export * from '@intlify/utils/h3';
/**
* @author kazuya kawaguchi (a.k.a. kazupon)
* @license MIT
*/
function defineI18nMiddleware(options) {
const i18n = createCoreContext(options);
const orgLocale = i18n.locale;
let staticLocaleDetector = null;
if (typeof orgLocale === "string") {
console.warn(
`defineI18nMiddleware 'locale' option is static ${orgLocale} locale! you should specify dynamic locale detector function.`
);
staticLocaleDetector = () => orgLocale;
}
const getLocaleDetector = (event, i18n2) => {
return typeof orgLocale === "function" ? orgLocale.bind(null, event, i18n2) : staticLocaleDetector == null ? detectLocaleFromAcceptLanguageHeader.bind(null, event) : staticLocaleDetector.bind(null, event, i18n2);
};
return {
onRequest(event) {
event.context._i18nLocale = getLocaleDetector(event, i18n);
i18n.locale = event.context._i18nLocale;
event.context.i18n = i18n;
},
onAfterResponse(event) {
i18n.locale = orgLocale;
delete event.context.i18n;
}
};
}
const detectLocaleFromAcceptLanguageHeader = (event) => getHeaderLocale(event).toString();
async function useTranslation(event) {
if (event.context.i18n == null) {
throw new Error(
"middleware not initialized, please setup `onRequest` and `onAfterResponse` options of `createApp` with the middleware obtained with `defineI18nMiddleware`"
);
}
const localeDetector = event.context._i18nLocale;
let locale;
if (localeDetector.constructor.name === "AsyncFunction") {
locale = await localeDetector(event);
event.context.i18n.locale = locale;
}
function translate$1(key, ...args) {
const [_, options] = parseTranslateArgs(key, ...args);
const [arg2] = args;
const result = Reflect.apply(translate, null, [
event.context.i18n,
key,
arg2,
{
// bind to request locale
locale,
...options
}
]);
return NOT_REOSLVED === result ? key : result;
}
return translate$1;
}
export { defineI18nMiddleware, detectLocaleFromAcceptLanguageHeader, useTranslation };

View File

@@ -0,0 +1,122 @@
{
"name": "@intlify/h3",
"description": "Internationalization middleware & utilities for h3",
"version": "0.7.4",
"author": {
"name": "kazuya kawaguchi",
"email": "kawakazu80@gmail.com"
},
"license": "MIT",
"funding": "https://github.com/sponsors/kazupon",
"bugs": {
"url": "https://github.com/intlify/h3/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/intlify/h3.git"
},
"keywords": [
"i18n",
"h3",
"internationalization",
"intlify",
"utilities",
"middleware"
],
"homepage": "https://github.com/intlify/h3#readme",
"publishConfig": {
"access": "public"
},
"engines": {
"node": ">= 20"
},
"type": "module",
"sideEffects": false,
"files": [
"dist"
],
"main": "dist/index.cjs",
"module": "dist/index.mjs",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
},
"./dist/*": "./dist/*",
"./package.json": "./package.json"
},
"types": "dist/index.d.ts",
"dependencies": {
"@intlify/core": "^11.1.12",
"@intlify/utils": "^0.13.0"
},
"devDependencies": {
"@eslint/compat": "^1.4.1",
"@eslint/markdown": "^7.5.0",
"@kazupon/eslint-config": "^0.38.0",
"@kazupon/prettier-config": "^0.1.1",
"@types/node": "^24.9.2",
"@types/supertest": "^6.0.3",
"@typescript/native-preview": "7.0.0-dev.20251025.1",
"@vitest/coverage-v8": "^4.0.6",
"@vitest/eslint-plugin": "^1.4.0",
"bumpp": "^10.3.1",
"eslint": "^9.39.0",
"eslint-config-prettier": "^10.1.8",
"eslint-import-resolver-typescript": "^4.4.4",
"eslint-plugin-import": "^2.32.0",
"eslint-plugin-jsdoc": "^61.1.11",
"eslint-plugin-jsonc": "^2.21.0",
"eslint-plugin-markdown-preferences": "^0.36.2",
"eslint-plugin-module-interop": "^0.3.1",
"eslint-plugin-promise": "^7.2.1",
"eslint-plugin-regexp": "^2.10.0",
"eslint-plugin-unicorn": "^62.0.0",
"eslint-plugin-unused-imports": "^4.3.0",
"eslint-plugin-yml": "^1.19.0",
"gh-changelogen": "^0.2.8",
"h3": "^1.15.4",
"knip": "^5.66.4",
"lint-staged": "^16.2.6",
"prettier": "^3.6.2",
"supertest": "^7.1.4",
"typescript": "^5.9.3",
"typescript-eslint": "^8.46.2",
"unbuild": "^3.6.1",
"vitest": "^4.0.6"
},
"prettier": "@kazupon/prettier-config",
"lint-staged": {
"*.ts?(x)": [
"prettier --parser=typescript --write",
"eslint --fix"
],
"*.{js,mjs,cjs}": [
"prettier --write",
"eslint --fix"
],
"*.{json,jsonc,json5,md,yml,yaml}": [
"prettier --write"
]
},
"scripts": {
"build": "unbuild",
"changelog": "gh-changelogen --repo=intlify/h3",
"dev:eslint": "pnpx @eslint/config-inspector --config eslint.config.ts",
"fix": "pnpm run --color \"/^fix:/\"",
"fix:eslint": "eslint . --fix",
"fix:knip": "knip --fix --no-exit-code",
"fix:prettier": "prettier . --write --experimental-cli",
"lint": "pnpm run --color \"/^lint:/\"",
"lint:eslint": "eslint . --cache",
"lint:knip": "knip",
"lint:prettier": "prettier . --check --experimental-cli",
"lint:typecheck": "tsgo --noEmit --diagnostics",
"play:basic": "pnpx tsx ./playground/basic/index.ts",
"release": "bumpp --commit \"release: v%s\" --push --tag",
"test": "pnpm run test:unit",
"test:coverage": "pnpm test --reporter verbose --coverage",
"test:unit": "vitest run --typecheck"
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,79 @@
{
"name": "@intlify/message-compiler",
"version": "11.4.2",
"description": "@intlify/message-compiler",
"keywords": [
"compiler",
"i18n",
"internationalization",
"intlify",
"message-format"
],
"license": "MIT",
"author": {
"name": "kazuya kawaguchi",
"email": "kawakazu80@gmail.com"
},
"homepage": "https://github.com/intlify/vue-i18n/tree/master/packages/message-compiler#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/intlify/vue-i18n.git",
"directory": "packages/message-compiler"
},
"bugs": {
"url": "https://github.com/intlify/vue-i18n/issues"
},
"files": [
"index.js",
"dist"
],
"main": "index.js",
"module": "dist/message-compiler.mjs",
"unpkg": "dist/message-compiler.global.js",
"jsdelivr": "dist/message-compiler.global.js",
"types": "dist/message-compiler.d.ts",
"dependencies": {
"source-map-js": "^1.0.2",
"@intlify/shared": "11.4.2"
},
"engines": {
"node": ">= 16"
},
"buildOptions": {
"name": "IntlifyMessageCompiler",
"formats": [
"mjs",
"mjs-node",
"browser",
"cjs",
"global"
],
"enableFullBundleForEsmBrowser": true
},
"exports": {
".": {
"types": "./dist/message-compiler.d.ts",
"import": "./dist/message-compiler.mjs",
"browser": "./dist/message-compiler.esm-browser.js",
"node": {
"import": {
"production": "./dist/message-compiler.node.mjs",
"development": "./dist/message-compiler.node.mjs",
"default": "./dist/message-compiler.node.mjs"
},
"require": {
"production": "./dist/message-compiler.prod.cjs",
"development": "./dist/message-compiler.cjs",
"default": "./dist/message-compiler.prod.cjs"
}
}
},
"./dist/*": "./dist/*",
"./package.json": "./package.json"
},
"funding": "https://github.com/sponsors/kazupon",
"publishConfig": {
"access": "public"
},
"sideEffects": false
}

View File

@@ -0,0 +1,281 @@
/*!
* shared v11.4.2
* (c) 2026 kazuya kawaguchi
* Released under the MIT License.
*/
function warn(msg, err) {
if (typeof console !== 'undefined') {
console.warn(`[intlify] ` + msg);
/* istanbul ignore if */
if (err) {
console.warn(err.stack);
}
}
}
const hasWarned = {};
function warnOnce(msg) {
if (!hasWarned[msg]) {
hasWarned[msg] = true;
warn(msg);
}
}
/**
* Original Utilities
* written by kazuya kawaguchi
*/
const inBrowser = typeof window !== 'undefined';
let mark;
let measure;
if ((process.env.NODE_ENV !== 'production')) {
const perf = inBrowser && window.performance;
if (perf &&
perf.mark &&
perf.measure &&
perf.clearMarks &&
// @ts-ignore browser compat
perf.clearMeasures) {
mark = (tag) => {
perf.mark(tag);
};
measure = (name, startTag, endTag) => {
perf.measure(name, startTag, endTag);
perf.clearMarks(startTag);
perf.clearMarks(endTag);
};
}
}
const RE_ARGS = /\{([0-9a-zA-Z]+)\}/g;
/* eslint-disable */
function format(message, ...args) {
if (args.length === 1 && isObject(args[0])) {
args = args[0];
}
if (!args || !args.hasOwnProperty) {
args = {};
}
return message.replace(RE_ARGS, (match, identifier) => {
return args.hasOwnProperty(identifier) ? args[identifier] : '';
});
}
const makeSymbol = (name, shareable = false) => !shareable ? Symbol(name) : Symbol.for(name);
const generateFormatCacheKey = (locale, key, source) => friendlyJSONstringify({ l: locale, k: key, s: source });
const friendlyJSONstringify = (json) => JSON.stringify(json)
.replace(/\u2028/g, '\\u2028')
.replace(/\u2029/g, '\\u2029')
.replace(/\u0027/g, '\\u0027');
const isNumber = (val) => typeof val === 'number' && isFinite(val);
const isDate = (val) => toTypeString(val) === '[object Date]';
const isRegExp = (val) => toTypeString(val) === '[object RegExp]';
const isEmptyObject = (val) => isPlainObject(val) && Object.keys(val).length === 0;
const assign = Object.assign;
const _create = Object.create;
const create = (obj = null) => _create(obj);
let _globalThis;
const getGlobalThis = () => {
// prettier-ignore
return (_globalThis ||
(_globalThis =
typeof globalThis !== 'undefined'
? globalThis
: typeof self !== 'undefined'
? self
: typeof window !== 'undefined'
? window
: typeof global !== 'undefined'
? global
: create()));
};
function escapeHtml(rawText) {
return rawText
.replace(/&/g, '&') // escape `&` first to avoid double escaping
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&apos;')
.replace(/\//g, '&#x2F;') // escape `/` to prevent closing tags or JavaScript URLs
.replace(/=/g, '&#x3D;'); // escape `=` to prevent attribute injection
}
function escapeAttributeValue(value) {
return value
.replace(/&(?![a-zA-Z0-9#]{2,6};)/g, '&amp;') // escape unescaped `&`
.replace(/"/g, '&quot;')
.replace(/'/g, '&apos;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
}
function sanitizeTranslatedHtml(html) {
// Escape dangerous characters in attribute values
// Process attributes with double quotes
html = html.replace(/(\w+)\s*=\s*"([^"]*)"/g, (_, attrName, attrValue) => `${attrName}="${escapeAttributeValue(attrValue)}"`);
// Process attributes with single quotes
html = html.replace(/(\w+)\s*=\s*'([^']*)'/g, (_, attrName, attrValue) => `${attrName}='${escapeAttributeValue(attrValue)}'`);
// Detect and neutralize event handler attributes
const eventHandlerPattern = /\s*on\w+\s*=\s*["']?[^"'>]+["']?/gi;
if (eventHandlerPattern.test(html)) {
if ((process.env.NODE_ENV !== 'production')) {
warn('Potentially dangerous event handlers detected in translation. ' +
'Consider removing onclick, onerror, etc. from your translation messages.');
}
// Neutralize event handler attributes by escaping 'on'
html = html.replace(/(\s+)(on)(\w+\s*=)/gi, '$1&#111;n$3');
}
// Disable javascript: URLs in various contexts
const javascriptUrlPattern = [
// In href, src, action, formaction attributes
/(\s+(?:href|src|action|formaction)\s*=\s*["']?)\s*javascript:/gi,
// In style attributes within url()
/(style\s*=\s*["'][^"']*url\s*\(\s*)javascript:/gi
];
javascriptUrlPattern.forEach(pattern => {
html = html.replace(pattern, '$1javascript&#58;');
});
return html;
}
const hasOwnProperty = Object.prototype.hasOwnProperty;
function hasOwn(obj, key) {
return hasOwnProperty.call(obj, key);
}
/* eslint-enable */
/**
* Useful Utilities By Evan you
* Modified by kazuya kawaguchi
* MIT License
* https://github.com/vuejs/vue-next/blob/master/packages/shared/src/index.ts
* https://github.com/vuejs/vue-next/blob/master/packages/shared/src/codeframe.ts
*/
const isArray = Array.isArray;
const isFunction = (val) => typeof val === 'function';
const isString = (val) => typeof val === 'string';
const isBoolean = (val) => typeof val === 'boolean';
const isSymbol = (val) => typeof val === 'symbol';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const isObject = (val) => val !== null && typeof val === 'object';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const isPromise = (val) => {
return isObject(val) && isFunction(val.then) && isFunction(val.catch);
};
const objectToString = Object.prototype.toString;
const toTypeString = (value) => objectToString.call(value);
const isPlainObject = (val) => toTypeString(val) === '[object Object]';
// for converting list and named values to displayed strings.
const toDisplayString = (val) => {
return val == null
? ''
: isArray(val) || (isPlainObject(val) && val.toString === objectToString)
? JSON.stringify(val, null, 2)
: String(val);
};
function join(items, separator = '') {
return items.reduce((str, item, index) => (index === 0 ? str + item : str + separator + item), '');
}
const RANGE = 2;
function generateCodeFrame(source, start = 0, end = source.length) {
const lines = source.split(/\r?\n/);
let count = 0;
const res = [];
for (let i = 0; i < lines.length; i++) {
count += lines[i].length + 1;
if (count >= start) {
for (let j = i - RANGE; j <= i + RANGE || end > count; j++) {
if (j < 0 || j >= lines.length)
continue;
const line = j + 1;
res.push(`${line}${' '.repeat(3 - String(line).length)}| ${lines[j]}`);
const lineLength = lines[j].length;
if (j === i) {
// push underline
const pad = start - (count - lineLength) + 1;
const length = Math.max(1, end > count ? lineLength - pad : end - start);
res.push(` | ` + ' '.repeat(pad) + '^'.repeat(length));
}
else if (j > i) {
if (end > count) {
const length = Math.max(Math.min(end - count, lineLength), 1);
res.push(` | ` + '^'.repeat(length));
}
count += lineLength + 1;
}
}
break;
}
}
return res.join('\n');
}
/**
* Event emitter, forked from the below:
* - original repository url: https://github.com/developit/mitt
* - code url: https://github.com/developit/mitt/blob/master/src/index.ts
* - author: Jason Miller (https://github.com/developit)
* - license: MIT
*/
/**
* Create a event emitter
*
* @returns An event emitter
*/
function createEmitter() {
const events = new Map();
const emitter = {
events,
on(event, handler) {
const handlers = events.get(event);
const added = handlers && handlers.push(handler);
if (!added) {
events.set(event, [handler]);
}
},
off(event, handler) {
const handlers = events.get(event);
if (handlers) {
handlers.splice(handlers.indexOf(handler) >>> 0, 1);
}
},
emit(event, payload) {
(events.get(event) || [])
.slice()
.map(handler => handler(payload));
(events.get('*') || [])
.slice()
.map(handler => handler(event, payload));
}
};
return emitter;
}
const isNotObjectOrIsArray = (val) => !isObject(val) || isArray(val);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function deepCopy(src, des) {
// src and des should both be objects, and none of them can be a array
if (isNotObjectOrIsArray(src) || isNotObjectOrIsArray(des)) {
throw new Error('Invalid value');
}
const stack = [{ src, des }];
while (stack.length) {
const { src, des } = stack.pop();
// using `Object.keys` which skips prototype properties
Object.keys(src).forEach(key => {
if (key === '__proto__') {
return;
}
// if src[key] is an object/array, set des[key]
// to empty object/array to prevent setting by reference
if (isObject(src[key]) && !isObject(des[key])) {
des[key] = Array.isArray(src[key]) ? [] : create();
}
if (isNotObjectOrIsArray(des[key]) || isNotObjectOrIsArray(src[key])) {
// replace with src[key] when:
// src[key] or des[key] is not an object, or
// src[key] or des[key] is an array
des[key] = src[key];
}
else {
// src[key] and des[key] are both objects, merge them
stack.push({ src: src[key], des: des[key] });
}
});
}
}
export { assign, create, createEmitter, deepCopy, escapeHtml, format, friendlyJSONstringify, generateCodeFrame, generateFormatCacheKey, getGlobalThis, hasOwn, inBrowser, isArray, isBoolean, isDate, isEmptyObject, isFunction, isNumber, isObject, isPlainObject, isPromise, isRegExp, isString, isSymbol, join, makeSymbol, mark, measure, objectToString, sanitizeTranslatedHtml, toDisplayString, toTypeString, warn, warnOnce };

View File

@@ -0,0 +1,69 @@
{
"name": "@intlify/shared",
"version": "11.4.2",
"description": "@intlify/shared",
"keywords": [
"i18n",
"internationalization",
"intlify",
"utitlity"
],
"license": "MIT",
"author": {
"name": "kazuya kawaguchi",
"email": "kawakazu80@gmail.com"
},
"homepage": "https://github.com/intlify/vue-i18n/tree/master/packages/shared#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/intlify/vue-i18n.git",
"directory": "packages/shared"
},
"bugs": {
"url": "https://github.com/intlify/vue-i18n/issues"
},
"files": [
"index.js",
"dist"
],
"main": "index.js",
"module": "dist/shared.mjs",
"types": "dist/shared.d.ts",
"engines": {
"node": ">= 16"
},
"buildOptions": {
"name": "IntlifyShared",
"formats": [
"mjs",
"browser",
"cjs"
]
},
"exports": {
".": {
"types": "./dist/shared.d.ts",
"import": "./dist/shared.mjs",
"browser": "./dist/shared.esm-browser.js",
"node": {
"import": {
"production": "./dist/shared.prod.cjs",
"development": "./dist/shared.mjs",
"default": "./dist/shared.prod.cjs"
},
"require": {
"production": "./dist/shared.prod.cjs",
"development": "./dist/shared.cjs",
"default": "./dist/shared.prod.cjs"
}
}
},
"./dist/*": "./dist/*",
"./package.json": "./package.json"
},
"funding": "https://github.com/sponsors/kazupon",
"publishConfig": {
"access": "public"
},
"sideEffects": false
}

View File

@@ -0,0 +1,89 @@
import { g as getHeaderLanguagesWithGetter, A as ACCEPT_LANGUAGE_HEADER, p as parseDefaultHeader, m as mapToLocaleFromLanguageTag, a as getLocaleWithGetter, D as DEFAULT_LANG_TAG, b as DEFAULT_COOKIE_NAME, v as validateLocale, d as getPathLocale$1, e as pathLanguageParser, f as getQueryLocale$1 } from './shared/utils.9f8159f5.mjs';
import { setCookie, getRequestURL, getCookie, getHeaders } from 'h3';
function getHeaderLanguages(event, {
name = ACCEPT_LANGUAGE_HEADER,
parser = parseDefaultHeader
} = {}) {
const getter = () => {
const headers = getHeaders(event);
return headers[name];
};
return getHeaderLanguagesWithGetter(getter, { name, parser });
}
function getHeaderLanguage(event, {
name = ACCEPT_LANGUAGE_HEADER,
parser = parseDefaultHeader
} = {}) {
return getHeaderLanguages(event, { name, parser })[0] || "";
}
function getHeaderLocales(event, {
name = ACCEPT_LANGUAGE_HEADER,
parser = parseDefaultHeader
} = {}) {
return mapToLocaleFromLanguageTag(getHeaderLanguages, event, { name, parser });
}
function tryHeaderLocales(event, {
name = ACCEPT_LANGUAGE_HEADER,
parser = parseDefaultHeader
} = {}) {
try {
return getHeaderLocales(event, { name, parser });
} catch {
return null;
}
}
function getHeaderLocale(event, {
lang = DEFAULT_LANG_TAG,
name = ACCEPT_LANGUAGE_HEADER,
parser = parseDefaultHeader
} = {}) {
return getLocaleWithGetter(() => getHeaderLanguages(event, { name, parser })[0] || lang);
}
function tryHeaderLocale(event, {
lang = DEFAULT_LANG_TAG,
name = ACCEPT_LANGUAGE_HEADER,
parser = parseDefaultHeader
} = {}) {
try {
return getHeaderLocale(event, { lang, name, parser });
} catch {
return null;
}
}
function getCookieLocale(event, { lang = DEFAULT_LANG_TAG, name = DEFAULT_COOKIE_NAME } = {}) {
return getLocaleWithGetter(() => getCookie(event, name) || lang);
}
function tryCookieLocale(event, { lang = DEFAULT_LANG_TAG, name = DEFAULT_COOKIE_NAME } = {}) {
try {
return getCookieLocale(event, { lang, name });
} catch {
return null;
}
}
function setCookieLocale(event, locale, options = { name: DEFAULT_COOKIE_NAME }) {
validateLocale(locale);
setCookie(event, options.name, locale.toString(), options);
}
function getPathLocale(event, { lang = DEFAULT_LANG_TAG, parser = pathLanguageParser } = {}) {
return getPathLocale$1(getRequestURL(event), { lang, parser });
}
function tryPathLocale(event, { lang = DEFAULT_LANG_TAG, parser = pathLanguageParser } = {}) {
try {
return getPathLocale(event, { lang, parser });
} catch {
return null;
}
}
function getQueryLocale(event, { lang = DEFAULT_LANG_TAG, name = "locale" } = {}) {
return getQueryLocale$1(getRequestURL(event), { lang, name });
}
function tryQueryLocale(event, { lang = DEFAULT_LANG_TAG, name = "locale" } = {}) {
try {
return getQueryLocale(event, { lang, name });
} catch {
return null;
}
}
export { getCookieLocale, getHeaderLanguage, getHeaderLanguages, getHeaderLocale, getHeaderLocales, getPathLocale, getQueryLocale, setCookieLocale, tryCookieLocale, tryHeaderLocale, tryHeaderLocales, tryPathLocale, tryQueryLocale };

View File

@@ -0,0 +1,108 @@
const objectToString = Object.prototype.toString;
const toTypeString = (value) => objectToString.call(value);
function isURL(val) {
return toTypeString(val) === "[object URL]";
}
function isURLSearchParams(val) {
return toTypeString(val) === "[object URLSearchParams]";
}
function isLocale(val) {
return toTypeString(val) === "[object Intl.Locale]";
}
function toLocale(val) {
return isLocale(val) ? val : new Intl.Locale(val);
}
function validateLangTag(lang) {
try {
Intl.getCanonicalLocales(lang);
return true;
} catch {
return false;
}
}
function parseAcceptLanguage(value) {
return value.split(",").map((tag) => tag.split(";")[0]).filter(
(tag) => !(tag === "*" || tag === "")
);
}
function normalizeLanguageName(langName) {
const [lang] = langName.split(".");
return lang.replace(/_/g, "-");
}
function createPathIndexLanguageParser(index = 0) {
return (path) => {
const rawPath = typeof path === "string" ? path : path.pathname;
const normalizedPath = rawPath.split("?")[0];
const parts = normalizedPath.split("/");
if (parts[0] === "") {
parts.shift();
}
return parts.length > index ? parts[index] || "" : "";
};
}
let pathLanguageParser = /* @__PURE__ */ createPathIndexLanguageParser();
function registerPathLanguageParser(parser) {
pathLanguageParser = parser;
}
const DEFAULT_LANG_TAG = "en-US";
const DEFAULT_COOKIE_NAME = "i18n_locale";
const ACCEPT_LANGUAGE_HEADER = "accept-language";
function parseDefaultHeader(input) {
return [input];
}
function getHeaderLanguagesWithGetter(getter, {
name = ACCEPT_LANGUAGE_HEADER,
parser = parseDefaultHeader
} = {}) {
const langString = getter();
return langString ? name === ACCEPT_LANGUAGE_HEADER ? parser === parseDefaultHeader ? parseAcceptLanguage(langString) : parser(langString) : parser(langString) : [];
}
function getLocaleWithGetter(getter) {
return toLocale(getter());
}
function validateLocale(locale) {
if (!(isLocale(locale) || typeof locale === "string" && validateLangTag(locale))) {
throw new SyntaxError(`locale is invalid: ${locale.toString()}`);
}
}
function mapToLocaleFromLanguageTag(getter, ...args) {
return Reflect.apply(getter, null, args).map(
(lang) => getLocaleWithGetter(() => lang)
);
}
function getExistCookies(name, getter) {
let setCookies = getter();
if (!Array.isArray(setCookies)) {
setCookies = [setCookies];
}
setCookies = setCookies.filter(
(cookieValue) => cookieValue && !cookieValue.startsWith(name + "=")
);
return setCookies;
}
function getPathLanguage(path, { lang = DEFAULT_LANG_TAG, parser = pathLanguageParser } = {}) {
return (parser || pathLanguageParser)(path) || lang;
}
function getPathLocale(path, { lang = DEFAULT_LANG_TAG, parser = pathLanguageParser } = {}) {
return new Intl.Locale(getPathLanguage(path, { lang, parser }));
}
function getURLSearchParams(input) {
if (isURLSearchParams(input)) {
return input;
} else if (isURL(input)) {
return input.searchParams;
} else {
return new URLSearchParams(input);
}
}
function getQueryLanguage(query, { lang = DEFAULT_LANG_TAG, name = "lang" } = {}) {
const queryParams = getURLSearchParams(query);
return queryParams.get(name) || lang;
}
function getQueryLocale(query, { lang = DEFAULT_LANG_TAG, name = "locale" } = {}) {
return new Intl.Locale(getQueryLanguage(query, { lang, name }));
}
export { ACCEPT_LANGUAGE_HEADER as A, DEFAULT_LANG_TAG as D, getLocaleWithGetter as a, DEFAULT_COOKIE_NAME as b, getExistCookies as c, getPathLocale as d, pathLanguageParser as e, getQueryLocale as f, getHeaderLanguagesWithGetter as g, createPathIndexLanguageParser as h, isLocale as i, parseAcceptLanguage as j, validateLangTag as k, mapToLocaleFromLanguageTag as m, normalizeLanguageName as n, parseDefaultHeader as p, registerPathLanguageParser as r, validateLocale as v };

View File

@@ -0,0 +1,129 @@
{
"name": "@intlify/utils",
"version": "0.13.0",
"description": "Collection of i18n utilities",
"keywords": [
"i18n",
"internationalization",
"intlify",
"utilities"
],
"author": {
"name": "kazuya kawaguchi",
"email": "kawakazu80@gmail.com"
},
"license": "MIT",
"funding": "https://github.com/sponsors/kazupon",
"bugs": {
"url": "https://github.com/intlify/utils/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/intlify/utils.git"
},
"homepage": "https://github.com/intlify/utils#readme",
"publishConfig": {
"access": "public"
},
"engines": {
"node": ">= 18"
},
"type": "module",
"sideEffects": false,
"main": "dist/index.cjs",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs",
"browser": "./dist/index.mjs",
"default": "./dist/index.mjs"
},
"./h3": {
"types": "./dist/h3.d.ts",
"import": "./dist/h3.mjs",
"require": "./dist/h3.cjs",
"default": "./dist/h3.mjs"
},
"./hono": {
"types": "./dist/hono.d.ts",
"import": "./dist/hono.mjs",
"require": "./dist/hono.cjs",
"default": "./dist/hono.mjs"
},
"./node": {
"types": "./dist/node.d.ts",
"import": "./dist/node.mjs",
"require": "./dist/node.cjs",
"default": "./dist/node.mjs"
},
"./dist/*": "./dist/*",
"./package.json": "./package.json"
},
"files": [
"dist"
],
"scripts": {
"prepare": "git config --local core.hooksPath .githooks",
"changelog": "gh-changelogen --repo=intlify/utils",
"release": "bumpp --commit \"release: v%s\" --all --push --tag",
"version": "npx tsx scripts/bump-deno.ts",
"fix": "run-p lint format",
"lint": "deno lint",
"format": "deno fmt",
"build": "unbuild && bun run ./scripts/deno.ts",
"test": "npm run test:typecheck && npm run test:unit",
"test:unit": "NODE_OPTIONS=--experimental-vm-modules vitest run ./src",
"test:typecheck": "vitest --typecheck --config ./vitest.type.config.ts --run",
"test:coverage": "npm test -- --reporter verbose --coverage",
"test:e2e": "run-s test:e2e:*",
"test:e2e:browser": "cd playground/browser && node --test",
"test:e2e:node": "cd playground/node && node --test",
"test:e2e:deno": "cd playground/deno && deno task test",
"test:e2e:bun": "cd playground/bun && npm run test",
"setup": "run-s setup:*",
"setup:browser": "cd playground/browser && bun install",
"setup:node": "cd playground/node && bun install",
"setup:deno": "cd playground/deno && deno cache --reload ./main.ts",
"setup:bun": "cd playground/bun && bun install",
"play:browser": "cd playground/browser && npm run dev",
"play:node": "cd playground/node && npm run dev",
"play:deno": "cd playground/deno && deno run --allow-net main.ts",
"play:bun": "cd playground/bun && npm run dev"
},
"lint-staged": {
"*.{js,ts,jsx,tsx,json,jsonc}": [
"deno fmt"
],
"*.{js,ts,jsx,tsx}": [
"deno lint"
]
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20231016.0",
"@types/node": "^20.11.24",
"@types/semver": "^7.5.8",
"@types/supertest": "^2.0.12",
"@vitest/coverage-v8": "^1.3.0",
"bumpp": "^9.2.0",
"bun-types": "latest",
"cookie-es": "^1.0.0",
"gh-changelogen": "^0.2.8",
"h3": "^1.8.1",
"hono": "^3.8.1",
"jsonc-parser": "^3.2.1",
"lint-staged": "^15.0.0",
"miniflare": "^3.20231016.0",
"npm-run-all2": "^6.0.0",
"pkg-types": "^1.0.2",
"playwright": "^1.38.1",
"semver": "^7.6.0",
"supertest": "^6.3.3",
"typescript": "^5.4.1-rc",
"unbuild": "^2.0.0",
"vitest": "^1.3.0",
"vitest-environment-miniflare": "^2.14.1"
}
}