Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

phonetic-alphabet-converter

remarkablemark136MIT1.1.0TypeScript support: included

NATO phonetic alphabet converter.

nato, phonetic, alphabet, converter

readme

phonetic-alphabet-converter

NPM

NPM version Build Status Coverage Status

Converts string to NATO phonetic alphabet words:

PhoneticAlphabetConverter(string[, alphabet])

Example

import converter from 'phonetic-alphabet-converter';
converter('abc'); // ['alpha', 'bravo', 'charlie']

Site | JSFiddle | Repl.it

Install

NPM:

npm install phonetic-alphabet-converter --save

Yarn:

yarn add phonetic-alphabet-converter

CDN:

<script src="https://unpkg.com/phonetic-alphabet-converter@latest/umd/phonetic-alphabet-converter.min.js"></script>
<script>
  window.PhoneticAlphabetConverter.default(/* string */);
</script>

Usage

Import module:

// ES Modules
import converter from 'phonetic-alphabet-converter';

// CommonJS
const converter = require('phonetic-alphabet-converter').default;

Parse string:

converter('Hello, world!');
// ['hotel', 'echo', 'lima', 'lima', 'oscar', 'whiskey', 'oscar', 'romeo', 'lima', 'delta']

The string is lowercased and characters not found on the alphabet map are ignored.

If the string is blank, an empty array is returned:

converter('');
// []

If the first argument is not a string, then an error will be thrown:

converter();
// TypeError: First argument must be a string

Second Argument

By default, the converter uses a mapping of the NATO phonetic alphabet:

import { NATO_PHONETIC_ALPHABET } from 'phonetic-alphabet-converter';

To override that, you can pass a custom object to the second argument:

converter('abc', {
  a: 'Amsterdam',
  b: 'Baltimore',
  c: 'Casablanca',
});
// ['Amsterdam', 'Baltimore', 'Casablanca']

Or you can assign values to the default alphabet map:

import { NATO_PHONETIC_ALPHABET } from 'phonetic-alphabet-converter';

converter('abc', {
  ...NATO_PHONETIC_ALPHABET,
  a: 'alfa',
});
// ['alfa', 'bravo', 'charlie']

Testing

Run tests with coverage:

npm test

Run tests in watch mode:

npm run test:watch

Lint files:

npm run lint

Fix lint errors:

npm run lint:fix

Release

Only collaborators with credentials can release and publish:

npm run release
git push --follow-tags && npm publish

License

MIT

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

1.1.0 (2021-01-29)

Features

  • index: replace indiana with india (eaf22e4)

1.0.0 (2020-11-09)

Performance Improvements

  • docs: use minified UMD bundle for demo site (4fa265b)

  • feat(index)!: skip characters that are not on the alphabet map (3579293)

BREAKING CHANGES

  • filter out undefined from converter array output when a character does not exist on the alphabet map.

0.3.0 (2020-11-08)

Bug Fixes

Features

  • docs: load Roboto font and use headline3 styles for heading (2559e35)

Performance Improvements

  • index: return early with empty array if string is blank (6a5334a)

0.2.0 (2020-02-21)

Bug Fixes

  • docs: ensure fallback cdn script is loaded on gh-pages (20311a4)

Features

  • docs: add github-corners and update meta description (7ff2d6a)
  • src: export NATO_PHONETIC_ALPHABET (e284565)

0.1.0 (2020-01-31)

Features

  • docs: add ripple styling to chips (606bfef)
  • docs: add static site demo of library that uses mdc web (b72e240)
  • docs: fallback to cdn if local js is not found in index.html (d0daf6f)
  • docs: style the words as chips (b6f86ca)
  • docs: wrap markup in html5-boilerplate (caf0a58)
  • index: add index.js and "files" in package.json (169f417)
  • index: remove index.js and update package.json (f9dfe12)
  • src: add index.ts with phonetic alphabet map and converter (d3bc7f7)
  • src: throw a type error if first argument is not a string (841555b)