How to use the @phensley/decimal.DecimalConstants.TWO function in @phensley/decimal

To help you get started, we’ve selected a few @phensley/decimal examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github phensley / cldr-engine / packages / messageformat / src / evaluation / evaluation.ts View on Github external
export type MessageFormatFunc =
  (args: MessageArg[], options: string[]) => string;

export type MessageFormatFuncMap = { [name: string]: MessageFormatFunc };

const get = (key: number | string, args: MessageArgs): MessageArg => {
  const res: MessageArg = args.named[key];
  return res !== undefined ? res : (typeof key === 'number' ? args.positional[key] : undefined);
};

// Save a bit of processing of common exact matches
const DECIMAL_EXACT: { [n: string]: Decimal } = {
  0: DecimalConstants.ZERO,
  1: DecimalConstants.ONE,
  2: DecimalConstants.TWO
};

/**
 * Evaluates a message format against a set of arguments, producing a string.
 */
export class MessageEngine {

  private buf: string = '';

  constructor(
    private plurals: PluralRules,
    private formatters: MessageFormatFuncMap,
    private code: MessageCode) { }

  evaluate(positional: MessageArg[], named: MessageNamedArgs = {}): string {
    return this._evaluate(this.code, { positional, named });
github phensley / cldr-engine / packages / cldr-core / src / internals / datefields / internal.ts View on Github external
const iszero = n.compare(DecimalConstants.ZERO) === 0;
    let res = '';

    if (iszero) {
      if (options.alwaysNow || !options.numericOnly) {
        res = format.current.get(bundle, field);
      }

    } else if (!options.numericOnly) {
      switch (field) {
        case 'hour':
        case 'minute':
        case 'second':
          break;
        default:
          if (n.compare(DecimalConstants.TWO) === 0) {
            const p = negative ? format.previous2.get(bundle, field) : format.next2.get(bundle, field);
            if (p !== '') {
              res = p;
            }
            // Fall through
          } else if (n.compare(DecimalConstants.ONE) === 0) {
            res = negative ? format.previous.get(bundle, field) : format.next.get(bundle, field);
          }
          break;
      }
    }

    // If we output anything above, return it
    if (res) {
      if (options.context) {
        res = this.internals.general.contextTransform(res, transform,