Skip to content

Commit

Permalink
Add exports of some useful types
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Nov 8, 2021
1 parent 5acfa54 commit 5fbf171
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/**
* @typedef {import('./lib/parse.js').Schema} Schema
* @typedef {import('./lib/parse.js').Extension} Extension
* @typedef {import('./lib/parse.js').Warning} Warning
* @typedef {import('./lib/parse.js').Options} Options
*/

export {parse} from './lib/parse.js'
Expand Down
22 changes: 14 additions & 8 deletions lib/parse.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
/**
* @typedef ParseOptions
* @callback Warning
* @param {string} reason
* @param {number} code
* @param {number} offset
* @returns {void}
*
* @typedef Options
* @property {boolean} [normalize=true]
* @property {boolean} [forgiving=false]
* @property {(reason: string, code: number, offset: number) => void} [warning]
* @property {Warning} [warning]
*
* @typedef Extension
* @property {string} singleton
* @property {Array<string>} extensions
*
* @typedef Schema
* @property {string|null} language
* @property {string|null|undefined} language
* @property {Array<string>} extendedLanguageSubtags
* @property {string|null} script
* @property {string|null} region
* @property {string|null|undefined} script
* @property {string|null|undefined} region
* @property {Array<string>} variants
* @property {Array<Extension>} extensions
* @property {Array<string>} privateuse
* @property {string|null} irregular
* @property {string|null} regular
* @property {string|null|undefined} irregular
* @property {string|null|undefined} regular
*/

import {isAlphanumerical} from 'is-alphanumerical'
Expand All @@ -32,7 +38,7 @@ const own = {}.hasOwnProperty
* Parse a BCP 47 language tag.
*
* @param {string} tag
* @param {ParseOptions} [options]
* @param {Options} [options]
* @returns {Schema}
*/
export function parse(tag, options = {}) {
Expand Down
2 changes: 1 addition & 1 deletion lib/stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Compile a language schema to a BCP 47 language tag.
*
* @param {Schema} schema
* @returns {string|undefined}
* @returns {string}
*/
export function stringify(schema = {}) {
/** @type {Array<string>} */
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ Called when an error occurs.
## Types

This package is fully typed with [TypeScript][].
It additionally exports the `Schema` type, which represents the structure of
that interface.
It exports additional `Schema`, `Extension`, `Warning`, and `Options` types that
model their respective interfaces.

## Compatibility

Expand Down

0 comments on commit 5fbf171

Please sign in to comment.