How to use @phensley/cldr-utils - 10 common examples

To help you get started, we’ve selected a few @phensley/cldr-utils 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 / cldr-core / src / internals / calendars / patterns.ts View on Github external
constructor(
    protected readonly bundle: Bundle,
    protected readonly internals: Internals,
    private readonly schema: CalendarSchema,
    readonly cacheSize: number = 50
  ) {
    this.language = bundle.language();
    this.region = bundle.region();
    this.skeletonParser = this.buildSkeletonParser();
    this.skeletonRequestCache = new LRU(cacheSize);
    this.intervalRequestCache = new LRU(cacheSize);
    this.namesCache = new LRU(cacheSize);

    // Fetch this locale's main formats
    this.dateFormats = schema.dateFormats.mapping(bundle);
    this.timeFormats = schema.timeFormats.mapping(bundle);
    this.wrapperFormats = schema.dateTimeFormats.mapping(bundle);

    // Fetch skeletons and build best-fit matchers
    this.rawAvailableFormats = this.schema.availableFormats.mapping(bundle);
    this.rawPluralFormats = this.schema.pluralFormats.mapping(bundle);
    this.rawIntervalFormats = this.schema.intervalFormats.mapping(bundle);
    this.buildAvailableMatcher();
    this.buildIntervalMatcher();

    this.intervalFallback = this.schema.intervalFormatFallback.get(bundle);
  }
github phensley / cldr-engine / packages / cldr-core / src / internals / calendars / patterns.ts View on Github external
constructor(
    protected readonly bundle: Bundle,
    protected readonly internals: Internals,
    private readonly schema: CalendarSchema,
    readonly cacheSize: number = 50
  ) {
    this.language = bundle.language();
    this.region = bundle.region();
    this.skeletonParser = this.buildSkeletonParser();
    this.skeletonRequestCache = new LRU(cacheSize);
    this.intervalRequestCache = new LRU(cacheSize);
    this.namesCache = new LRU(cacheSize);

    // Fetch this locale's main formats
    this.dateFormats = schema.dateFormats.mapping(bundle);
    this.timeFormats = schema.timeFormats.mapping(bundle);
    this.wrapperFormats = schema.dateTimeFormats.mapping(bundle);

    // Fetch skeletons and build best-fit matchers
    this.rawAvailableFormats = this.schema.availableFormats.mapping(bundle);
    this.rawPluralFormats = this.schema.pluralFormats.mapping(bundle);
    this.rawIntervalFormats = this.schema.intervalFormats.mapping(bundle);
    this.buildAvailableMatcher();
    this.buildIntervalMatcher();

    this.intervalFallback = this.schema.intervalFormatFallback.get(bundle);
  }
github phensley / cldr-engine / packages / cldr-core / src / internals / calendars / patterns.ts View on Github external
constructor(
    protected readonly bundle: Bundle,
    protected readonly internals: Internals,
    private readonly schema: CalendarSchema,
    readonly cacheSize: number = 50
  ) {
    this.language = bundle.language();
    this.region = bundle.region();
    this.skeletonParser = this.buildSkeletonParser();
    this.skeletonRequestCache = new LRU(cacheSize);
    this.intervalRequestCache = new LRU(cacheSize);
    this.namesCache = new LRU(cacheSize);

    // Fetch this locale's main formats
    this.dateFormats = schema.dateFormats.mapping(bundle);
    this.timeFormats = schema.timeFormats.mapping(bundle);
    this.wrapperFormats = schema.dateTimeFormats.mapping(bundle);

    // Fetch skeletons and build best-fit matchers
    this.rawAvailableFormats = this.schema.availableFormats.mapping(bundle);
    this.rawPluralFormats = this.schema.pluralFormats.mapping(bundle);
    this.rawIntervalFormats = this.schema.intervalFormats.mapping(bundle);
    this.buildAvailableMatcher();
    this.buildIntervalMatcher();

    this.intervalFallback = this.schema.intervalFormatFallback.get(bundle);
github phensley / cldr-engine / packages / cldr-core / src / resource / checksum.ts View on Github external
export const checksumIndices = (version: string, map: KeyIndexMap): string => {
  const c = new Checksum();
  c.update(version);

  // Visit map keys in sorted order
  const keys = Object.keys(map).sort();
  for (const key of keys) {
    c.update(key);

    // Mapped values must be visited in their existing order.
    for (const val of map[key].keys) {
      c.update(val);
    }
  }
  return c.get().toString(16);
};
github phensley / cldr-engine / packages / cldr-core / __tests__ / _helpers / bundle.ts View on Github external
import * as fs from 'fs';
import { join } from 'path';

import { SchemaConfig } from '@phensley/cldr-schema';
import { LRU } from '@phensley/cldr-utils';
import { LanguageResolver } from '@phensley/locale';

import { Bundle, Pack } from '../../src/resource';
import { CLDRFramework } from '../../src';
import { VERSION } from '../../src/utils/version';

const pkg = require('../../package.json');

const TEMPROOT = join(__dirname, '..', '..', '.custom-packs');

const bundleCache = new LRU(15);

interface PackSpec {
  hash: string;
  config: string;
}

const makedir = (dir: string) => {
  if (!fs.existsSync(dir)) {
    fs.mkdirSync(dir);
  }
};

/**
 * Configure a framework with a loader that will load a custom resource pack.
 * This allows us to test purposefully-mismatched resource pack and framework
 * checksums;
github phensley / cldr-engine / packages / cldr-core / src / internals / calendars / internal.ts View on Github external
constructor(
    readonly internals: Internals,
    readonly cacheSize: number = 50
  ) {
    this.schema = internals.schema;
    this.dayPeriodRules = new DayPeriodRules(cacheSize);
    this.patternCache = new Cache(parseDatePattern, cacheSize);
    this.availableCalendars = new Set(internals.config.calendars || []);
    this.hourPatternCache = new Cache((raw: string): [DateTimeNode[], DateTimeNode[]] => {
      const parts = raw.split(';');
      return [this.patternCache.get(parts[0]), this.patternCache.get(parts[1])];
    }, cacheSize);

    this.calendarFormatterCache = new Cache((calendar: string) => {
      let s: CalendarSchema | undefined;
      if (this.availableCalendars.has(calendar)) {
        switch (calendar) {
          case 'buddhist':
            s = this.schema.Buddhist;
            break;
          case 'japanese':
            s = this.schema.Japanese;
            break;
github phensley / cldr-engine / packages / cldr-core / src / internals / calendars / internal.ts View on Github external
constructor(
    readonly internals: Internals,
    readonly cacheSize: number = 50
  ) {
    this.schema = internals.schema;
    this.dayPeriodRules = new DayPeriodRules(cacheSize);
    this.patternCache = new Cache(parseDatePattern, cacheSize);
    this.availableCalendars = new Set(internals.config.calendars || []);
    this.hourPatternCache = new Cache((raw: string): [DateTimeNode[], DateTimeNode[]] => {
      const parts = raw.split(';');
      return [this.patternCache.get(parts[0]), this.patternCache.get(parts[1])];
    }, cacheSize);

    this.calendarFormatterCache = new Cache((calendar: string) => {
      let s: CalendarSchema | undefined;
      if (this.availableCalendars.has(calendar)) {
        switch (calendar) {
          case 'buddhist':
            s = this.schema.Buddhist;
            break;
          case 'japanese':
            s = this.schema.Japanese;
            break;
          case 'persian':
            s = this.schema.Persian;
            break;
        }
      }
      if (s === undefined) {
        s = this.schema.Gregorian;
github phensley / cldr-engine / packages / cldr-core / src / internals / calendars / internal.ts View on Github external
constructor(
    readonly internals: Internals,
    readonly cacheSize: number = 50
  ) {
    this.schema = internals.schema;
    this.dayPeriodRules = new DayPeriodRules(cacheSize);
    this.patternCache = new Cache(parseDatePattern, cacheSize);
    this.availableCalendars = new Set(internals.config.calendars || []);
    this.hourPatternCache = new Cache((raw: string): [DateTimeNode[], DateTimeNode[]] => {
      const parts = raw.split(';');
      return [this.patternCache.get(parts[0]), this.patternCache.get(parts[1])];
    }, cacheSize);

    this.calendarFormatterCache = new Cache((calendar: string) => {
      let s: CalendarSchema | undefined;
      if (this.availableCalendars.has(calendar)) {
        switch (calendar) {
          case 'buddhist':
            s = this.schema.Buddhist;
            break;
          case 'japanese':
            s = this.schema.Japanese;
            break;
          case 'persian':
            s = this.schema.Persian;
github phensley / cldr-engine / packages / cldr-core / src / internals / calendars / rules.ts View on Github external
constructor(protected cacheSize: number) {
    this.cache = new Cache(parseRule, cacheSize);
  }
github phensley / cldr-engine / packages / cldr-core / src / internals / wrapper / internal.ts View on Github external
constructor(cacheSize: number = 50) {
    this.wrapperPatternCache = new Cache(parseWrapperPattern, cacheSize);
  }

@phensley/cldr-utils

Utilities for cldr-engine packages

Apache-2.0
Latest version published 17 days ago

Package Health Score

60 / 100
Full package analysis

Similar packages