New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@smg-automotive/i18n-pkg

Package Overview
Dependencies
Maintainers
1
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@smg-automotive/i18n-pkg - npm Package Compare versions

Comparing version 1.3.1 to 1.4.0-IN-652-a2af575dd84eb7a11a2b35e8a6d63b382f0273ce.1

dist/__mocks__/types/components/context.d.ts

16

dist/__mocks__/index.js
'use strict';
var useI18n = function () {
return {
t: function (key) { return key; },
language: 'de'
};
const useI18n = () => {
return {
t: (key) => key,
language: 'de',
};
};
var Trans = function (_a) {
var i18nKey = _a.i18nKey;
return i18nKey;
};
const Trans = ({ i18nKey }) => i18nKey;
exports.Trans = Trans;
exports.useI18n = useI18n;

@@ -112,2 +112,45 @@ 'use strict';

var isDictionary = function (value) {
return typeof value === 'object';
};
var extractSubScopeFromDictionary = function (_a) {
var scopeName = _a.scopeName, localizedDictionary = _a.localizedDictionary;
var scopeKeys = scopeName.split('.');
var subScope = localizedDictionary;
// Extract the requested (sub) dictionary
// Note: I assume there is a way of only iterating once trough
// the keys and building up the dictionary object at the same time
// It might be harder to follow and read but we might wanna revisit it
// in case we run into performance issues
scopeKeys.forEach(function (scopeKey) {
if (!subScope[scopeKey]) {
throw new Error("Dictionary scope ".concat(scopeName, " does not exist in the dictionary!"));
}
var subScopeLevel = subScope[scopeKey];
if (isDictionary(subScopeLevel)) {
subScope = subScopeLevel;
}
else {
throw new Error("You are trying to access the subScope ".concat(scopeKey, " on scope ").concat(scopeName, " which is not a dictionary!"));
}
});
// reverse the keys and build up the dictionary object
var filteredDictionary = scopeKeys
.reverse()
.reduce(function (newDictionary, subKey) {
var _a, _b;
if (Object.keys(newDictionary).length === 0) {
newDictionary = (_a = {},
_a[subKey] = subScope,
_a);
return newDictionary;
}
else {
return _b = {},
_b[subKey] = newDictionary,
_b;
}
}, {});
return filteredDictionary;
};
var filterDictionaryScopes = (function (_a) {

@@ -118,9 +161,12 @@ var _b, _c;

return _b = {}, _b[language] = dictionaries[language], _b;
var scopedDict = Object.assign.apply(Object, tslib.__spreadArray([{}], dictionaryScopes.map(function (scope) {
var _a;
if (!dictionaries[language][scope]) {
throw new Error("Dictionary scope ".concat(scope, " does not exist in the ").concat(language, " dictionary!"));
}
return _a = {}, _a[scope] = dictionaries[language][scope], _a;
}), false));
var scopedDict = dictionaryScopes.reduce(function (scopedDictionary, scopeName) {
// Note @Marine: If there is no . in the key the split will result in one entry
// in the keys array which will just extract that level
var subScope = extractSubScopeFromDictionary({
scopeName: scopeName,
localizedDictionary: dictionaries[language]
});
Object.assign(scopedDictionary, subScope);
return scopedDictionary;
}, {});
return _c = {}, _c[language] = scopedDict, _c;

@@ -127,0 +173,0 @@ });

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

import { __assign, __spreadArray } from 'tslib';
import { __assign } from 'tslib';
import { jsx } from 'react/jsx-runtime';

@@ -110,2 +110,45 @@ import { createContext, useState, useContext, useMemo, Fragment, cloneElement } from 'react';

var isDictionary = function (value) {
return typeof value === 'object';
};
var extractSubScopeFromDictionary = function (_a) {
var scopeName = _a.scopeName, localizedDictionary = _a.localizedDictionary;
var scopeKeys = scopeName.split('.');
var subScope = localizedDictionary;
// Extract the requested (sub) dictionary
// Note: I assume there is a way of only iterating once trough
// the keys and building up the dictionary object at the same time
// It might be harder to follow and read but we might wanna revisit it
// in case we run into performance issues
scopeKeys.forEach(function (scopeKey) {
if (!subScope[scopeKey]) {
throw new Error("Dictionary scope ".concat(scopeName, " does not exist in the dictionary!"));
}
var subScopeLevel = subScope[scopeKey];
if (isDictionary(subScopeLevel)) {
subScope = subScopeLevel;
}
else {
throw new Error("You are trying to access the subScope ".concat(scopeKey, " on scope ").concat(scopeName, " which is not a dictionary!"));
}
});
// reverse the keys and build up the dictionary object
var filteredDictionary = scopeKeys
.reverse()
.reduce(function (newDictionary, subKey) {
var _a, _b;
if (Object.keys(newDictionary).length === 0) {
newDictionary = (_a = {},
_a[subKey] = subScope,
_a);
return newDictionary;
}
else {
return _b = {},
_b[subKey] = newDictionary,
_b;
}
}, {});
return filteredDictionary;
};
var filterDictionaryScopes = (function (_a) {

@@ -116,9 +159,12 @@ var _b, _c;

return _b = {}, _b[language] = dictionaries[language], _b;
var scopedDict = Object.assign.apply(Object, __spreadArray([{}], dictionaryScopes.map(function (scope) {
var _a;
if (!dictionaries[language][scope]) {
throw new Error("Dictionary scope ".concat(scope, " does not exist in the ").concat(language, " dictionary!"));
}
return _a = {}, _a[scope] = dictionaries[language][scope], _a;
}), false));
var scopedDict = dictionaryScopes.reduce(function (scopedDictionary, scopeName) {
// Note @Marine: If there is no . in the key the split will result in one entry
// in the keys array which will just extract that level
var subScope = extractSubScopeFromDictionary({
scopeName: scopeName,
localizedDictionary: dictionaries[language]
});
Object.assign(scopedDictionary, subScope);
return scopedDictionary;
}, {});
return _c = {}, _c[language] = scopedDict, _c;

@@ -125,0 +171,0 @@ });

@@ -14,3 +14,3 @@ import React, { Dispatch, SetStateAction } from 'react';

type TranslateFunction = (key: string, params?: Params) => string;
type Dictionary = Record<string, any>;
type Dictionary$1 = Record<string, any>;
type OnMissing = (error: Error) => void;

@@ -25,3 +25,3 @@ interface ContextProps {

language: Language;
lngDict: Dictionary;
lngDict: Dictionary$1;
onMissingTranslation: OnMissing;

@@ -34,2 +34,6 @@ }

type DictionaryEntry = Dictionary | string;
interface Dictionary {
[key: string]: DictionaryEntry;
}
interface Options {

@@ -39,10 +43,10 @@ language: Language;

dictionaries: {
de: Record<string, unknown>;
fr: Record<string, unknown>;
it: Record<string, unknown>;
en: Record<string, unknown>;
de: Dictionary;
fr: Dictionary;
it: Dictionary;
en: Dictionary;
};
}
declare const _default: ({ language, dictionaryScopes, dictionaries }: Options) => {
[x: string]: any;
declare const _default: ({ language, dictionaryScopes, dictionaries, }: Options) => {
[key: string]: Dictionary;
};

@@ -49,0 +53,0 @@

{
"name": "@smg-automotive/i18n-pkg",
"version": "1.3.1",
"version": "1.4.0-IN-652-a2af575dd84eb7a11a2b35e8a6d63b382f0273ce.1",
"description": "A boilerplate package setup",

@@ -5,0 +5,0 @@ "main": "dist/cjs/index.js",

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