Socket
Socket
Sign inDemoInstall

@18f/identity-components

Package Overview
Dependencies
8
Maintainers
11
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 2.0.0-beta0.1

120

dist/index.js
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_179142b8__ from "react/jsx-runtime";
import * as __WEBPACK_EXTERNAL_MODULE__18f_identity_i18n_6b4e2544__ from "@18f/identity-i18n";
import * as __WEBPACK_EXTERNAL_MODULE_react_dom_7dac9eee__ from "react-dom";

@@ -92,105 +93,6 @@ import * as __WEBPACK_EXTERNAL_MODULE_focus_trap_4348fbe4__ from "focus-trap";

/* harmony default export */ const alert_0 = (/*#__PURE__*/(0,external_react_namespaceObject.forwardRef)(Alert));
;// CONCATENATED MODULE: ../i18n/index.ts
const hasOwn = (object, key) => Object.prototype.hasOwnProperty.call(object, key);
/**
* Returns the pluralization object key corresponding to the given number.
*
* @param count Count.
*
* @return Pluralization key.
*/
const getPluralizationKey = count => count === 1 ? 'one' : 'other';
/**
* Returns an entry from locale data.
*
* @param entry Locale data.
* @param count Pluralization count, if applicable.
*
* @return Entry string or object.
*/
const getEntry = (strings, key) => hasOwn(strings, key) ? strings[key] : key;
/**
* Returns true if the given entry is a pluralization entry, or false otherwise.
*
* @param entry Entry to test.
*
* @return Whether entry is a pluralization entry.
*/
const isPluralizedEntry = entry => typeof entry === 'object' && 'one' in entry;
/**
* Returns true if the given entry is a string entry, or false otherwise.
*
* @param entry Entry to test.
*
* @return Whether entry is a string entry.
*/
const isStringEntry = entry => typeof entry === 'string';
/**
* Returns the resulting string from the given entry, incorporating pluralization if necessary.
*
* @param entry Entry string or object.
* @param count Pluralization count, if applicable.
*
* @return Entry string.
*/
function getString(entry, count) {
if (isPluralizedEntry(entry)) {
if (typeof count !== 'number') {
throw new TypeError('Expected count for PluralizedEntry');
}
return entry[getPluralizationKey(count)];
}
return entry;
}
/**
* Returns string with variable substitution.
*
* @param string Original string.
* @param variables Variables to replace.
*
* @return String with variables substituted.
*/
const replaceVariables = (string, variables) => string.replace(/%{(\w+)}/g, (match, key) => hasOwn(variables, key) ? variables[key] : match);
class I18n {
constructor() {
let {
strings
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
this.strings = Object.assign(Object.create(null), strings);
this.t = this.t.bind(this);
}
/**
* Returns the translated string by the given key.
*
* @param keyOrKeys Key or keys to retrieve.
* @param variables Variables to substitute in string.
*
* @return Translated string.
*/
t(keyOrKeys) {
let variables = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
const isSingular = !Array.isArray(keyOrKeys);
const keys = isSingular ? [keyOrKeys] : keyOrKeys;
const entries = keys.map(key => getEntry(this.strings, key));
const strings = entries.map(entry => isPluralizedEntry(entry) ? getString(entry, variables?.count) : entry).map(entry => isStringEntry(entry) ? replaceVariables(entry, variables) : entry);
return isSingular ? strings[0] : strings.flat();
}
}
// eslint-disable-next-line no-underscore-dangle
const i18n = new I18n({
strings: globalThis._locale_data
});
const {
t
} = i18n;
;// CONCATENATED MODULE: external "@18f/identity-i18n"
var identity_i18n_x = y => { var x = {}; __webpack_require__.d(x, y); return x; }
var identity_i18n_y = x => () => x
const identity_i18n_namespaceObject = identity_i18n_x({ ["i18n"]: () => __WEBPACK_EXTERNAL_MODULE__18f_identity_i18n_6b4e2544__.i18n, ["t"]: () => __WEBPACK_EXTERNAL_MODULE__18f_identity_i18n_6b4e2544__.t });
;// CONCATENATED MODULE: ./link.tsx

@@ -232,3 +134,3 @@

className: "usa-sr-only",
children: t('links.new_tab')
children: (0,identity_i18n_namespaceObject.t)('links.new_tab')
})]

@@ -428,3 +330,3 @@ });

const I18nContext = /*#__PURE__*/(0,external_react_namespaceObject.createContext)(i18n);
const I18nContext = /*#__PURE__*/(0,external_react_namespaceObject.createContext)(identity_i18n_namespaceObject.i18n);
I18nContext.displayName = 'I18nContext';

@@ -977,6 +879,6 @@ /* harmony default export */ const i18n_context = (I18nContext);

const STATUS_ALT = {
error: t('image_description.error'),
question: t('image_description.info_question'),
warning: t('image_description.warning'),
lock: t('image_description.error_lock')
error: (0,identity_i18n_namespaceObject.t)('image_description.error'),
question: (0,identity_i18n_namespaceObject.t)('image_description.info_question'),
warning: (0,identity_i18n_namespaceObject.t)('image_description.warning'),
lock: (0,identity_i18n_namespaceObject.t)('image_description.error_lock')
};

@@ -983,0 +885,0 @@ function StatusPage(_ref) {

5

package.json
{
"name": "@18f/identity-components",
"version": "1.0.0",
"version": "2.0.0-beta0.1",
"type": "module",

@@ -28,3 +28,4 @@ "private": false,

"react": ">=17",
"react-dom": ">=17"
"react-dom": ">=17",
"@18f/identity-i18n": ">=1"
},

@@ -31,0 +32,0 @@ "repository": {

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc