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

@wfp/ui

Package Overview
Dependencies
Maintainers
7
Versions
349
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wfp/ui - npm Package Compare versions

Comparing version 0.17.70 to 0.17.72

es/components/Unit/StringUnit.js

4

es/components/Unit/SvgUnit.js

@@ -8,4 +8,2 @@ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

var SvgUnit = function SvgUnit(value, props) {
console.log(props);
var className = props.className,

@@ -24,3 +22,3 @@ style = props.style,

style: style
}, ' ', value.extension ? value.extension.default.after + '' : '', value.after));else return React.createElement(InvalidSvg, {
}, ' ', value.output ? value.output.default.after + '' : '', value.after));else return React.createElement(InvalidSvg, {
className: props.className

@@ -27,0 +25,0 @@ });

@@ -7,3 +7,4 @@ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

import SimpleCalc from './SimpleCalc';
import SvgUnit from './SvgUnit'; // All Unit Components together in <Unit type="Unitname" />
import SvgUnit from './SvgUnit';
import StringUnit from './StringUnit'; // All Unit Components together in <Unit type="Unitname" />

@@ -36,6 +37,7 @@ export var scaleLookup = {

input = props.input,
extension = props.extension,
output = props.output,
maximumSignificantDigits = props.maximumSignificantDigits,
maximumFractionDigits = props.maximumFractionDigits,
calcOnly = props.calcOnly,
string = props.string,
svg = props.svg,

@@ -48,11 +50,11 @@ hideZero = props.hideZero; // Remove commas

value = value !== 0 && input && scaleLookup[input] ? scaleLookup[input].pow * value : value; // Extension
value = value !== 0 && input && scaleLookup[input] ? scaleLookup[input].pow * value : value; // output
var extensionCalc = extension && scaleLookup[extension] ? scaleLookup[extension] : undefined;
value = value !== 0 && extension ? value / extensionCalc.pow : value; // Convert to Locale String
var outputCalc = output && scaleLookup[output] ? scaleLookup[output] : undefined;
value = value !== 0 && output ? value / outputCalc.pow : value; // Convert to Locale String
value = value.toLocaleString('en-EN', {
minimumFractionDigits: exact ? 0 : maximumSignificantDigits ? maximumSignificantDigits : extensionCalc && extensionCalc.defaultmaximumFractionDigits ? extensionCalc.defaultmaximumFractionDigits : 2,
minimumFractionDigits: exact ? 0 : maximumSignificantDigits ? maximumSignificantDigits : outputCalc && outputCalc.defaultmaximumFractionDigits ? outputCalc.defaultmaximumFractionDigits : 2,
maximumSignificantDigits: maximumSignificantDigits,
maximumFractionDigits: exact ? 0 : value <= 0.5 ? 5 : maximumFractionDigits ? maximumFractionDigits : extensionCalc && extensionCalc.defaultmaximumFractionDigits ? extensionCalc.defaultmaximumFractionDigits : 2
maximumFractionDigits: exact ? 0 : value <= 0.5 ? 5 : maximumFractionDigits ? maximumFractionDigits : outputCalc && outputCalc.defaultmaximumFractionDigits ? outputCalc.defaultmaximumFractionDigits : 2
});

@@ -63,3 +65,3 @@ var calcObject = {

after: after,
extension: extensionCalc
output: outputCalc
};

@@ -72,3 +74,3 @@ var className = props.className;

if ((!value || value === 'NaN' || parseFloat(value) === 0) && hideZero) return false;else if (calcOnly) return calcObject;else if (svg) return SvgUnit(calcObject, props);else if (value !== false) return React.createElement("span", {
if ((!value || value === 'NaN' || parseFloat(value) === 0) && hideZero) return false;else if (calcOnly) return calcObject;else if (svg) return SvgUnit(calcObject, props);else if (string) return StringUnit(calcObject, props);else if (value !== false) return React.createElement("span", {
className: className

@@ -83,2 +85,3 @@ }, value);else return React.createElement(Invalid, {

from = props.from,
string = props.string,
svg = props.svg,

@@ -109,5 +112,5 @@ hideZero = props.hideZero,

after: after,
extension: undefined
output: undefined
};
if ((!value || value === 'NaN' || parseFloat(value) === 0) && hideZero) return false;else if (calcOnly) return calcObject;else if (svg) return SvgUnit(calcObject, props);else if (value !== false) return React.createElement("span", {
if ((!value || value === 'NaN' || parseFloat(value) === 0) && hideZero) return false;else if (calcOnly) return calcObject;else if (svg) return SvgUnit(calcObject, props);else if (string) return StringUnit(calcObject, props);else if (value !== false) return React.createElement("span", {
className: props.className

@@ -137,3 +140,4 @@ }, value);else return React.createElement(Invalid, {

var className = props.className,
extension = props.extension,
output = props.output,
string = props.string,
textAnchor = props.textAnchor,

@@ -147,3 +151,3 @@ hideZero = props.hideZero,

var unitClassName = props.type ? 'wfp--unit--' + props.type.toLowerCase() : '';
var extensionClassName = extension && scaleLookup[extension] ? 'wfp--unit--' + extension : '';
var outputClassName = output && scaleLookup[output] ? 'wfp--unit--' + output : '';
var setupClassName = setup ? 'wfp--unit--' + setup : '';

@@ -153,4 +157,8 @@ var classNameCalc = 'wfp--unit ' + className + ' ' + unitClassName + ' ' +

' ' +*/
extensionClassName + ' ' + setupClassName;
outputClassName + ' ' + setupClassName;
if (string) {
return Unit(props);
}
if (Unit === undefined) {

@@ -157,0 +165,0 @@ console.warn("The unit \"".concat(type, "\" is undefined"));

@@ -17,4 +17,2 @@ "use strict";

var SvgUnit = function SvgUnit(value, props) {
console.log(props);
var className = props.className,

@@ -33,3 +31,3 @@ style = props.style,

style: style
}, ' ', value.extension ? value.extension.default.after + '' : '', value.after));else return _react.default.createElement(InvalidSvg, {
}, ' ', value.output ? value.output.default.after + '' : '', value.after));else return _react.default.createElement(InvalidSvg, {
className: props.className

@@ -36,0 +34,0 @@ });

@@ -18,2 +18,4 @@ "use strict";

var _StringUnit = _interopRequireDefault(require("./StringUnit"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -52,6 +54,7 @@

input = props.input,
extension = props.extension,
output = props.output,
maximumSignificantDigits = props.maximumSignificantDigits,
maximumFractionDigits = props.maximumFractionDigits,
calcOnly = props.calcOnly,
string = props.string,
svg = props.svg,

@@ -64,11 +67,11 @@ hideZero = props.hideZero; // Remove commas

value = value !== 0 && input && scaleLookup[input] ? scaleLookup[input].pow * value : value; // Extension
value = value !== 0 && input && scaleLookup[input] ? scaleLookup[input].pow * value : value; // output
var extensionCalc = extension && scaleLookup[extension] ? scaleLookup[extension] : undefined;
value = value !== 0 && extension ? value / extensionCalc.pow : value; // Convert to Locale String
var outputCalc = output && scaleLookup[output] ? scaleLookup[output] : undefined;
value = value !== 0 && output ? value / outputCalc.pow : value; // Convert to Locale String
value = value.toLocaleString('en-EN', {
minimumFractionDigits: exact ? 0 : maximumSignificantDigits ? maximumSignificantDigits : extensionCalc && extensionCalc.defaultmaximumFractionDigits ? extensionCalc.defaultmaximumFractionDigits : 2,
minimumFractionDigits: exact ? 0 : maximumSignificantDigits ? maximumSignificantDigits : outputCalc && outputCalc.defaultmaximumFractionDigits ? outputCalc.defaultmaximumFractionDigits : 2,
maximumSignificantDigits: maximumSignificantDigits,
maximumFractionDigits: exact ? 0 : value <= 0.5 ? 5 : maximumFractionDigits ? maximumFractionDigits : extensionCalc && extensionCalc.defaultmaximumFractionDigits ? extensionCalc.defaultmaximumFractionDigits : 2
maximumFractionDigits: exact ? 0 : value <= 0.5 ? 5 : maximumFractionDigits ? maximumFractionDigits : outputCalc && outputCalc.defaultmaximumFractionDigits ? outputCalc.defaultmaximumFractionDigits : 2
});

@@ -79,3 +82,3 @@ var calcObject = {

after: after,
extension: extensionCalc
output: outputCalc
};

@@ -88,3 +91,3 @@ var className = props.className;

if ((!value || value === 'NaN' || parseFloat(value) === 0) && hideZero) return false;else if (calcOnly) return calcObject;else if (svg) return (0, _SvgUnit.default)(calcObject, props);else if (value !== false) return _react.default.createElement("span", {
if ((!value || value === 'NaN' || parseFloat(value) === 0) && hideZero) return false;else if (calcOnly) return calcObject;else if (svg) return (0, _SvgUnit.default)(calcObject, props);else if (string) return (0, _StringUnit.default)(calcObject, props);else if (value !== false) return _react.default.createElement("span", {
className: className

@@ -102,2 +105,3 @@ }, value);else return _react.default.createElement(Invalid, {

from = props.from,
string = props.string,
svg = props.svg,

@@ -128,5 +132,5 @@ hideZero = props.hideZero,

after: after,
extension: undefined
output: undefined
};
if ((!value || value === 'NaN' || parseFloat(value) === 0) && hideZero) return false;else if (calcOnly) return calcObject;else if (svg) return (0, _SvgUnit.default)(calcObject, props);else if (value !== false) return _react.default.createElement("span", {
if ((!value || value === 'NaN' || parseFloat(value) === 0) && hideZero) return false;else if (calcOnly) return calcObject;else if (svg) return (0, _SvgUnit.default)(calcObject, props);else if (string) return (0, _StringUnit.default)(calcObject, props);else if (value !== false) return _react.default.createElement("span", {
className: props.className

@@ -158,3 +162,4 @@ }, value);else return _react.default.createElement(Invalid, {

var className = props.className,
extension = props.extension,
output = props.output,
string = props.string,
textAnchor = props.textAnchor,

@@ -168,3 +173,3 @@ hideZero = props.hideZero,

var unitClassName = props.type ? 'wfp--unit--' + props.type.toLowerCase() : '';
var extensionClassName = extension && scaleLookup[extension] ? 'wfp--unit--' + extension : '';
var outputClassName = output && scaleLookup[output] ? 'wfp--unit--' + output : '';
var setupClassName = setup ? 'wfp--unit--' + setup : '';

@@ -174,4 +179,8 @@ var classNameCalc = 'wfp--unit ' + className + ' ' + unitClassName + ' ' +

' ' +*/
extensionClassName + ' ' + setupClassName;
outputClassName + ' ' + setupClassName;
if (string) {
return Unit(props);
}
if (Unit === undefined) {

@@ -178,0 +187,0 @@ console.warn("The unit \"".concat(type, "\" is undefined"));

{
"name": "@wfp/ui",
"version": "0.17.70",
"version": "0.17.72",
"description": "WFP UI-Kit Next",

@@ -5,0 +5,0 @@ "license": "Apache-2",

The Unit component method returns a component with a language and unit sensitive representation of this number based on the [Reference on developer.mozilla.org](http://cdn.wfp.org/guides/editorial/content/numbers-and-units).
```js
~~~js
import { Unit } from '@wfp/ui';
```
~~~
```js
~~~js
<Unit
type="Usd"
setup={{
"extension":"million",
"output":"million",
"input":"thousand",

@@ -18,18 +19,20 @@ "showZero"

</Unit>
```
~~~
| Setting | Default | Options | Role |
| -------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------- |
| children | `undefined` | `string` | The value which should be displayed |
| type | `None` | `Countries` `Usd` `Partners` `People` `Beneficiaries` `Households` `Months` `Level` `Mt` `None` `Num` `Percentage` `YearMonth` `false` | Select a unit type |
| setup | `undefined` | `object` | Custom settings related to the selected unit type |
|Setting|Default|Options|Role|
|--- |--- |--- |--- |
|children|`undefined`|`string` |The value which should be displayed|
|type|`None`|`Countries` `Usd` `Partners` `People` `Beneficiaries` `Households` `Months` `Level` `Mt` `None` `Num` `Percentage` `YearMonth` `false`|Select a unit type|
|setup|`undefined`|`object`|Custom settings related to the selected unit type|
## Setup details
| Setting | Default | Options | Role |
| ------------------------ | ----------- | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| from | `undefined` | `string` `float` | only used for type `Percentage` will divide `value`/`from` |
| minimumFractionDigits | `undefined` | `0-20` | The minimum number of fraction digits to use. Possible values are from 0 to 20.Only used on numeric types [Reference on developer.mozilla.org](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString) |
| maximumSignificantDigits | `undefined` | `1-21` | The maximum number of significant digits to use. Possible values are from 1 to 21; the default is `minimumSignificantDigits`.[Reference on developer.mozilla.org](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString) |
| maximumFractionDigits | `undefined` | `1-21` | The maximum number of significant digits to use. Possible values are from 1 to 21; the default is `minimumSignificantDigits`. |
| hideEmpty | `false` | `boolean` | Hide the Unit if it's value is zero. |
|Setting|Default|Options|Role|
|--- |--- |--- |--- |
|from|`undefined`|`string` `float`| only used for type `Percentage` will divide `value`/`from`
|minimumFractionDigits|`undefined`|`0-20` | The minimum number of fraction digits to use. Possible values are from 0 to 20.Only used on numeric types [Reference on developer.mozilla.org](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString)
|maximumSignificantDigits|`undefined`|`1-21` | The maximum number of significant digits to use. Possible values are from 1 to 21; the default is `minimumSignificantDigits`.[Reference on developer.mozilla.org](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString)
|maximumFractionDigits|`undefined`|`1-21` | The maximum number of significant digits to use. Possible values are from 1 to 21; the default is `minimumSignificantDigits`.
|hideEmpty|`false`|`boolean` | Hide the Unit if it's value is zero.
import React from 'react';
const SvgUnit = (value, props) => {
console.log(props);
const { className, style, type, ...other } = props;

@@ -14,3 +13,3 @@

{' '}
{value.extension ? value.extension.default.after + '' : ''}
{value.output ? value.output.default.after + '' : ''}
{value.after}

@@ -17,0 +16,0 @@ </tspan>

@@ -22,2 +22,3 @@ import React from 'react';

import SvgUnit from './SvgUnit';
import StringUnit from './StringUnit';
// All Unit Components together in <Unit type="Unitname" />

@@ -47,6 +48,7 @@

input,
extension,
output,
maximumSignificantDigits,
maximumFractionDigits,
calcOnly,
string,
svg,

@@ -56,2 +58,3 @@ hideZero,

// Remove commas

@@ -70,7 +73,7 @@ var value =

// Extension
const extensionCalc =
extension && scaleLookup[extension] ? scaleLookup[extension] : undefined;
// output
const outputCalc =
output && scaleLookup[output] ? scaleLookup[output] : undefined;
value = value !== 0 && extension ? value / extensionCalc.pow : value;
value = value !== 0 && output ? value / outputCalc.pow : value;

@@ -83,4 +86,4 @@ // Convert to Locale String

? maximumSignificantDigits
: extensionCalc && extensionCalc.defaultmaximumFractionDigits
? extensionCalc.defaultmaximumFractionDigits
: outputCalc && outputCalc.defaultmaximumFractionDigits
? outputCalc.defaultmaximumFractionDigits
: 2,

@@ -94,4 +97,4 @@ maximumSignificantDigits: maximumSignificantDigits,

? maximumFractionDigits
: extensionCalc && extensionCalc.defaultmaximumFractionDigits
? extensionCalc.defaultmaximumFractionDigits
: outputCalc && outputCalc.defaultmaximumFractionDigits
? outputCalc.defaultmaximumFractionDigits
: 2,

@@ -104,3 +107,3 @@ });

after: after,
extension: extensionCalc,
output: outputCalc,
};

@@ -117,2 +120,3 @@

else if (svg) return SvgUnit(calcObject, props);
else if (string) return StringUnit(calcObject, props);
else if (value !== false) return <span className={className}>{value}</span>;

@@ -127,2 +131,3 @@ else return <Invalid className={props.className} />;

from,
string,
svg,

@@ -161,3 +166,3 @@ hideZero,

after: after,
extension: undefined,
output: undefined,
};

@@ -168,2 +173,3 @@ if ((!value || value === 'NaN' || parseFloat(value) === 0) && hideZero)

else if (svg) return SvgUnit(calcObject, props);
else if (string) return StringUnit(calcObject, props);
else if (value !== false)

@@ -192,3 +198,3 @@ return <span className={props.className}>{value}</span>;

const Unit = props => {
const { className, extension, textAnchor, hideZero, setup } = props;
const { className, output, string, textAnchor, hideZero, setup } = props;
const type = props.type ? props.type : 'None';

@@ -202,4 +208,4 @@ const Unit = components[type];

const extensionClassName =
extension && scaleLookup[extension] ? 'wfp--unit--' + extension : '';
const outputClassName =
output && scaleLookup[output] ? 'wfp--unit--' + output : '';
const setupClassName = setup ? 'wfp--unit--' + setup : '';

@@ -214,6 +220,10 @@ const classNameCalc =

' ' +*/
extensionClassName +
outputClassName +
' ' +
setupClassName;
if (string) {
return (Unit(props));
}
if (Unit === undefined) {

@@ -242,5 +252,5 @@ console.warn(`The unit "${type}" is undefined`);

Unit.defaultProps = {
type: 'None',
type: 'None'
};
export default Unit;

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

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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