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

@phensley/cldr-core

Package Overview
Dependencies
Maintainers
1
Versions
242
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@phensley/cldr-core - npm Package Compare versions

Comparing version 0.2.3 to 0.2.4

9

lib/engine/numbers/context.d.ts

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

import { NumberFormatModeType, NumberFormatOptions, RoundingModeType } from './options';
import { NumberFormatOptions, RoundingModeType } from './options';
import { Decimal } from '../../types/numbers';

@@ -11,3 +11,2 @@ import { NumberPattern } from '../../parsing/patterns/number';

roundingMode: RoundingModeType;
formatMode: NumberFormatModeType;
useSignificant: boolean;

@@ -20,3 +19,3 @@ minInt: number;

currencyDigits: number;
constructor(options: NumberFormatOptions, defaultFormatMode: NumberFormatModeType, currencyDigits?: number);
constructor(options: NumberFormatOptions, currencyDigits?: number);
/**

@@ -29,3 +28,3 @@ * Set a pattern.

*/
setCompact(pattern: NumberPattern, integerDigits: number, divisor: number): void;
setCompact(pattern: NumberPattern, integerDigits: number, divisor: number, maxFracDigits?: number): void;
/**

@@ -38,3 +37,3 @@ * Adjust the scale of the number using the resolved parameters.

*/
private _setPattern(pattern, maxSigDigits, minSigDigits);
private _setPattern(pattern, maxSigDigits, minSigDigits, maxFracDigits);
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var options_1 = require("./options");
/**

@@ -9,3 +8,3 @@ * Provides a context to set number formatting parameters, combining user-supplied

var NumberContext = /** @class */ (function () {
function NumberContext(options, defaultFormatMode, currencyDigits) {
function NumberContext(options, currencyDigits) {
if (currencyDigits === void 0) { currencyDigits = -1; }

@@ -17,6 +16,5 @@ this.maxSig = -1;

this.roundingMode = options.round || 'half-even';
this.formatMode = options.formatMode === undefined ? defaultFormatMode : options.formatMode;
this.currencyDigits = currencyDigits;
this.useSignificant = this.formatMode === options_1.NumberFormatMode.SIGNIFICANT ||
this.formatMode === options_1.NumberFormatMode.SIGNIFICANT_MAXFRAC;
this.useSignificant = options.minimumSignificantDigits !== undefined ||
options.maximumSignificantDigits !== undefined;
}

@@ -27,3 +25,3 @@ /**

NumberContext.prototype.setPattern = function (pattern) {
this._setPattern(pattern, -1, -1);
this._setPattern(pattern, -1, -1, -1);
};

@@ -33,9 +31,6 @@ /**

*/
NumberContext.prototype.setCompact = function (pattern, integerDigits, divisor) {
var maxSigDigits = Math.max(pattern.minInt, integerDigits) + 1;
var minSigDigits = 1;
if (divisor === 0) {
maxSigDigits = integerDigits + 1;
}
this._setPattern(pattern, maxSigDigits, minSigDigits);
NumberContext.prototype.setCompact = function (pattern, integerDigits, divisor, maxFracDigits) {
if (maxFracDigits === void 0) { maxFracDigits = -1; }
var maxSigDigits = Math.max(pattern.minInt, integerDigits);
this._setPattern(pattern, maxSigDigits, 1, maxFracDigits);
};

@@ -47,11 +42,7 @@ /**

if (this.useSignificant && this.maxSig > 0 && this.maxSig > 0) {
// Scale the number to have at most the maximum significant digits.
if (n.precision() > this.maxSig) {
// Scale the number to have at most the maximum significant digits.
var scale = this.maxSig - n.precision() + n.scale();
n = n.setScale(scale, this.roundingMode);
}
// Ensure we don't exceed the maximum number of fraction digits allowed.
if (this.formatMode === options_1.NumberFormatMode.SIGNIFICANT_MAXFRAC && this.maxFrac < n.scale()) {
n = n.setScale(this.maxFrac, this.roundingMode);
}
// Ensure that one less digit is emitted if the number is exactly zero.

@@ -86,24 +77,37 @@ n = n.stripTrailingZeros();

*/
NumberContext.prototype._setPattern = function (pattern, maxSigDigits, minSigDigits) {
NumberContext.prototype._setPattern = function (pattern, maxSigDigits, minSigDigits, maxFracDigits) {
var o = this.options;
this.minInt = orDefault(o.minimumIntegerDigits, pattern.minInt);
this.minFrac = this.currencyDigits === -1 ? pattern.minFrac : this.currencyDigits;
this.maxFrac = this.currencyDigits === -1 ? pattern.maxFrac : this.currencyDigits;
this.maxFrac = orDefault(o.maximumFractionDigits, this.maxFrac);
this.minFrac = this.currencyDigits === -1 ? pattern.minFrac : this.currencyDigits;
this.minFrac = orDefault(o.minimumFractionDigits, this.minFrac);
if (this.minFrac !== -1 && this.minFrac > this.maxFrac) {
this.maxFrac = this.minFrac;
var minFrac = o.minimumFractionDigits;
var maxFrac = o.maximumFractionDigits;
if (minFrac === undefined && maxFrac === undefined && maxFracDigits > -1) {
maxFrac = maxFracDigits;
}
if (this.maxFrac !== -1 && this.maxFrac < this.minFrac) {
this.minFrac = this.maxFrac;
if (maxFrac !== undefined && maxFrac > -1) {
this.maxFrac = maxFrac;
}
if (minFrac !== undefined && minFrac > -1) {
this.minFrac = maxFrac !== undefined && maxFrac > -1 ? (maxFrac < minFrac ? maxFrac : minFrac) : minFrac;
if (this.minFrac > this.maxFrac) {
this.maxFrac = this.minFrac;
}
}
if (maxFrac !== undefined && maxFrac > -1) {
if (this.maxFrac < this.minFrac || this.minFrac === -1) {
this.minFrac = this.maxFrac;
}
}
if (this.useSignificant) {
this.maxSig = orDefault(o.maximumSignificantDigits, maxSigDigits);
this.minSig = orDefault(o.minimumSignificantDigits, minSigDigits);
if (this.minSig !== -1 && this.minSig > this.maxSig) {
this.maxSig = this.minSig;
var minSig = orDefault(o.minimumSignificantDigits, minSigDigits);
var maxSig = orDefault(o.maximumSignificantDigits, maxSigDigits);
if (minSig !== -1 && minSig > maxSig) {
maxSig = minSig;
}
if (this.maxSig !== -1 && this.maxSig < this.minSig) {
this.minSig = this.maxSig;
if (maxSig !== -1 && maxSig < minSig) {
minSig = maxSig;
}
this.minSig = minSig === -1 ? maxSig : minSig;
this.maxSig = maxSig === -1 ? minSig : maxSig;
}

@@ -110,0 +114,0 @@ else {

@@ -5,3 +5,2 @@ "use strict";

var context_1 = require("./context");
var options_1 = require("./options");
var number_1 = require("../../parsing/patterns/number");

@@ -37,3 +36,3 @@ var cache_1 = require("../../utils/cache");

: this.decimalFormats.long.decimalFormat;
var ctx = new context_1.NumberContext(options, options_1.NumberFormatMode.SIGNIFICANT);
var ctx = new context_1.NumberContext(options);
// Adjust the number using the compact pattern and divisor.

@@ -69,3 +68,3 @@ var _a = this.setupCompact(bundle, n, ctx, standardRaw, patternImpl, divisorImpl), q2 = _a[0], ndigits = _a[1];

// Adjust number using pattern and options, then render.
var ctx = new context_1.NumberContext(options, options_1.NumberFormatMode.DEFAULT, -1);
var ctx = new context_1.NumberContext(options, -1);
ctx.setPattern(pattern);

@@ -82,3 +81,3 @@ n = ctx.adjust(n);

// Adjust number using pattern and options, then render.
var ctx = new context_1.NumberContext(options, options_1.NumberFormatMode.DEFAULT, -1);
var ctx = new context_1.NumberContext(options, -1);
ctx.setPattern(pattern);

@@ -105,3 +104,3 @@ n = ctx.adjust(n);

// Adjust number using pattern and options, then render.
var ctx = new context_1.NumberContext(options, options_1.NumberFormatMode.DEFAULT, fractions.digits);
var ctx = new context_1.NumberContext(options, fractions.digits);
ctx.setPattern(pattern);

@@ -125,3 +124,3 @@ n = ctx.adjust(n);

var patternImpl = this.currencyFormats.short.standard;
var ctx = new context_1.NumberContext(options, options_1.NumberFormatMode.SIGNIFICANT_MAXFRAC, fractions.digits);
var ctx = new context_1.NumberContext(options, fractions.digits);
var symbol = this.Currencies(code).symbol(bundle, width);

@@ -147,3 +146,3 @@ // Adjust the number using the compact pattern and divisor.

// Adjust number using pattern and options, then render.
var ctx = new context_1.NumberContext(options, options_1.NumberFormatMode.DEFAULT, fractions.digits);
var ctx = new context_1.NumberContext(options, fractions.digits);
ctx.setPattern(pattern);

@@ -174,4 +173,6 @@ n = ctx.adjust(n);

// Select the correct divisor based on the number of integer digits in n.
var negative = n.isNegative();
var ndigits = n.integerDigits();
var ndivisor = divisorImpl(bundle, ndigits);
var fracDigits = ctx.useSignificant ? -1 : 0;
// Move the decimal point of n, producing q1. We always strip trailing

@@ -181,3 +182,3 @@ // zeros on compact patterns.

if (ndivisor > 0) {
q1 = q1.movePoint(-ndivisor).stripTrailingZeros();
q1 = q1.movePoint(-ndivisor);
}

@@ -187,6 +188,6 @@ // Select the initial compact pattern based on the integer digits of n.

var raw = patternImpl(bundle, ndigits, cldr_schema_1.Plural.OTHER) || standardRaw;
var pattern = this.getNumberPattern(raw, false);
var pattern = this.getNumberPattern(raw, negative);
// Adjust q1 using the compact pattern's parameters, to produce q2.
var q1digits = q1.integerDigits();
ctx.setCompact(pattern, q1digits, ndivisor);
ctx.setCompact(pattern, q1digits, ndivisor, fracDigits);
var q2 = ctx.adjust(q1);

@@ -200,3 +201,3 @@ var q2digits = q2.integerDigits();

raw = patternImpl(bundle, ndigits, cldr_schema_1.Plural.OTHER) || standardRaw;
pattern = this.getNumberPattern(raw, false);
pattern = this.getNumberPattern(raw, negative);
// If divisor changed we need to divide and adjust again. We don't divide,

@@ -206,4 +207,9 @@ // we just move the decimal point, since our Decimal type uses a radix that

if (divisor > ndivisor) {
q1 = n.movePoint(-divisor).stripTrailingZeros();
ctx.setCompact(pattern, q1.integerDigits(), divisor);
// We shift right before we move the decimal point. This triggers rounding
// of the number at its correct scale. Otherwise we would end up with
// 999,999 becoming 0.999999 and half-even rounding truncating the
// number to '0M' instead of '1M'.
q1 = n.shiftright(divisor);
q1 = q1.movePoint(-divisor);
ctx.setCompact(pattern, q1.integerDigits(), divisor, fracDigits);
q2 = ctx.adjust(q1);

@@ -210,0 +216,0 @@ }

@@ -10,11 +10,4 @@ import { CurrencySpacing, NumberSymbols } from '@phensley/cldr-schema';

}
export declare enum NumberFormatMode {
DEFAULT = "default",
SIGNIFICANT = "significant",
SIGNIFICANT_MAXFRAC = "significant-maxfrac",
}
export declare type NumberFormatModeType = 'default' | 'significant' | 'significant-maxfrac';
export declare type RoundingModeType = 'up' | 'down' | 'ceiling' | 'floor' | 'half-up' | 'half-down' | 'half-even' | '05up' | 'truncate';
export interface NumberFormatOptions {
formatMode?: NumberFormatModeType;
round?: RoundingModeType;

@@ -21,0 +14,0 @@ group?: boolean;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var NumberFormatMode;
(function (NumberFormatMode) {
NumberFormatMode["DEFAULT"] = "default";
NumberFormatMode["SIGNIFICANT"] = "significant";
NumberFormatMode["SIGNIFICANT_MAXFRAC"] = "significant-maxfrac";
})(NumberFormatMode = exports.NumberFormatMode || (exports.NumberFormatMode = {}));
var CurrencySymbolWidth;

@@ -10,0 +4,0 @@ (function (CurrencySymbolWidth) {

@@ -7,3 +7,4 @@ export * from './engine';

export { LRU } from './utils/lru';
export { AvailableFormatType, CurrencyType, FieldWidthType, FormatWidthType } from '@phensley/cldr-schema';
import * as encoding from './resource/encoding';
export { encoding };
{
"name": "@phensley/cldr-core",
"version": "0.2.3",
"version": "0.2.4",
"description": "Core library for @phensley/cldr",

@@ -30,3 +30,3 @@ "main": "lib/index.js",

"dependencies": {
"@phensley/cldr-schema": "^0.2.3"
"@phensley/cldr-schema": "^0.2.4"
},

@@ -33,0 +33,0 @@ "devDependencies": {

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 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