Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

i18next-resources-to-backend

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

i18next-resources-to-backend - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

licence

16

dist/cjs/index.js

@@ -9,6 +9,20 @@ 'use strict';

if (typeof res === 'function') {
if (res.length === 2) {
try {
var r = res(language, namespace);
if (r && typeof r.then === 'function') {
r.then(function (data) {
return callback(null, data);
}).catch(callback);
} else {
callback(null, r);
}
} catch (err) {
callback(err);
}
return;
}
res(language, namespace, callback);
return;
}
callback(null, res && res[language] && res[language][namespace]);

@@ -15,0 +29,0 @@ }

@@ -7,6 +7,20 @@ var resourcesToBackend = function resourcesToBackend(res) {

if (typeof res === 'function') {
if (res.length === 2) {
try {
var r = res(language, namespace);
if (r && typeof r.then === 'function') {
r.then(function (data) {
return callback(null, data);
}).catch(callback);
} else {
callback(null, r);
}
} catch (err) {
callback(err);
}
return;
}
res(language, namespace, callback);
return;
}
callback(null, res && res[language] && res[language][namespace]);

@@ -17,2 +31,2 @@ }

export default resourcesToBackend;
export { resourcesToBackend as default };

@@ -5,3 +5,3 @@ (function (global, factory) {

(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.i18nextResourcesToBackend = factory());
}(this, (function () { 'use strict';
})(this, (function () { 'use strict';

@@ -14,6 +14,20 @@ var resourcesToBackend = function resourcesToBackend(res) {

if (typeof res === 'function') {
if (res.length === 2) {
try {
var r = res(language, namespace);
if (r && typeof r.then === 'function') {
r.then(function (data) {
return callback(null, data);
}).catch(callback);
} else {
callback(null, r);
}
} catch (err) {
callback(err);
}
return;
}
res(language, namespace, callback);
return;
}
callback(null, res && res[language] && res[language][namespace]);

@@ -26,2 +40,2 @@ }

})));
}));

2

dist/umd/i18nextResourcesToBackend.min.js

@@ -1,1 +0,1 @@

!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).i18nextResourcesToBackend=n()}(this,(function(){"use strict";return function(e){return{type:"backend",init:function(e,n,t){},read:function(n,t,o){"function"!=typeof e?o(null,e&&e[n]&&e[n][t]):e(n,t,o)}}}}));
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).i18nextResourcesToBackend=n()}(this,(function(){"use strict";return function(e){return{type:"backend",init:function(e,n,t){},read:function(n,t,o){if("function"!=typeof e)o(null,e&&e[n]&&e[n][t]);else{if(2===e.length){try{var f=e(n,t);f&&"function"==typeof f.then?f.then((function(e){return o(null,e)})).catch(o):o(null,f)}catch(e){o(e)}return}e(n,t,o)}}}}}));

@@ -1,4 +0,4 @@

import { BackendModule, Resource, ReadCallback } from 'i18next'
import { BackendModule, Resource, ReadCallback, ResourceKey } from 'i18next'
type ImportFn = (language: string, namespace: string, callback: ReadCallback) => void
type ImportFn = ((language: string, namespace: string, callback: ReadCallback) => void) | ((language: string, namespace: string) => Promise<ResourceKey | boolean | null | undefined>)

@@ -5,0 +5,0 @@ declare function resourcesToBackend(res: Resource | ImportFn): BackendModule

{
"name": "i18next-resources-to-backend",
"version": "1.0.0",
"version": "1.1.0",
"description": "This package helps to transform resources to an i18next backend",
"keywords": [
"i18next",
"i18next-backend",
"i18next-chained-backend"
],
"homepage": "https://github.com/i18next/i18next-resources-to-backend",
"repository": {
"type": "git",
"url": "git@github.com:i18next/i18next-resources-to-backend.git"
},
"bugs": {
"url": "https://github.com/i18next/i18next-resources-to-backend/issues"
},
"type": "module",

@@ -40,31 +53,31 @@ "main": "./dist/cjs/index.js",

"dependencies": {
"@babel/runtime": "7.14.0"
"@babel/runtime": "^7.20.6"
},
"devDependencies": {
"@babel/core": "7.14.3",
"@babel/plugin-transform-runtime": "7.14.3",
"@babel/preset-env": "7.14.2",
"@types/mocha": "8.2.2",
"@typescript-eslint/eslint-plugin": "4.24.0",
"@typescript-eslint/parser": "4.24.0",
"babel-plugin-add-module-exports": "1.0.4",
"eslint": "7.27.0",
"eslint-config-standard": "16.0.2",
"eslint-plugin-import": "2.23.3",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-promise": "5.1.0",
"eslint-plugin-require-path-exists": "1.1.9",
"eslint-plugin-standard": "5.0.0",
"i18next": "20.3.0",
"i18next-chained-backend": "3.0.2",
"mocha": "8.4.0",
"rollup": "2.49.0",
"rollup-plugin-babel": "4.4.0",
"rollup-plugin-commonjs": "10.1.0",
"rollup-plugin-node-resolve": "5.2.0",
"rollup-plugin-terser": "7.0.2",
"should": "13.2.3",
"sinon": "10.0.0",
"tsd": "0.15.1",
"typescript": "4.2.4"
"@babel/core": "^7.20.5",
"@babel/plugin-transform-runtime": "^7.19.6",
"@babel/preset-env": "^7.20.2",
"@types/mocha": "^10.0.1",
"@typescript-eslint/eslint-plugin": "^5.45.1",
"@typescript-eslint/parser": "^5.45.1",
"babel-plugin-add-module-exports": "^1.0.4",
"eslint": "^8.29.0",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-n": "^15.6.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-require-path-exists": "^1.1.9",
"eslint-plugin-standard": "^5.0.0",
"i18next": "^22.1.0",
"i18next-chained-backend": "^4.1.0",
"mocha": "^10.1.0",
"rollup": "^2.79.1",
"@rollup/plugin-babel": "^6.0.0",
"@rollup/plugin-commonjs": "^23.0.0",
"@rollup/plugin-node-resolve": "^14.1.0",
"rollup-plugin-terser": "^7.0.2",
"should": "^13.2.3",
"sinon": "^15.0.0",
"tsd": "^0.25.0",
"typescript": "^4.9.3"
},

@@ -71,0 +84,0 @@ "tsd": {

@@ -80,11 +80,13 @@ # Introduction

HttpBackend, // if a namespace can't be loaded via normal http-backend loadPath, then the inMemoryLocalBackend will try to return the correct resources
resourcesToBackend((language, namespace, callback) => {
import(`./locales/${language}/${namespace}.json`)
.then((resources) => {
callback(null, resources)
})
.catch((error) => {
callback(error, null)
})
})
// with dynamic import, you have to use the "default" key of the module ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#importing_defaults )
resourcesToBackend((language, namespace) => import(`./locales/${language}/${namespace}.json`))
// resourcesToBackend((language, namespace, callback) => {
// import(`./locales/${language}/${namespace}.json`)
// .then(({ default: resources }) => {
// callback(null, resources)
// })
// .catch((error) => {
// callback(error, null)
// })
// })
],

@@ -91,0 +93,0 @@ backendOptions: [{

@@ -1,5 +0,5 @@

import babel from 'rollup-plugin-babel'
import nodeResolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs'
import { babel } from '@rollup/plugin-babel'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import { terser } from 'rollup-plugin-terser'
import commonjs from '@rollup/plugin-commonjs'
import pkg from './package.json'

@@ -9,3 +9,3 @@

exclude: /node_modules/,
runtimeHelpers: true,
babelHelpers: 'runtime',
plugins: [['@babel/transform-runtime', { useESModules }]].concat(plugins),

@@ -12,0 +12,0 @@ comments: false

@@ -6,2 +6,19 @@ const resourcesToBackend = (res) => ({

if (typeof res === 'function') { // in case someone wants to customize the loading...
if (res.length === 2) {
// no callback
try {
const r = res(language, namespace)
if (r && typeof r.then === 'function') {
// promise
r.then((data) => callback(null, data)).catch(callback)
} else {
// sync
callback(null, r)
}
} catch (err) {
callback(err)
}
return
}
// normal with callback
res(language, namespace, callback)

@@ -8,0 +25,0 @@ return

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc