open-index/open-npm huggingface dataset:
npm package: @phensley/language-tag
Description: Parsing and construction of BCP 47 language tags
Author: Patrick Hensley
Latest version: 1.14.0

# @phensley/language-tag

[![@phensley/language-tag](https://badge.fury.io/js/%40phensley%2Flocale.svg)](https://www.npmjs.com/package/@phensley/language-tag) [![min+gzip](https://badgen.net/bundlephobia/minzip/@phensley/language-tag)](https://bundlephobia.com/result?p=@phensley/language-tag)

Implements BCP 47 language tag parsing and construction.

## Installation

NPM:

```
npm install --save @phensley/language-tag
```

Yarn:

```
yarn add @phensley/language-tag
```

## Examples

```typescript
const IDS = ['en', 'es', 'es-419', 'und-AR', 'und-Hant', 'iw', 'i-klingon'];
for (const id of IDS) {
  const tag = parseLanguageTag(id);
  console.log(`${tag.compact().padStart(10)}  ${tag.expanded()}`);
}
```

```
        en  en-Zzzz-ZZ
        es  es-Zzzz-ZZ
    es-419  es-Zzzz-419
    und-AR  und-Zzzz-AR
  und-Hant  und-Hant-ZZ
        iw  iw-Zzzz-ZZ
       tlh  tlh-Zzzz-ZZ
```

```typescript
const t = new LanguageTag(undefined, 'latn', 'us', 'PoSiX', {
  u: ['ca-gregory']
});
console.log(t.expanded());
```

```
und-Latn-US-posix-u-ca-gregory
```
npm package: @phensley/locale
Description: Locale subtag resolver
Author: Patrick Hensley
Latest version: 1.14.0

# @phensley/locale

[![@phensley/locale](https://badge.fury.io/js/%40phensley%2Flocale.svg)](https://www.npmjs.com/package/@phensley/locale) [![min+gzip](https://badgen.net/bundlephobia/minzip/@phensley/locale)](https://bundlephobia.com/result?p=@phensley/locale)

Implements resolving of BCP 47 language tags by alias and likely subtags substitution.

## Installation

NPM:

```
npm install --save @phensley/locale
```

Yarn:

```
yarn add @phensley/locale
```

## Examples

```typescript
import { LanguageResolver } from '@phensley/locale-resolver';

const IDS = ['en', 'es', 'es-419', 'und-AR', 'und-Hant', 'iw', 'i-klingon'];
for (const id of IDS) {
  const r = LanguageResolver.resolve(id);
  console.log(r.expanded());
}
```

```
en-Latn-US
es-Latn-ES
es-Latn-419
es-Latn-AR
zh-Hant-TW
he-Hebr-IL
tlh-Latn-US
```
npm package: @phensley/locale-matcher
Description: Implements CLDR enhanced language matching
Author: Patrick Hensley
Latest version: 1.14.0

# @phensley/locale-matcher

[![@phensley/locale-matcher](https://badge.fury.io/js/%40phensley%2Flocale-matcher.svg)](https://www.npmjs.com/package/@phensley/locale-matcher) [![min+gzip](https://badgen.net/bundlephobia/minzip/@phensley/locale-matcher)](https://bundlephobia.com/result?p=@phensley/locale-matcher)

Implements distance based locale matching using the CLDR enhanced language matching algorithm.

## Installation

NPM:

```
npm install --save @phensley/locale-matcher
```

Yarn:

```
yarn add @phensley/locale-matcher
```

## Examples

```typescript
import { LocaleMatch, LocaleMatcher } from '@phensley/locale-matcher';

// Add supported locales to matcher
const matcher = new LocaleMatcher('en, en_GB, zh, pt_AR, es-419');
let m: LocaleMatch;

// Query desired locales to find the nearest match
m = matcher.match('en-AU');
console.log(`distance ${m.distance} locale ${m.locale.id}`);

m = matcher.match('es-MX');
console.log(`distance ${m.distance} locale ${m.locale.id}`);
```

```
distance 3 locale en_GB
distance 4 locale es-419
```
npm package: @phensley/timezone
Description: Compact timezone lib based on tz database
Author: Patrick Hensley
Latest version: 1.14.0

# @phensley/timezone

[![@phensley/timezone](https://badge.fury.io/js/%40phensley%2Ftimezone.svg)](https://www.npmjs.com/package/@phensley/timezone) [![min+gzip](https://badgen.net/bundlephobia/minzip/@phensley/timezone)](https://bundlephobia.com/result?p=@phensley/timezone)

Compact timezone library provides the full range of tzdb data. https://data.iana.org/time-zones/tz-link.html

## Installation

NPM:

```
npm install --save @phensley/timezone
```

Yarn:

```
yarn add @phensley/timezone
```

## Examples

Resolve old timezone ids that are deprecated.

```typescript
import { TZ } from '@phensley/timezone';

const id = TZ.resolveId('Pacific/Samoa');
console.log(id);
```

```
Pacific/Pago_Pago
```

#### Lookup the zone info for a timezone id at a given UTC time.

Timezone offsets are in milliseconds.

```typescript
const ZONES = [
  'UTC',
  'Pacific/Samoa',
  'America/New_York',
  'Pacific/Pago_Pago',
  'Asia/Tokyo',
  'Europe/Paris',
];

const now = new Date(2020, 2, 18, 12, 30, 0).getTime();
for (const zoneid of ZONES) {
  const info = TZ.fromUTC(zoneid, now);
  console.log(`${zoneid.padEnd(18)} -> ${JSON.stringify(info)}`);
}
```

```
UTC                -> {"abbr":"UTC","dst":0,"offset":0,"zoneid":"Etc/UTC"}
Pacific/Samoa      -> {"abbr":"SST","dst":0,"offset":-39600000,"zoneid":"Pacific/Pago_Pago"}
America/New_York   -> {"abbr":"EDT","dst":1,"offset":-14400000,"zoneid":"America/New_York"}
Pacific/Pago_Pago  -> {"abbr":"SST","dst":0,"offset":-39600000,"zoneid":"Pacific/Pago_Pago"}
Asia/Tokyo         -> {"abbr":"JST","dst":0,"offset":32400000,"zoneid":"Asia/Tokyo"}
Europe/Paris       -> {"abbr":"CET","dst":0,"offset":3600000,"zoneid":"Europe/Paris"}
```

#### Lookup the zone info for a timezone id and a local "wall clock" timestamp.

Returns the corresponding UTC timestamp along with a zone info record.

```typescript
// Sun Mar  8 2020 02:10:00 AM NY time
const epoch = 1583633400000;
const zoneid = 'America/New_York';
const [utc, info] = TZ.fromUTC(zoneid, now)!;
console.log(utc);
console.log(JSON.stringify(info));
```

```
1583651400000
{"abbr":"EDT","dst":1,"offset":-14400000,"zoneid":"America/New_York"}
```
npm package: @phensley/unit-converter
Description: Conversions between CLDR units
Author: Patrick Hensley
Latest version: 1.14.0

# @phensley/unit-converter

[![@phensley/unit-converter](https://badge.fury.io/js/%40phensley%2Flocale.svg)](https://www.npmjs.com/package/@phensley/unit-converter) [![min+gzip](https://badgen.net/bundlephobia/minzip/@phensley/unit-converter)](https://bundlephobia.com/result?p=@phensley/unit-converter)

General framework for converting between units. Includes pre-defined factors for conversion between CLDR units.

```typescript
import { MathContext } from '@phensley/decimal';
import { LENGTH, UnitFactors } from '@phensley/unit-converter';

const factors = new UnitFactors(LENGTH);
const ctx: MathContext = { precision: 7 };
const dst = 'yard';
for (const unit of ['foot', 'mile']) {
  const fac = factors.get(unit, dst)!;
  for (const n of [1, 1.5, 2, 3, 4, 5, 6, 10]) {
    const r = fac.multiply(n, ctx);

    const a = `${n} ${unit}`.padStart(10);
    const b = `${r.toDecimal(ctx).toString()} ${dst}`.padEnd(14);
    const c = `${r.numerator()} \u00F7 ${r.denominator()} ${dst}`;
    console.log(`${a} == ${b}    ${c}`);
  }
  console.log();
}
```

```
    1 foot == 0.3333333 yard    12 ÷ 36 yard
  1.5 foot == 0.5 yard          18.0 ÷ 36 yard
    2 foot == 0.6666667 yard    24 ÷ 36 yard
    3 foot == 1 yard            36 ÷ 36 yard
    4 foot == 1.333333 yard     48 ÷ 36 yard
    5 foot == 1.666667 yard     60 ÷ 36 yard
    6 foot == 2 yard            72 ÷ 36 yard
   10 foot == 3.333333 yard     120 ÷ 36 yard

    1 mile == 1760 yard         63360 ÷ 36 yard
  1.5 mile == 2640 yard         95040.0 ÷ 36 yard
    2 mile == 3520 yard         126720 ÷ 36 yard
    3 mile == 5280 yard         190080 ÷ 36 yard
    4 mile == 7040 yard         253440 ÷ 36 yard
    5 mile == 8800 yard         316800 ÷ 36 yard
    6 mile == 10560 yard        380160 ÷ 36 yard
   10 mile == 17600 yard        633600 ÷ 36 yard
```