1
0
Fork 0

worked on GarageApp stuff

This commit is contained in:
Techognito 2025-08-25 17:46:11 +02:00
parent 60aaf17af3
commit eb606572b0
51919 changed files with 2168177 additions and 18 deletions

View file

@ -0,0 +1,24 @@
# Number of days of inactivity before an issue becomes stale
daysUntilStale: 7
# Number of days of inactivity before a stale issue is closed
daysUntilClose: 7
# Issues with these labels will never be considered stale
exemptLabels:
- "discussion"
- "feature request"
- "bug"
- "breaking change"
- "doc"
- "issue"
- "help wanted"
- "good first issue"
# Label to use when marking an issue as stale
staleLabel: stale
# Comment to post when marking an issue as stale. Set to `false` to disable
markComment: >
This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs. Thank you
for your contributions.
# Comment to post when closing a stale issue. Set to `false` to disable
closeComment: false

View file

@ -0,0 +1,8 @@
{
"bracketSpacing": true,
"jsxBracketSameLine": false,
"printWidth": 100,
"semi": true,
"singleQuote": true,
"trailingComma": "all"
}

View file

@ -0,0 +1,206 @@
### 8.2.0
- feat: add support for hash detector [304](https://github.com/i18next/i18next-browser-languageDetector/issues/304)
### 8.1.0
- feat: add support for Partitioned cookies [303](https://github.com/i18next/i18next-browser-languageDetector/pull/303)
### 8.0.5
- check for common xss attack patterns on detected language
### 8.0.4
- fix localstorage check to try to address [297](https://github.com/i18next/i18next-browser-languageDetector/issues/297) [300](https://github.com/i18next/i18next-browser-languageDetector/pull/300)
### 8.0.3
- change localstorage check to try to address [297](https://github.com/i18next/i18next-browser-languageDetector/issues/297)
### 8.0.2
- fix for when passed services are null, should address [296](https://github.com/i18next/i18next-browser-languageDetector/issues/296)
### 8.0.1
- some environments, throws when accessing document.cookie
### 8.0.0
- chore: set browsers target to defaults [286](https://github.com/i18next/i18next-browser-languageDetector/pull/286)
- perf: use object deconstruction, optional chaining and hot path optimisations [287](https://github.com/i18next/i18next-browser-languageDetector/pull/287)
### 7.2.1
- fix: align addDetector impementation to type definition [282](https://github.com/i18next/i18next-browser-languageDetector/issues/282)
### 7.2.0
- fix: separate cjs and mjs typings
### 7.1.0
- introduce convertDetectedLanguage option
### 7.0.2
- simplify usage without i18next
### 7.0.1
- try to force esm moduel type for esm build [269](https://github.com/i18next/i18next-browser-languageDetector/issues/269)
### 7.0.0
- typescript fix for i18next v22
### 6.1.8
- fix export order for typescript [267](https://github.com/i18next/i18next-browser-languageDetector/issues/267)
### 6.1.7
- Types entries missing in package exports (Needed for Typescript >= 4.7 and moduleResolution="Node16"/"Nodenext") [266](https://github.com/i18next/i18next-browser-languageDetector/issues/266)
### 6.1.6
- define module exports in package.json
### 6.1.5
- lookup subdomain with localhost option [264](https://github.com/i18next/i18next-browser-languageDetector/pull/264)
### 6.1.4
- fix querystring lookup if happening after # [256](https://github.com/i18next/i18next-browser-languageDetector/issues/256)
### 6.1.3
- export DecetorOptions and CustomDetector types
### 6.1.2
- fix lookup return types [245](https://github.com/i18next/i18next-browser-languageDetector/issues/245)
### 6.1.1
- cookieOptions types [239](https://github.com/i18next/i18next-browser-languageDetector/pull/239)
### 6.1.0
- Type PluginOptions properly [235](https://github.com/i18next/i18next-browser-languageDetector/pull/235)
### 6.0.1
- optimize check for local storage and session storage [222](https://github.com/i18next/i18next-browser-languageDetector/pull/222)
### 6.0.0
- **BREAKING** rename lookupSessionStorage and add it to defaults [221](https://github.com/i18next/i18next-browser-languageDetector/pull/221)
### 5.0.1
- optimize cookie serialization and set sameSite to strict by default, to prepare for browser changes
### 5.0.0
- **BREAKING** needs i18next >= 19.5.0
- let i18next figure out which detected lng is best match
### 4.3.1
- typescript Updated typescript typings for DetectorOptions to align with current options [216](https://github.com/i18next/i18next-browser-languageDetector/pull/216)
### 4.3.0
- sessionStorage support [215](https://github.com/i18next/i18next-browser-languageDetector/pull/215)
### 4.2.0
- Add config option checkForSimilarInWhitelist [211](https://github.com/i18next/i18next-browser-languageDetector/pull/211)
### 4.1.1
- fix: pass cookieOptions with the cacheUserLang [205](https://github.com/i18next/i18next-browser-languageDetector/pull/205)
### 4.1.0
- feat: add cookieOptions for setting cookies [203](https://github.com/i18next/i18next-browser-languageDetector/pull/203)
### 4.0.2
- update index file to reflect build changes done in 4.0.0
### 4.0.1
- typescript: Use updated ts export default from i18next [194](https://github.com/i18next/i18next-browser-languageDetector/pull/194)
### 4.0.0
- removes deprecated jsnext:main from package.json
- Bundle all entry points with rollup bringing it up to same standard as [xhr-backend](https://github.com/i18next/i18next-xhr-backend/pull/314)
- **note:** dist/es -> dist/esm, dist/commonjs -> dist/cjs (individual files -> one bundled file)
- removes bower finally
### v3.1.1
- add default checkWhitelist: true
### v3.1.0
- Added option to prevent checking whitelist for detected languages `checkWhitelist: true` [190](https://github.com/i18next/i18next-browser-languageDetector/pull/190)
### v3.0.3
- Remove clutter from npm package [181](https://github.com/i18next/i18next-browser-languageDetector/pull/181)
### v3.0.2
- typescript: Fix types for `use()` module [180](https://github.com/i18next/i18next-browser-languageDetector/pull/180)
### v3.0.1
- typescript: fix types [165](https://github.com/i18next/i18next-browser-languageDetector/pull/165)
### v3.0.0
- typescript: add types [164](https://github.com/i18next/i18next-browser-languageDetector/pull/164)
### v2.2.4
- fix [157](https://github.com/i18next/i18next-browser-languageDetector/issues/157)
### v2.2.3
- fix [159](https://github.com/i18next/i18next-browser-languageDetector/pull/159)
### v2.2.2
- Lang by path: skip if language not found [159](https://github.com/i18next/i18next-browser-languageDetector/pull/159)
### v2.2.1
- fixes option validation in path lookup [158](https://github.com/i18next/i18next-browser-languageDetector/issues/158)
- fixes lookup from href for subdomain [157](https://github.com/i18next/i18next-browser-languageDetector/issues/157)
### v2.2.0
- add detector for path and subdomain [PR153](https://github.com/i18next/i18next-browser-languageDetector/pull/153) and [PR152](https://github.com/i18next/i18next-browser-languageDetector/pull/152)
### v2.1.1
- support for fallback language in form of object [151](https://github.com/i18next/i18next-browser-languageDetector/issues/151)
### v2.1.0
- add .js for browser import implementation [PR147](https://github.com/i18next/i18next-browser-languageDetector/pull/147)
### v2.0.0
- [BREAKING] options.excludeCacheFor (array of language codes; default ['cimode']): if a language maps a value in that list the language will not be written to cache (eg. localStorage, cookie). If you use lng cimode in your tests and require it to be cached set the option to false or empty array

22
node_modules/i18next-browser-languagedetector/LICENSE generated vendored Normal file
View file

@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2025 i18next
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

167
node_modules/i18next-browser-languagedetector/README.md generated vendored Normal file
View file

@ -0,0 +1,167 @@
# Introduction
[![npm version](https://img.shields.io/npm/v/i18next-browser-languagedetector.svg?style=flat-square)](https://www.npmjs.com/package/i18next-browser-languagedetector)
This is an i18next language detection plugin used to detect user language in the browser, with support for:
- cookie (set cookie i18next=LANGUAGE)
- sessionStorage (set key i18nextLng=LANGUAGE)
- localStorage (set key i18nextLng=LANGUAGE)
- navigator (set browser language)
- querystring (append `?lng=LANGUAGE` to URL)
- htmlTag (add html language tag <html lang="LANGUAGE" ...)
- path (http://my.site.com/LANGUAGE/...)
- subdomain (http://LANGUAGE.site.com/...)
# Getting started
Source can be loaded via [npm](https://www.npmjs.com/package/i18next-browser-languagedetector), bower or [downloaded](https://github.com/i18next/i18next-browser-languagedetector/blob/master/i18nextBrowserLanguageDetector.min.js) from this repo.
```
# npm package
$ npm install i18next-browser-languagedetector
# bower
$ bower install i18next-browser-languagedetector
```
- If you don't use a module loader it will be added to `window.i18nextBrowserLanguageDetector`
Wiring up:
```js
import i18next from 'i18next';
import LanguageDetector from 'i18next-browser-languagedetector';
i18next.use(LanguageDetector).init({
supportedLngs: ['de', 'en', 'fr'],
...i18nextOptions
});
```
As with all modules you can either pass the constructor function (class) to the `i18next.use` or to a concrete instance.
[`supportedLngs`](https://www.i18next.com/overview/configuration-options#languages-namespaces-resources) is optional, but allows i18next to pick the best match from the list of detected languages. If it's not set then [`language`](https://www.i18next.com/overview/api#language) will be set to the first detected language, regardless of whether your application has translations for that language or not.
## Detector Options
*The default options can be found [here](https://github.com/i18next/i18next-browser-languageDetector/blob/9efebe6ca0271c3797bc09b84babf1ba2d9b4dbb/src/index.js#L11).*
```js
{
// order and from where user language should be detected
order: ['querystring', 'hash', 'cookie', 'localStorage', 'sessionStorage', 'navigator', 'htmlTag', 'path', 'subdomain'],
// keys or params to lookup language from
lookupQuerystring: 'lng',
lookupCookie: 'i18next',
lookupLocalStorage: 'i18nextLng',
lookupSessionStorage: 'i18nextLng',
lookupFromPathIndex: 0,
lookupFromSubdomainIndex: 0,
lookupHash: 'lng', // #lng=pt or #something&lng=en
lookupFromHashIndex: 0, // #/de
// cache user language on
caches: ['localStorage', 'cookie'],
excludeCacheFor: ['cimode'], // languages to not persist (cookie, localStorage)
// optional expiry and domain for set cookie
cookieMinutes: 10,
cookieDomain: 'myDomain',
// optional htmlTag with lang attribute, the default is:
htmlTag: document.documentElement,
// optional set cookie options, reference:[MDN Set-Cookie docs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie)
cookieOptions: { path: '/', sameSite: 'strict' },
// optional conversion function used to modify the detected language code
convertDetectedLanguage: 'Iso15897',
convertDetectedLanguage: (lng) => lng.replace('-', '_')
}
```
Options can be passed in:
**preferred** - by setting options.detection in i18next.init:
```js
import i18next from 'i18next';
import LanguageDetector from 'i18next-browser-languagedetector';
i18next.use(LanguageDetector).init({
detection: options,
});
```
on construction:
```js
import LanguageDetector from 'i18next-browser-languagedetector';
const languageDetector = new LanguageDetector(null, options);
```
via calling init:
```js
import LanguageDetector from 'i18next-browser-languagedetector';
const languageDetector = new LanguageDetector();
languageDetector.init(options);
```
## Adding own detection functionality
### interface
```js
export default {
name: 'myDetectorsName',
lookup(options) {
// options -> are passed in options
return 'en';
},
cacheUserLanguage(lng, options) {
// options -> are passed in options
// lng -> current language, will be called after init and on changeLanguage
// store it
},
};
```
### adding it
```js
import LanguageDetector from 'i18next-browser-languagedetector';
const languageDetector = new LanguageDetector();
languageDetector.addDetector(myDetector);
i18next.use(languageDetector).init({
detection: options,
});
```
Don't forget: You have to add the name of your detector (`myDetectorsName` in this case) to the `order` array in your `options` object. Without that, your detector won't be used. See the [Detector Options section for more](#detector-options).
---
<h3 align="center">Gold Sponsors</h3>
<p align="center">
<a href="https://locize.com/" target="_blank">
<img src="https://raw.githubusercontent.com/i18next/i18next/master/assets/locize_sponsor_240.gif" width="240px">
</a>
</p>
---
**localization as a service - locize.com**
Needing a translation management? Want to edit your translations with an InContext Editor? Use the orginal provided to you by the maintainers of i18next!
![locize](https://locize.com/img/ads/github_locize.png)
With using [locize](http://locize.com/?utm_source=react_i18next_readme&utm_medium=github) you directly support the future of i18next and react-i18next.
---

View file

@ -0,0 +1,444 @@
'use strict';
const {
slice,
forEach
} = [];
function defaults(obj) {
forEach.call(slice.call(arguments, 1), source => {
if (source) {
for (const prop in source) {
if (obj[prop] === undefined) obj[prop] = source[prop];
}
}
});
return obj;
}
function hasXSS(input) {
if (typeof input !== 'string') return false;
// Common XSS attack patterns
const xssPatterns = [/<\s*script.*?>/i, /<\s*\/\s*script\s*>/i, /<\s*img.*?on\w+\s*=/i, /<\s*\w+\s*on\w+\s*=.*?>/i, /javascript\s*:/i, /vbscript\s*:/i, /expression\s*\(/i, /eval\s*\(/i, /alert\s*\(/i, /document\.cookie/i, /document\.write\s*\(/i, /window\.location/i, /innerHTML/i];
return xssPatterns.some(pattern => pattern.test(input));
}
// eslint-disable-next-line no-control-regex
const fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
const serializeCookie = function (name, val) {
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
path: '/'
};
const opt = options;
const value = encodeURIComponent(val);
let str = `${name}=${value}`;
if (opt.maxAge > 0) {
const maxAge = opt.maxAge - 0;
if (Number.isNaN(maxAge)) throw new Error('maxAge should be a Number');
str += `; Max-Age=${Math.floor(maxAge)}`;
}
if (opt.domain) {
if (!fieldContentRegExp.test(opt.domain)) {
throw new TypeError('option domain is invalid');
}
str += `; Domain=${opt.domain}`;
}
if (opt.path) {
if (!fieldContentRegExp.test(opt.path)) {
throw new TypeError('option path is invalid');
}
str += `; Path=${opt.path}`;
}
if (opt.expires) {
if (typeof opt.expires.toUTCString !== 'function') {
throw new TypeError('option expires is invalid');
}
str += `; Expires=${opt.expires.toUTCString()}`;
}
if (opt.httpOnly) str += '; HttpOnly';
if (opt.secure) str += '; Secure';
if (opt.sameSite) {
const sameSite = typeof opt.sameSite === 'string' ? opt.sameSite.toLowerCase() : opt.sameSite;
switch (sameSite) {
case true:
str += '; SameSite=Strict';
break;
case 'lax':
str += '; SameSite=Lax';
break;
case 'strict':
str += '; SameSite=Strict';
break;
case 'none':
str += '; SameSite=None';
break;
default:
throw new TypeError('option sameSite is invalid');
}
}
if (opt.partitioned) str += '; Partitioned';
return str;
};
const cookie = {
create(name, value, minutes, domain) {
let cookieOptions = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
path: '/',
sameSite: 'strict'
};
if (minutes) {
cookieOptions.expires = new Date();
cookieOptions.expires.setTime(cookieOptions.expires.getTime() + minutes * 60 * 1000);
}
if (domain) cookieOptions.domain = domain;
document.cookie = serializeCookie(name, value, cookieOptions);
},
read(name) {
const nameEQ = `${name}=`;
const ca = document.cookie.split(';');
for (let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) === ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
}
return null;
},
remove(name, domain) {
this.create(name, '', -1, domain);
}
};
var cookie$1 = {
name: 'cookie',
// Deconstruct the options object and extract the lookupCookie property
lookup(_ref) {
let {
lookupCookie
} = _ref;
if (lookupCookie && typeof document !== 'undefined') {
return cookie.read(lookupCookie) || undefined;
}
return undefined;
},
// Deconstruct the options object and extract the lookupCookie, cookieMinutes, cookieDomain, and cookieOptions properties
cacheUserLanguage(lng, _ref2) {
let {
lookupCookie,
cookieMinutes,
cookieDomain,
cookieOptions
} = _ref2;
if (lookupCookie && typeof document !== 'undefined') {
cookie.create(lookupCookie, lng, cookieMinutes, cookieDomain, cookieOptions);
}
}
};
var querystring = {
name: 'querystring',
// Deconstruct the options object and extract the lookupQuerystring property
lookup(_ref) {
let {
lookupQuerystring
} = _ref;
let found;
if (typeof window !== 'undefined') {
let {
search
} = window.location;
if (!window.location.search && window.location.hash?.indexOf('?') > -1) {
search = window.location.hash.substring(window.location.hash.indexOf('?'));
}
const query = search.substring(1);
const params = query.split('&');
for (let i = 0; i < params.length; i++) {
const pos = params[i].indexOf('=');
if (pos > 0) {
const key = params[i].substring(0, pos);
if (key === lookupQuerystring) {
found = params[i].substring(pos + 1);
}
}
}
}
return found;
}
};
var hash = {
name: 'hash',
// Deconstruct the options object and extract the lookupHash property and the lookupFromHashIndex property
lookup(_ref) {
let {
lookupHash,
lookupFromHashIndex
} = _ref;
let found;
if (typeof window !== 'undefined') {
const {
hash
} = window.location;
if (hash && hash.length > 2) {
const query = hash.substring(1);
if (lookupHash) {
const params = query.split('&');
for (let i = 0; i < params.length; i++) {
const pos = params[i].indexOf('=');
if (pos > 0) {
const key = params[i].substring(0, pos);
if (key === lookupHash) {
found = params[i].substring(pos + 1);
}
}
}
}
if (found) return found;
if (!found && lookupFromHashIndex > -1) {
const language = hash.match(/\/([a-zA-Z-]*)/g);
if (!Array.isArray(language)) return undefined;
const index = typeof lookupFromHashIndex === 'number' ? lookupFromHashIndex : 0;
return language[index]?.replace('/', '');
}
}
}
return found;
}
};
let hasLocalStorageSupport = null;
const localStorageAvailable = () => {
if (hasLocalStorageSupport !== null) return hasLocalStorageSupport;
try {
hasLocalStorageSupport = typeof window !== 'undefined' && window.localStorage !== null;
if (!hasLocalStorageSupport) {
return false;
}
const testKey = 'i18next.translate.boo';
window.localStorage.setItem(testKey, 'foo');
window.localStorage.removeItem(testKey);
} catch (e) {
hasLocalStorageSupport = false;
}
return hasLocalStorageSupport;
};
var localStorage = {
name: 'localStorage',
// Deconstruct the options object and extract the lookupLocalStorage property
lookup(_ref) {
let {
lookupLocalStorage
} = _ref;
if (lookupLocalStorage && localStorageAvailable()) {
return window.localStorage.getItem(lookupLocalStorage) || undefined; // Undefined ensures type consistency with the previous version of this function
}
return undefined;
},
// Deconstruct the options object and extract the lookupLocalStorage property
cacheUserLanguage(lng, _ref2) {
let {
lookupLocalStorage
} = _ref2;
if (lookupLocalStorage && localStorageAvailable()) {
window.localStorage.setItem(lookupLocalStorage, lng);
}
}
};
let hasSessionStorageSupport = null;
const sessionStorageAvailable = () => {
if (hasSessionStorageSupport !== null) return hasSessionStorageSupport;
try {
hasSessionStorageSupport = typeof window !== 'undefined' && window.sessionStorage !== null;
if (!hasSessionStorageSupport) {
return false;
}
const testKey = 'i18next.translate.boo';
window.sessionStorage.setItem(testKey, 'foo');
window.sessionStorage.removeItem(testKey);
} catch (e) {
hasSessionStorageSupport = false;
}
return hasSessionStorageSupport;
};
var sessionStorage = {
name: 'sessionStorage',
lookup(_ref) {
let {
lookupSessionStorage
} = _ref;
if (lookupSessionStorage && sessionStorageAvailable()) {
return window.sessionStorage.getItem(lookupSessionStorage) || undefined;
}
return undefined;
},
cacheUserLanguage(lng, _ref2) {
let {
lookupSessionStorage
} = _ref2;
if (lookupSessionStorage && sessionStorageAvailable()) {
window.sessionStorage.setItem(lookupSessionStorage, lng);
}
}
};
var navigator$1 = {
name: 'navigator',
lookup(options) {
const found = [];
if (typeof navigator !== 'undefined') {
const {
languages,
userLanguage,
language
} = navigator;
if (languages) {
// chrome only; not an array, so can't use .push.apply instead of iterating
for (let i = 0; i < languages.length; i++) {
found.push(languages[i]);
}
}
if (userLanguage) {
found.push(userLanguage);
}
if (language) {
found.push(language);
}
}
return found.length > 0 ? found : undefined;
}
};
var htmlTag = {
name: 'htmlTag',
// Deconstruct the options object and extract the htmlTag property
lookup(_ref) {
let {
htmlTag
} = _ref;
let found;
const internalHtmlTag = htmlTag || (typeof document !== 'undefined' ? document.documentElement : null);
if (internalHtmlTag && typeof internalHtmlTag.getAttribute === 'function') {
found = internalHtmlTag.getAttribute('lang');
}
return found;
}
};
var path = {
name: 'path',
// Deconstruct the options object and extract the lookupFromPathIndex property
lookup(_ref) {
let {
lookupFromPathIndex
} = _ref;
if (typeof window === 'undefined') return undefined;
const language = window.location.pathname.match(/\/([a-zA-Z-]*)/g);
if (!Array.isArray(language)) return undefined;
const index = typeof lookupFromPathIndex === 'number' ? lookupFromPathIndex : 0;
return language[index]?.replace('/', '');
}
};
var subdomain = {
name: 'subdomain',
lookup(_ref) {
let {
lookupFromSubdomainIndex
} = _ref;
// If given get the subdomain index else 1
const internalLookupFromSubdomainIndex = typeof lookupFromSubdomainIndex === 'number' ? lookupFromSubdomainIndex + 1 : 1;
// get all matches if window.location. is existing
// first item of match is the match itself and the second is the first group match which should be the first subdomain match
// is the hostname no public domain get the or option of localhost
const language = typeof window !== 'undefined' && window.location?.hostname?.match(/^(\w{2,5})\.(([a-z0-9-]{1,63}\.[a-z]{2,6})|localhost)/i);
// if there is no match (null) return undefined
if (!language) return undefined;
// return the given group match
return language[internalLookupFromSubdomainIndex];
}
};
// some environments, throws when accessing document.cookie
let canCookies = false;
try {
// eslint-disable-next-line no-unused-expressions
document.cookie;
canCookies = true;
// eslint-disable-next-line no-empty
} catch (e) {}
const order = ['querystring', 'cookie', 'localStorage', 'sessionStorage', 'navigator', 'htmlTag'];
if (!canCookies) order.splice(1, 1);
const getDefaults = () => ({
order,
lookupQuerystring: 'lng',
lookupCookie: 'i18next',
lookupLocalStorage: 'i18nextLng',
lookupSessionStorage: 'i18nextLng',
// cache user language
caches: ['localStorage'],
excludeCacheFor: ['cimode'],
// cookieMinutes: 10,
// cookieDomain: 'myDomain'
convertDetectedLanguage: l => l
});
class Browser {
constructor(services) {
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
this.type = 'languageDetector';
this.detectors = {};
this.init(services, options);
}
init() {
let services = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
languageUtils: {}
};
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
let i18nOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
this.services = services;
this.options = defaults(options, this.options || {}, getDefaults());
if (typeof this.options.convertDetectedLanguage === 'string' && this.options.convertDetectedLanguage.indexOf('15897') > -1) {
this.options.convertDetectedLanguage = l => l.replace('-', '_');
}
// backwards compatibility
if (this.options.lookupFromUrlIndex) this.options.lookupFromPathIndex = this.options.lookupFromUrlIndex;
this.i18nOptions = i18nOptions;
this.addDetector(cookie$1);
this.addDetector(querystring);
this.addDetector(localStorage);
this.addDetector(sessionStorage);
this.addDetector(navigator$1);
this.addDetector(htmlTag);
this.addDetector(path);
this.addDetector(subdomain);
this.addDetector(hash);
}
addDetector(detector) {
this.detectors[detector.name] = detector;
return this;
}
detect() {
let detectionOrder = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.options.order;
let detected = [];
detectionOrder.forEach(detectorName => {
if (this.detectors[detectorName]) {
let lookup = this.detectors[detectorName].lookup(this.options);
if (lookup && typeof lookup === 'string') lookup = [lookup];
if (lookup) detected = detected.concat(lookup);
}
});
detected = detected.filter(d => d !== undefined && d !== null && !hasXSS(d)).map(d => this.options.convertDetectedLanguage(d));
if (this.services && this.services.languageUtils && this.services.languageUtils.getBestMatchFromCodes) return detected; // new i18next v19.5.0
return detected.length > 0 ? detected[0] : null; // a little backward compatibility
}
cacheUserLanguage(lng) {
let caches = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.options.caches;
if (!caches) return;
if (this.options.excludeCacheFor && this.options.excludeCacheFor.indexOf(lng) > -1) return;
caches.forEach(cacheName => {
if (this.detectors[cacheName]) this.detectors[cacheName].cacheUserLanguage(lng, this.options);
});
}
}
Browser.type = 'languageDetector';
module.exports = Browser;

View file

@ -0,0 +1,442 @@
const {
slice,
forEach
} = [];
function defaults(obj) {
forEach.call(slice.call(arguments, 1), source => {
if (source) {
for (const prop in source) {
if (obj[prop] === undefined) obj[prop] = source[prop];
}
}
});
return obj;
}
function hasXSS(input) {
if (typeof input !== 'string') return false;
// Common XSS attack patterns
const xssPatterns = [/<\s*script.*?>/i, /<\s*\/\s*script\s*>/i, /<\s*img.*?on\w+\s*=/i, /<\s*\w+\s*on\w+\s*=.*?>/i, /javascript\s*:/i, /vbscript\s*:/i, /expression\s*\(/i, /eval\s*\(/i, /alert\s*\(/i, /document\.cookie/i, /document\.write\s*\(/i, /window\.location/i, /innerHTML/i];
return xssPatterns.some(pattern => pattern.test(input));
}
// eslint-disable-next-line no-control-regex
const fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
const serializeCookie = function (name, val) {
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
path: '/'
};
const opt = options;
const value = encodeURIComponent(val);
let str = `${name}=${value}`;
if (opt.maxAge > 0) {
const maxAge = opt.maxAge - 0;
if (Number.isNaN(maxAge)) throw new Error('maxAge should be a Number');
str += `; Max-Age=${Math.floor(maxAge)}`;
}
if (opt.domain) {
if (!fieldContentRegExp.test(opt.domain)) {
throw new TypeError('option domain is invalid');
}
str += `; Domain=${opt.domain}`;
}
if (opt.path) {
if (!fieldContentRegExp.test(opt.path)) {
throw new TypeError('option path is invalid');
}
str += `; Path=${opt.path}`;
}
if (opt.expires) {
if (typeof opt.expires.toUTCString !== 'function') {
throw new TypeError('option expires is invalid');
}
str += `; Expires=${opt.expires.toUTCString()}`;
}
if (opt.httpOnly) str += '; HttpOnly';
if (opt.secure) str += '; Secure';
if (opt.sameSite) {
const sameSite = typeof opt.sameSite === 'string' ? opt.sameSite.toLowerCase() : opt.sameSite;
switch (sameSite) {
case true:
str += '; SameSite=Strict';
break;
case 'lax':
str += '; SameSite=Lax';
break;
case 'strict':
str += '; SameSite=Strict';
break;
case 'none':
str += '; SameSite=None';
break;
default:
throw new TypeError('option sameSite is invalid');
}
}
if (opt.partitioned) str += '; Partitioned';
return str;
};
const cookie = {
create(name, value, minutes, domain) {
let cookieOptions = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
path: '/',
sameSite: 'strict'
};
if (minutes) {
cookieOptions.expires = new Date();
cookieOptions.expires.setTime(cookieOptions.expires.getTime() + minutes * 60 * 1000);
}
if (domain) cookieOptions.domain = domain;
document.cookie = serializeCookie(name, value, cookieOptions);
},
read(name) {
const nameEQ = `${name}=`;
const ca = document.cookie.split(';');
for (let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) === ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
}
return null;
},
remove(name, domain) {
this.create(name, '', -1, domain);
}
};
var cookie$1 = {
name: 'cookie',
// Deconstruct the options object and extract the lookupCookie property
lookup(_ref) {
let {
lookupCookie
} = _ref;
if (lookupCookie && typeof document !== 'undefined') {
return cookie.read(lookupCookie) || undefined;
}
return undefined;
},
// Deconstruct the options object and extract the lookupCookie, cookieMinutes, cookieDomain, and cookieOptions properties
cacheUserLanguage(lng, _ref2) {
let {
lookupCookie,
cookieMinutes,
cookieDomain,
cookieOptions
} = _ref2;
if (lookupCookie && typeof document !== 'undefined') {
cookie.create(lookupCookie, lng, cookieMinutes, cookieDomain, cookieOptions);
}
}
};
var querystring = {
name: 'querystring',
// Deconstruct the options object and extract the lookupQuerystring property
lookup(_ref) {
let {
lookupQuerystring
} = _ref;
let found;
if (typeof window !== 'undefined') {
let {
search
} = window.location;
if (!window.location.search && window.location.hash?.indexOf('?') > -1) {
search = window.location.hash.substring(window.location.hash.indexOf('?'));
}
const query = search.substring(1);
const params = query.split('&');
for (let i = 0; i < params.length; i++) {
const pos = params[i].indexOf('=');
if (pos > 0) {
const key = params[i].substring(0, pos);
if (key === lookupQuerystring) {
found = params[i].substring(pos + 1);
}
}
}
}
return found;
}
};
var hash = {
name: 'hash',
// Deconstruct the options object and extract the lookupHash property and the lookupFromHashIndex property
lookup(_ref) {
let {
lookupHash,
lookupFromHashIndex
} = _ref;
let found;
if (typeof window !== 'undefined') {
const {
hash
} = window.location;
if (hash && hash.length > 2) {
const query = hash.substring(1);
if (lookupHash) {
const params = query.split('&');
for (let i = 0; i < params.length; i++) {
const pos = params[i].indexOf('=');
if (pos > 0) {
const key = params[i].substring(0, pos);
if (key === lookupHash) {
found = params[i].substring(pos + 1);
}
}
}
}
if (found) return found;
if (!found && lookupFromHashIndex > -1) {
const language = hash.match(/\/([a-zA-Z-]*)/g);
if (!Array.isArray(language)) return undefined;
const index = typeof lookupFromHashIndex === 'number' ? lookupFromHashIndex : 0;
return language[index]?.replace('/', '');
}
}
}
return found;
}
};
let hasLocalStorageSupport = null;
const localStorageAvailable = () => {
if (hasLocalStorageSupport !== null) return hasLocalStorageSupport;
try {
hasLocalStorageSupport = typeof window !== 'undefined' && window.localStorage !== null;
if (!hasLocalStorageSupport) {
return false;
}
const testKey = 'i18next.translate.boo';
window.localStorage.setItem(testKey, 'foo');
window.localStorage.removeItem(testKey);
} catch (e) {
hasLocalStorageSupport = false;
}
return hasLocalStorageSupport;
};
var localStorage = {
name: 'localStorage',
// Deconstruct the options object and extract the lookupLocalStorage property
lookup(_ref) {
let {
lookupLocalStorage
} = _ref;
if (lookupLocalStorage && localStorageAvailable()) {
return window.localStorage.getItem(lookupLocalStorage) || undefined; // Undefined ensures type consistency with the previous version of this function
}
return undefined;
},
// Deconstruct the options object and extract the lookupLocalStorage property
cacheUserLanguage(lng, _ref2) {
let {
lookupLocalStorage
} = _ref2;
if (lookupLocalStorage && localStorageAvailable()) {
window.localStorage.setItem(lookupLocalStorage, lng);
}
}
};
let hasSessionStorageSupport = null;
const sessionStorageAvailable = () => {
if (hasSessionStorageSupport !== null) return hasSessionStorageSupport;
try {
hasSessionStorageSupport = typeof window !== 'undefined' && window.sessionStorage !== null;
if (!hasSessionStorageSupport) {
return false;
}
const testKey = 'i18next.translate.boo';
window.sessionStorage.setItem(testKey, 'foo');
window.sessionStorage.removeItem(testKey);
} catch (e) {
hasSessionStorageSupport = false;
}
return hasSessionStorageSupport;
};
var sessionStorage = {
name: 'sessionStorage',
lookup(_ref) {
let {
lookupSessionStorage
} = _ref;
if (lookupSessionStorage && sessionStorageAvailable()) {
return window.sessionStorage.getItem(lookupSessionStorage) || undefined;
}
return undefined;
},
cacheUserLanguage(lng, _ref2) {
let {
lookupSessionStorage
} = _ref2;
if (lookupSessionStorage && sessionStorageAvailable()) {
window.sessionStorage.setItem(lookupSessionStorage, lng);
}
}
};
var navigator$1 = {
name: 'navigator',
lookup(options) {
const found = [];
if (typeof navigator !== 'undefined') {
const {
languages,
userLanguage,
language
} = navigator;
if (languages) {
// chrome only; not an array, so can't use .push.apply instead of iterating
for (let i = 0; i < languages.length; i++) {
found.push(languages[i]);
}
}
if (userLanguage) {
found.push(userLanguage);
}
if (language) {
found.push(language);
}
}
return found.length > 0 ? found : undefined;
}
};
var htmlTag = {
name: 'htmlTag',
// Deconstruct the options object and extract the htmlTag property
lookup(_ref) {
let {
htmlTag
} = _ref;
let found;
const internalHtmlTag = htmlTag || (typeof document !== 'undefined' ? document.documentElement : null);
if (internalHtmlTag && typeof internalHtmlTag.getAttribute === 'function') {
found = internalHtmlTag.getAttribute('lang');
}
return found;
}
};
var path = {
name: 'path',
// Deconstruct the options object and extract the lookupFromPathIndex property
lookup(_ref) {
let {
lookupFromPathIndex
} = _ref;
if (typeof window === 'undefined') return undefined;
const language = window.location.pathname.match(/\/([a-zA-Z-]*)/g);
if (!Array.isArray(language)) return undefined;
const index = typeof lookupFromPathIndex === 'number' ? lookupFromPathIndex : 0;
return language[index]?.replace('/', '');
}
};
var subdomain = {
name: 'subdomain',
lookup(_ref) {
let {
lookupFromSubdomainIndex
} = _ref;
// If given get the subdomain index else 1
const internalLookupFromSubdomainIndex = typeof lookupFromSubdomainIndex === 'number' ? lookupFromSubdomainIndex + 1 : 1;
// get all matches if window.location. is existing
// first item of match is the match itself and the second is the first group match which should be the first subdomain match
// is the hostname no public domain get the or option of localhost
const language = typeof window !== 'undefined' && window.location?.hostname?.match(/^(\w{2,5})\.(([a-z0-9-]{1,63}\.[a-z]{2,6})|localhost)/i);
// if there is no match (null) return undefined
if (!language) return undefined;
// return the given group match
return language[internalLookupFromSubdomainIndex];
}
};
// some environments, throws when accessing document.cookie
let canCookies = false;
try {
// eslint-disable-next-line no-unused-expressions
document.cookie;
canCookies = true;
// eslint-disable-next-line no-empty
} catch (e) {}
const order = ['querystring', 'cookie', 'localStorage', 'sessionStorage', 'navigator', 'htmlTag'];
if (!canCookies) order.splice(1, 1);
const getDefaults = () => ({
order,
lookupQuerystring: 'lng',
lookupCookie: 'i18next',
lookupLocalStorage: 'i18nextLng',
lookupSessionStorage: 'i18nextLng',
// cache user language
caches: ['localStorage'],
excludeCacheFor: ['cimode'],
// cookieMinutes: 10,
// cookieDomain: 'myDomain'
convertDetectedLanguage: l => l
});
class Browser {
constructor(services) {
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
this.type = 'languageDetector';
this.detectors = {};
this.init(services, options);
}
init() {
let services = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
languageUtils: {}
};
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
let i18nOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
this.services = services;
this.options = defaults(options, this.options || {}, getDefaults());
if (typeof this.options.convertDetectedLanguage === 'string' && this.options.convertDetectedLanguage.indexOf('15897') > -1) {
this.options.convertDetectedLanguage = l => l.replace('-', '_');
}
// backwards compatibility
if (this.options.lookupFromUrlIndex) this.options.lookupFromPathIndex = this.options.lookupFromUrlIndex;
this.i18nOptions = i18nOptions;
this.addDetector(cookie$1);
this.addDetector(querystring);
this.addDetector(localStorage);
this.addDetector(sessionStorage);
this.addDetector(navigator$1);
this.addDetector(htmlTag);
this.addDetector(path);
this.addDetector(subdomain);
this.addDetector(hash);
}
addDetector(detector) {
this.detectors[detector.name] = detector;
return this;
}
detect() {
let detectionOrder = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.options.order;
let detected = [];
detectionOrder.forEach(detectorName => {
if (this.detectors[detectorName]) {
let lookup = this.detectors[detectorName].lookup(this.options);
if (lookup && typeof lookup === 'string') lookup = [lookup];
if (lookup) detected = detected.concat(lookup);
}
});
detected = detected.filter(d => d !== undefined && d !== null && !hasXSS(d)).map(d => this.options.convertDetectedLanguage(d));
if (this.services && this.services.languageUtils && this.services.languageUtils.getBestMatchFromCodes) return detected; // new i18next v19.5.0
return detected.length > 0 ? detected[0] : null; // a little backward compatibility
}
cacheUserLanguage(lng) {
let caches = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.options.caches;
if (!caches) return;
if (this.options.excludeCacheFor && this.options.excludeCacheFor.indexOf(lng) > -1) return;
caches.forEach(cacheName => {
if (this.detectors[cacheName]) this.detectors[cacheName].cacheUserLanguage(lng, this.options);
});
}
}
Browser.type = 'languageDetector';
export { Browser as default };

View file

@ -0,0 +1 @@
{"type":"module","version":"8.2.0"}

View file

@ -0,0 +1,450 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.i18nextBrowserLanguageDetector = factory());
})(this, (function () { 'use strict';
const {
slice,
forEach
} = [];
function defaults(obj) {
forEach.call(slice.call(arguments, 1), source => {
if (source) {
for (const prop in source) {
if (obj[prop] === undefined) obj[prop] = source[prop];
}
}
});
return obj;
}
function hasXSS(input) {
if (typeof input !== 'string') return false;
// Common XSS attack patterns
const xssPatterns = [/<\s*script.*?>/i, /<\s*\/\s*script\s*>/i, /<\s*img.*?on\w+\s*=/i, /<\s*\w+\s*on\w+\s*=.*?>/i, /javascript\s*:/i, /vbscript\s*:/i, /expression\s*\(/i, /eval\s*\(/i, /alert\s*\(/i, /document\.cookie/i, /document\.write\s*\(/i, /window\.location/i, /innerHTML/i];
return xssPatterns.some(pattern => pattern.test(input));
}
// eslint-disable-next-line no-control-regex
const fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
const serializeCookie = function (name, val) {
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
path: '/'
};
const opt = options;
const value = encodeURIComponent(val);
let str = `${name}=${value}`;
if (opt.maxAge > 0) {
const maxAge = opt.maxAge - 0;
if (Number.isNaN(maxAge)) throw new Error('maxAge should be a Number');
str += `; Max-Age=${Math.floor(maxAge)}`;
}
if (opt.domain) {
if (!fieldContentRegExp.test(opt.domain)) {
throw new TypeError('option domain is invalid');
}
str += `; Domain=${opt.domain}`;
}
if (opt.path) {
if (!fieldContentRegExp.test(opt.path)) {
throw new TypeError('option path is invalid');
}
str += `; Path=${opt.path}`;
}
if (opt.expires) {
if (typeof opt.expires.toUTCString !== 'function') {
throw new TypeError('option expires is invalid');
}
str += `; Expires=${opt.expires.toUTCString()}`;
}
if (opt.httpOnly) str += '; HttpOnly';
if (opt.secure) str += '; Secure';
if (opt.sameSite) {
const sameSite = typeof opt.sameSite === 'string' ? opt.sameSite.toLowerCase() : opt.sameSite;
switch (sameSite) {
case true:
str += '; SameSite=Strict';
break;
case 'lax':
str += '; SameSite=Lax';
break;
case 'strict':
str += '; SameSite=Strict';
break;
case 'none':
str += '; SameSite=None';
break;
default:
throw new TypeError('option sameSite is invalid');
}
}
if (opt.partitioned) str += '; Partitioned';
return str;
};
const cookie = {
create(name, value, minutes, domain) {
let cookieOptions = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
path: '/',
sameSite: 'strict'
};
if (minutes) {
cookieOptions.expires = new Date();
cookieOptions.expires.setTime(cookieOptions.expires.getTime() + minutes * 60 * 1000);
}
if (domain) cookieOptions.domain = domain;
document.cookie = serializeCookie(name, value, cookieOptions);
},
read(name) {
const nameEQ = `${name}=`;
const ca = document.cookie.split(';');
for (let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) === ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
}
return null;
},
remove(name, domain) {
this.create(name, '', -1, domain);
}
};
var cookie$1 = {
name: 'cookie',
// Deconstruct the options object and extract the lookupCookie property
lookup(_ref) {
let {
lookupCookie
} = _ref;
if (lookupCookie && typeof document !== 'undefined') {
return cookie.read(lookupCookie) || undefined;
}
return undefined;
},
// Deconstruct the options object and extract the lookupCookie, cookieMinutes, cookieDomain, and cookieOptions properties
cacheUserLanguage(lng, _ref2) {
let {
lookupCookie,
cookieMinutes,
cookieDomain,
cookieOptions
} = _ref2;
if (lookupCookie && typeof document !== 'undefined') {
cookie.create(lookupCookie, lng, cookieMinutes, cookieDomain, cookieOptions);
}
}
};
var querystring = {
name: 'querystring',
// Deconstruct the options object and extract the lookupQuerystring property
lookup(_ref) {
let {
lookupQuerystring
} = _ref;
let found;
if (typeof window !== 'undefined') {
let {
search
} = window.location;
if (!window.location.search && window.location.hash?.indexOf('?') > -1) {
search = window.location.hash.substring(window.location.hash.indexOf('?'));
}
const query = search.substring(1);
const params = query.split('&');
for (let i = 0; i < params.length; i++) {
const pos = params[i].indexOf('=');
if (pos > 0) {
const key = params[i].substring(0, pos);
if (key === lookupQuerystring) {
found = params[i].substring(pos + 1);
}
}
}
}
return found;
}
};
var hash = {
name: 'hash',
// Deconstruct the options object and extract the lookupHash property and the lookupFromHashIndex property
lookup(_ref) {
let {
lookupHash,
lookupFromHashIndex
} = _ref;
let found;
if (typeof window !== 'undefined') {
const {
hash
} = window.location;
if (hash && hash.length > 2) {
const query = hash.substring(1);
if (lookupHash) {
const params = query.split('&');
for (let i = 0; i < params.length; i++) {
const pos = params[i].indexOf('=');
if (pos > 0) {
const key = params[i].substring(0, pos);
if (key === lookupHash) {
found = params[i].substring(pos + 1);
}
}
}
}
if (found) return found;
if (!found && lookupFromHashIndex > -1) {
const language = hash.match(/\/([a-zA-Z-]*)/g);
if (!Array.isArray(language)) return undefined;
const index = typeof lookupFromHashIndex === 'number' ? lookupFromHashIndex : 0;
return language[index]?.replace('/', '');
}
}
}
return found;
}
};
let hasLocalStorageSupport = null;
const localStorageAvailable = () => {
if (hasLocalStorageSupport !== null) return hasLocalStorageSupport;
try {
hasLocalStorageSupport = typeof window !== 'undefined' && window.localStorage !== null;
if (!hasLocalStorageSupport) {
return false;
}
const testKey = 'i18next.translate.boo';
window.localStorage.setItem(testKey, 'foo');
window.localStorage.removeItem(testKey);
} catch (e) {
hasLocalStorageSupport = false;
}
return hasLocalStorageSupport;
};
var localStorage = {
name: 'localStorage',
// Deconstruct the options object and extract the lookupLocalStorage property
lookup(_ref) {
let {
lookupLocalStorage
} = _ref;
if (lookupLocalStorage && localStorageAvailable()) {
return window.localStorage.getItem(lookupLocalStorage) || undefined; // Undefined ensures type consistency with the previous version of this function
}
return undefined;
},
// Deconstruct the options object and extract the lookupLocalStorage property
cacheUserLanguage(lng, _ref2) {
let {
lookupLocalStorage
} = _ref2;
if (lookupLocalStorage && localStorageAvailable()) {
window.localStorage.setItem(lookupLocalStorage, lng);
}
}
};
let hasSessionStorageSupport = null;
const sessionStorageAvailable = () => {
if (hasSessionStorageSupport !== null) return hasSessionStorageSupport;
try {
hasSessionStorageSupport = typeof window !== 'undefined' && window.sessionStorage !== null;
if (!hasSessionStorageSupport) {
return false;
}
const testKey = 'i18next.translate.boo';
window.sessionStorage.setItem(testKey, 'foo');
window.sessionStorage.removeItem(testKey);
} catch (e) {
hasSessionStorageSupport = false;
}
return hasSessionStorageSupport;
};
var sessionStorage = {
name: 'sessionStorage',
lookup(_ref) {
let {
lookupSessionStorage
} = _ref;
if (lookupSessionStorage && sessionStorageAvailable()) {
return window.sessionStorage.getItem(lookupSessionStorage) || undefined;
}
return undefined;
},
cacheUserLanguage(lng, _ref2) {
let {
lookupSessionStorage
} = _ref2;
if (lookupSessionStorage && sessionStorageAvailable()) {
window.sessionStorage.setItem(lookupSessionStorage, lng);
}
}
};
var navigator$1 = {
name: 'navigator',
lookup(options) {
const found = [];
if (typeof navigator !== 'undefined') {
const {
languages,
userLanguage,
language
} = navigator;
if (languages) {
// chrome only; not an array, so can't use .push.apply instead of iterating
for (let i = 0; i < languages.length; i++) {
found.push(languages[i]);
}
}
if (userLanguage) {
found.push(userLanguage);
}
if (language) {
found.push(language);
}
}
return found.length > 0 ? found : undefined;
}
};
var htmlTag = {
name: 'htmlTag',
// Deconstruct the options object and extract the htmlTag property
lookup(_ref) {
let {
htmlTag
} = _ref;
let found;
const internalHtmlTag = htmlTag || (typeof document !== 'undefined' ? document.documentElement : null);
if (internalHtmlTag && typeof internalHtmlTag.getAttribute === 'function') {
found = internalHtmlTag.getAttribute('lang');
}
return found;
}
};
var path = {
name: 'path',
// Deconstruct the options object and extract the lookupFromPathIndex property
lookup(_ref) {
let {
lookupFromPathIndex
} = _ref;
if (typeof window === 'undefined') return undefined;
const language = window.location.pathname.match(/\/([a-zA-Z-]*)/g);
if (!Array.isArray(language)) return undefined;
const index = typeof lookupFromPathIndex === 'number' ? lookupFromPathIndex : 0;
return language[index]?.replace('/', '');
}
};
var subdomain = {
name: 'subdomain',
lookup(_ref) {
let {
lookupFromSubdomainIndex
} = _ref;
// If given get the subdomain index else 1
const internalLookupFromSubdomainIndex = typeof lookupFromSubdomainIndex === 'number' ? lookupFromSubdomainIndex + 1 : 1;
// get all matches if window.location. is existing
// first item of match is the match itself and the second is the first group match which should be the first subdomain match
// is the hostname no public domain get the or option of localhost
const language = typeof window !== 'undefined' && window.location?.hostname?.match(/^(\w{2,5})\.(([a-z0-9-]{1,63}\.[a-z]{2,6})|localhost)/i);
// if there is no match (null) return undefined
if (!language) return undefined;
// return the given group match
return language[internalLookupFromSubdomainIndex];
}
};
// some environments, throws when accessing document.cookie
let canCookies = false;
try {
// eslint-disable-next-line no-unused-expressions
document.cookie;
canCookies = true;
// eslint-disable-next-line no-empty
} catch (e) {}
const order = ['querystring', 'cookie', 'localStorage', 'sessionStorage', 'navigator', 'htmlTag'];
if (!canCookies) order.splice(1, 1);
const getDefaults = () => ({
order,
lookupQuerystring: 'lng',
lookupCookie: 'i18next',
lookupLocalStorage: 'i18nextLng',
lookupSessionStorage: 'i18nextLng',
// cache user language
caches: ['localStorage'],
excludeCacheFor: ['cimode'],
// cookieMinutes: 10,
// cookieDomain: 'myDomain'
convertDetectedLanguage: l => l
});
class Browser {
constructor(services) {
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
this.type = 'languageDetector';
this.detectors = {};
this.init(services, options);
}
init() {
let services = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
languageUtils: {}
};
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
let i18nOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
this.services = services;
this.options = defaults(options, this.options || {}, getDefaults());
if (typeof this.options.convertDetectedLanguage === 'string' && this.options.convertDetectedLanguage.indexOf('15897') > -1) {
this.options.convertDetectedLanguage = l => l.replace('-', '_');
}
// backwards compatibility
if (this.options.lookupFromUrlIndex) this.options.lookupFromPathIndex = this.options.lookupFromUrlIndex;
this.i18nOptions = i18nOptions;
this.addDetector(cookie$1);
this.addDetector(querystring);
this.addDetector(localStorage);
this.addDetector(sessionStorage);
this.addDetector(navigator$1);
this.addDetector(htmlTag);
this.addDetector(path);
this.addDetector(subdomain);
this.addDetector(hash);
}
addDetector(detector) {
this.detectors[detector.name] = detector;
return this;
}
detect() {
let detectionOrder = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.options.order;
let detected = [];
detectionOrder.forEach(detectorName => {
if (this.detectors[detectorName]) {
let lookup = this.detectors[detectorName].lookup(this.options);
if (lookup && typeof lookup === 'string') lookup = [lookup];
if (lookup) detected = detected.concat(lookup);
}
});
detected = detected.filter(d => d !== undefined && d !== null && !hasXSS(d)).map(d => this.options.convertDetectedLanguage(d));
if (this.services && this.services.languageUtils && this.services.languageUtils.getBestMatchFromCodes) return detected; // new i18next v19.5.0
return detected.length > 0 ? detected[0] : null; // a little backward compatibility
}
cacheUserLanguage(lng) {
let caches = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.options.caches;
if (!caches) return;
if (this.options.excludeCacheFor && this.options.excludeCacheFor.indexOf(lng) > -1) return;
caches.forEach(cacheName => {
if (this.detectors[cacheName]) this.detectors[cacheName].cacheUserLanguage(lng, this.options);
});
}
}
Browser.type = 'languageDetector';
return Browser;
}));

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,450 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.i18nextBrowserLanguageDetector = factory());
})(this, (function () { 'use strict';
const {
slice,
forEach
} = [];
function defaults(obj) {
forEach.call(slice.call(arguments, 1), source => {
if (source) {
for (const prop in source) {
if (obj[prop] === undefined) obj[prop] = source[prop];
}
}
});
return obj;
}
function hasXSS(input) {
if (typeof input !== 'string') return false;
// Common XSS attack patterns
const xssPatterns = [/<\s*script.*?>/i, /<\s*\/\s*script\s*>/i, /<\s*img.*?on\w+\s*=/i, /<\s*\w+\s*on\w+\s*=.*?>/i, /javascript\s*:/i, /vbscript\s*:/i, /expression\s*\(/i, /eval\s*\(/i, /alert\s*\(/i, /document\.cookie/i, /document\.write\s*\(/i, /window\.location/i, /innerHTML/i];
return xssPatterns.some(pattern => pattern.test(input));
}
// eslint-disable-next-line no-control-regex
const fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
const serializeCookie = function (name, val) {
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
path: '/'
};
const opt = options;
const value = encodeURIComponent(val);
let str = `${name}=${value}`;
if (opt.maxAge > 0) {
const maxAge = opt.maxAge - 0;
if (Number.isNaN(maxAge)) throw new Error('maxAge should be a Number');
str += `; Max-Age=${Math.floor(maxAge)}`;
}
if (opt.domain) {
if (!fieldContentRegExp.test(opt.domain)) {
throw new TypeError('option domain is invalid');
}
str += `; Domain=${opt.domain}`;
}
if (opt.path) {
if (!fieldContentRegExp.test(opt.path)) {
throw new TypeError('option path is invalid');
}
str += `; Path=${opt.path}`;
}
if (opt.expires) {
if (typeof opt.expires.toUTCString !== 'function') {
throw new TypeError('option expires is invalid');
}
str += `; Expires=${opt.expires.toUTCString()}`;
}
if (opt.httpOnly) str += '; HttpOnly';
if (opt.secure) str += '; Secure';
if (opt.sameSite) {
const sameSite = typeof opt.sameSite === 'string' ? opt.sameSite.toLowerCase() : opt.sameSite;
switch (sameSite) {
case true:
str += '; SameSite=Strict';
break;
case 'lax':
str += '; SameSite=Lax';
break;
case 'strict':
str += '; SameSite=Strict';
break;
case 'none':
str += '; SameSite=None';
break;
default:
throw new TypeError('option sameSite is invalid');
}
}
if (opt.partitioned) str += '; Partitioned';
return str;
};
const cookie = {
create(name, value, minutes, domain) {
let cookieOptions = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
path: '/',
sameSite: 'strict'
};
if (minutes) {
cookieOptions.expires = new Date();
cookieOptions.expires.setTime(cookieOptions.expires.getTime() + minutes * 60 * 1000);
}
if (domain) cookieOptions.domain = domain;
document.cookie = serializeCookie(name, value, cookieOptions);
},
read(name) {
const nameEQ = `${name}=`;
const ca = document.cookie.split(';');
for (let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) === ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
}
return null;
},
remove(name, domain) {
this.create(name, '', -1, domain);
}
};
var cookie$1 = {
name: 'cookie',
// Deconstruct the options object and extract the lookupCookie property
lookup(_ref) {
let {
lookupCookie
} = _ref;
if (lookupCookie && typeof document !== 'undefined') {
return cookie.read(lookupCookie) || undefined;
}
return undefined;
},
// Deconstruct the options object and extract the lookupCookie, cookieMinutes, cookieDomain, and cookieOptions properties
cacheUserLanguage(lng, _ref2) {
let {
lookupCookie,
cookieMinutes,
cookieDomain,
cookieOptions
} = _ref2;
if (lookupCookie && typeof document !== 'undefined') {
cookie.create(lookupCookie, lng, cookieMinutes, cookieDomain, cookieOptions);
}
}
};
var querystring = {
name: 'querystring',
// Deconstruct the options object and extract the lookupQuerystring property
lookup(_ref) {
let {
lookupQuerystring
} = _ref;
let found;
if (typeof window !== 'undefined') {
let {
search
} = window.location;
if (!window.location.search && window.location.hash?.indexOf('?') > -1) {
search = window.location.hash.substring(window.location.hash.indexOf('?'));
}
const query = search.substring(1);
const params = query.split('&');
for (let i = 0; i < params.length; i++) {
const pos = params[i].indexOf('=');
if (pos > 0) {
const key = params[i].substring(0, pos);
if (key === lookupQuerystring) {
found = params[i].substring(pos + 1);
}
}
}
}
return found;
}
};
var hash = {
name: 'hash',
// Deconstruct the options object and extract the lookupHash property and the lookupFromHashIndex property
lookup(_ref) {
let {
lookupHash,
lookupFromHashIndex
} = _ref;
let found;
if (typeof window !== 'undefined') {
const {
hash
} = window.location;
if (hash && hash.length > 2) {
const query = hash.substring(1);
if (lookupHash) {
const params = query.split('&');
for (let i = 0; i < params.length; i++) {
const pos = params[i].indexOf('=');
if (pos > 0) {
const key = params[i].substring(0, pos);
if (key === lookupHash) {
found = params[i].substring(pos + 1);
}
}
}
}
if (found) return found;
if (!found && lookupFromHashIndex > -1) {
const language = hash.match(/\/([a-zA-Z-]*)/g);
if (!Array.isArray(language)) return undefined;
const index = typeof lookupFromHashIndex === 'number' ? lookupFromHashIndex : 0;
return language[index]?.replace('/', '');
}
}
}
return found;
}
};
let hasLocalStorageSupport = null;
const localStorageAvailable = () => {
if (hasLocalStorageSupport !== null) return hasLocalStorageSupport;
try {
hasLocalStorageSupport = typeof window !== 'undefined' && window.localStorage !== null;
if (!hasLocalStorageSupport) {
return false;
}
const testKey = 'i18next.translate.boo';
window.localStorage.setItem(testKey, 'foo');
window.localStorage.removeItem(testKey);
} catch (e) {
hasLocalStorageSupport = false;
}
return hasLocalStorageSupport;
};
var localStorage = {
name: 'localStorage',
// Deconstruct the options object and extract the lookupLocalStorage property
lookup(_ref) {
let {
lookupLocalStorage
} = _ref;
if (lookupLocalStorage && localStorageAvailable()) {
return window.localStorage.getItem(lookupLocalStorage) || undefined; // Undefined ensures type consistency with the previous version of this function
}
return undefined;
},
// Deconstruct the options object and extract the lookupLocalStorage property
cacheUserLanguage(lng, _ref2) {
let {
lookupLocalStorage
} = _ref2;
if (lookupLocalStorage && localStorageAvailable()) {
window.localStorage.setItem(lookupLocalStorage, lng);
}
}
};
let hasSessionStorageSupport = null;
const sessionStorageAvailable = () => {
if (hasSessionStorageSupport !== null) return hasSessionStorageSupport;
try {
hasSessionStorageSupport = typeof window !== 'undefined' && window.sessionStorage !== null;
if (!hasSessionStorageSupport) {
return false;
}
const testKey = 'i18next.translate.boo';
window.sessionStorage.setItem(testKey, 'foo');
window.sessionStorage.removeItem(testKey);
} catch (e) {
hasSessionStorageSupport = false;
}
return hasSessionStorageSupport;
};
var sessionStorage = {
name: 'sessionStorage',
lookup(_ref) {
let {
lookupSessionStorage
} = _ref;
if (lookupSessionStorage && sessionStorageAvailable()) {
return window.sessionStorage.getItem(lookupSessionStorage) || undefined;
}
return undefined;
},
cacheUserLanguage(lng, _ref2) {
let {
lookupSessionStorage
} = _ref2;
if (lookupSessionStorage && sessionStorageAvailable()) {
window.sessionStorage.setItem(lookupSessionStorage, lng);
}
}
};
var navigator$1 = {
name: 'navigator',
lookup(options) {
const found = [];
if (typeof navigator !== 'undefined') {
const {
languages,
userLanguage,
language
} = navigator;
if (languages) {
// chrome only; not an array, so can't use .push.apply instead of iterating
for (let i = 0; i < languages.length; i++) {
found.push(languages[i]);
}
}
if (userLanguage) {
found.push(userLanguage);
}
if (language) {
found.push(language);
}
}
return found.length > 0 ? found : undefined;
}
};
var htmlTag = {
name: 'htmlTag',
// Deconstruct the options object and extract the htmlTag property
lookup(_ref) {
let {
htmlTag
} = _ref;
let found;
const internalHtmlTag = htmlTag || (typeof document !== 'undefined' ? document.documentElement : null);
if (internalHtmlTag && typeof internalHtmlTag.getAttribute === 'function') {
found = internalHtmlTag.getAttribute('lang');
}
return found;
}
};
var path = {
name: 'path',
// Deconstruct the options object and extract the lookupFromPathIndex property
lookup(_ref) {
let {
lookupFromPathIndex
} = _ref;
if (typeof window === 'undefined') return undefined;
const language = window.location.pathname.match(/\/([a-zA-Z-]*)/g);
if (!Array.isArray(language)) return undefined;
const index = typeof lookupFromPathIndex === 'number' ? lookupFromPathIndex : 0;
return language[index]?.replace('/', '');
}
};
var subdomain = {
name: 'subdomain',
lookup(_ref) {
let {
lookupFromSubdomainIndex
} = _ref;
// If given get the subdomain index else 1
const internalLookupFromSubdomainIndex = typeof lookupFromSubdomainIndex === 'number' ? lookupFromSubdomainIndex + 1 : 1;
// get all matches if window.location. is existing
// first item of match is the match itself and the second is the first group match which should be the first subdomain match
// is the hostname no public domain get the or option of localhost
const language = typeof window !== 'undefined' && window.location?.hostname?.match(/^(\w{2,5})\.(([a-z0-9-]{1,63}\.[a-z]{2,6})|localhost)/i);
// if there is no match (null) return undefined
if (!language) return undefined;
// return the given group match
return language[internalLookupFromSubdomainIndex];
}
};
// some environments, throws when accessing document.cookie
let canCookies = false;
try {
// eslint-disable-next-line no-unused-expressions
document.cookie;
canCookies = true;
// eslint-disable-next-line no-empty
} catch (e) {}
const order = ['querystring', 'cookie', 'localStorage', 'sessionStorage', 'navigator', 'htmlTag'];
if (!canCookies) order.splice(1, 1);
const getDefaults = () => ({
order,
lookupQuerystring: 'lng',
lookupCookie: 'i18next',
lookupLocalStorage: 'i18nextLng',
lookupSessionStorage: 'i18nextLng',
// cache user language
caches: ['localStorage'],
excludeCacheFor: ['cimode'],
// cookieMinutes: 10,
// cookieDomain: 'myDomain'
convertDetectedLanguage: l => l
});
class Browser {
constructor(services) {
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
this.type = 'languageDetector';
this.detectors = {};
this.init(services, options);
}
init() {
let services = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
languageUtils: {}
};
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
let i18nOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
this.services = services;
this.options = defaults(options, this.options || {}, getDefaults());
if (typeof this.options.convertDetectedLanguage === 'string' && this.options.convertDetectedLanguage.indexOf('15897') > -1) {
this.options.convertDetectedLanguage = l => l.replace('-', '_');
}
// backwards compatibility
if (this.options.lookupFromUrlIndex) this.options.lookupFromPathIndex = this.options.lookupFromUrlIndex;
this.i18nOptions = i18nOptions;
this.addDetector(cookie$1);
this.addDetector(querystring);
this.addDetector(localStorage);
this.addDetector(sessionStorage);
this.addDetector(navigator$1);
this.addDetector(htmlTag);
this.addDetector(path);
this.addDetector(subdomain);
this.addDetector(hash);
}
addDetector(detector) {
this.detectors[detector.name] = detector;
return this;
}
detect() {
let detectionOrder = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.options.order;
let detected = [];
detectionOrder.forEach(detectorName => {
if (this.detectors[detectorName]) {
let lookup = this.detectors[detectorName].lookup(this.options);
if (lookup && typeof lookup === 'string') lookup = [lookup];
if (lookup) detected = detected.concat(lookup);
}
});
detected = detected.filter(d => d !== undefined && d !== null && !hasXSS(d)).map(d => this.options.convertDetectedLanguage(d));
if (this.services && this.services.languageUtils && this.services.languageUtils.getBestMatchFromCodes) return detected; // new i18next v19.5.0
return detected.length > 0 ? detected[0] : null; // a little backward compatibility
}
cacheUserLanguage(lng) {
let caches = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.options.caches;
if (!caches) return;
if (this.options.excludeCacheFor && this.options.excludeCacheFor.indexOf(lng) > -1) return;
caches.forEach(cacheName => {
if (this.detectors[cacheName]) this.detectors[cacheName].cacheUserLanguage(lng, this.options);
});
}
}
Browser.type = 'languageDetector';
return Browser;
}));

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,6 @@
import * as index from './index.js';
export default index.default;
export type DetectorOptions = index.DetectorOptions;
export type CustomDetector = index.CustomDetector;

View file

@ -0,0 +1,101 @@
import * as i18next from 'i18next';
interface CookieOptions {
maxAge?: number;
expires?: Date;
httpOnly?: boolean;
path?: string;
domain?: string;
secure?: boolean;
sameSite?: boolean | 'lax' | 'strict' | 'none';
}
export interface DetectorOptions {
/**
* order and from where user language should be detected
*/
order?: Array<
'querystring' | 'cookie' | 'sessionStorage' | 'localStorage' | 'navigator' | 'htmlTag' | string
>;
/**
* keys or params to lookup language from
*/
lookupQuerystring?: string;
lookupCookie?: string;
lookupSessionStorage?: string;
lookupLocalStorage?: string;
lookupFromPathIndex?: number;
lookupFromSubdomainIndex?: number;
/**
* cache user language on
*/
caches?: string[];
/**
* languages to not persist (cookie, localStorage)
*/
excludeCacheFor?: string[];
/**
* optional expire for set cookie
* @default 10
*/
cookieMinutes?: number;
/**
* optional domain for set cookie
*/
cookieDomain?: string;
/**
* optional cookie options
*/
cookieOptions?: CookieOptions
/**
* optional htmlTag with lang attribute
* @default document.documentElement
*/
htmlTag?: HTMLElement | null;
/**
* optional conversion function to use to modify the detected language code
*/
convertDetectedLanguage?: 'Iso15897' | ((lng: string) => string);
}
export interface CustomDetector {
name: string;
cacheUserLanguage?(lng: string, options: DetectorOptions): void;
lookup(options: DetectorOptions): string | string[] | undefined;
}
export default class I18nextBrowserLanguageDetector implements i18next.LanguageDetectorModule {
constructor(services?: any, options?: DetectorOptions);
/**
* Adds detector.
*/
addDetector(detector: CustomDetector): I18nextBrowserLanguageDetector;
/**
* Initializes detector.
*/
init(services?: any, options?: DetectorOptions): void;
detect(detectionOrder?: DetectorOptions['order']): string | string[] | undefined;
cacheUserLanguage(lng: string, caches?: string[]): void;
type: 'languageDetector';
detectors: { [key: string]: any };
services: any;
i18nOptions: any;
}
declare module 'i18next' {
interface CustomPluginOptions {
detection?: DetectorOptions;
}
}

View file

@ -0,0 +1,5 @@
/* eslint no-var: 0 */
var main = require('./dist/cjs/i18nextBrowserLanguageDetector.js');
module.exports = main;
module.exports.default = main;

View file

@ -0,0 +1,87 @@
{
"name": "i18next-browser-languagedetector",
"version": "8.2.0",
"description": "language detector used in browser environment for i18next",
"main": "./dist/cjs/i18nextBrowserLanguageDetector.js",
"module": "./dist/esm/i18nextBrowserLanguageDetector.js",
"types": "./index.d.mts",
"exports": {
"./package.json": "./package.json",
".": {
"types": {
"require": "./index.d.ts",
"import": "./index.d.mts"
},
"module": "./dist/esm/i18nextBrowserLanguageDetector.js",
"import": "./dist/esm/i18nextBrowserLanguageDetector.js",
"require": "./dist/cjs/i18nextBrowserLanguageDetector.js",
"default": "./dist/esm/i18nextBrowserLanguageDetector.js"
},
"./cjs": {
"types": "./index.d.ts",
"default": "./dist/cjs/i18nextBrowserLanguageDetector.js"
},
"./esm": {
"types": "./index.d.mts",
"default": "./dist/esm/i18nextBrowserLanguageDetector.js"
}
},
"keywords": [
"i18next",
"i18next-languageDetector"
],
"homepage": "https://github.com/i18next/i18next-browser-languageDetector",
"bugs": "https://github.com/i18next/i18next-browser-languageDetector/issues",
"repository": {
"type": "git",
"url": "https://github.com/i18next/i18next-browser-languageDetector.git"
},
"dependencies": {
"@babel/runtime": "^7.23.2"
},
"devDependencies": {
"@babel/core": "^7.23.3",
"@babel/plugin-transform-runtime": "^7.23.3",
"@babel/preset-env": "^7.23.3",
"@babel/eslint-parser": "^7.23.3",
"babel-polyfill": "^6.26.0",
"babelify": "^10.0.0",
"browserify": "17.0.0",
"browserify-istanbul": "3.0.1",
"chai": "4.3.10",
"coveralls": "3.1.1",
"cpy-cli": "^5.0.0",
"dtslint": "^4.2.1",
"eslint": "8.53.0",
"eslint-config-airbnb": "19.0.4",
"expect.js": "0.3.1",
"i18next": "23.7.1",
"mkdirp": "3.0.1",
"mocha": "10.8.2",
"rimraf": "5.0.5",
"rollup": "^2.79.1",
"@rollup/plugin-babel": "^5.3.1",
"@rollup/plugin-node-resolve": "^14.1.0",
"rollup-plugin-terser": "^7.0.2",
"tslint": "^5.20.1",
"tsd": "0.29.0",
"typescript": "5.1.3",
"yargs": "17.7.2"
},
"scripts": {
"lint": "eslint src",
"pretest": "npm run lint && npm run test:typescript && npm run test:typescript:noninterop",
"test": "npm run build && mocha test -R spec --exit",
"test:typescript": "tslint --project tsconfig.json && tsd",
"test:typescript:noninterop": "tslint --project tsconfig.nonEsModuleInterop.json",
"build": "rimraf dist && rollup -c && echo '{\"type\":\"module\"}' > dist/esm/package.json && cpy \"./dist/umd/*.js\" ./",
"fix_dist_package": "node -e 'console.log(`{\"type\":\"module\",\"version\":\"${process.env.npm_package_version}\"}`)' > dist/esm/package.json",
"preversion": "npm run test && npm run build && git push",
"postversion": "npm run fix_dist_package && git push && git push --tags"
},
"tsd": {
"directory": "test/typescript"
},
"author": "Jan Mühlemann <jan.muehlemann@gmail.com> (https://github.com/jamuhl)",
"license": "MIT"
}

View file

@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
// typescript defaults to these
"esModuleInterop": false,
"allowSyntheticDefaultImports": false
}
}