UNPKG

3.4 kBMarkdownView Raw
1# phonetic-alphabet-converter
2
3[![NPM](https://nodei.co/npm/phonetic-alphabet-converter.png)](https://nodei.co/npm/phonetic-alphabet-converter/)
4
5[![NPM version](https://img.shields.io/npm/v/phonetic-alphabet-converter.svg)](https://www.npmjs.com/package/phonetic-alphabet-converter)
6[![Build Status](https://github.com/remarkablemark/phonetic-alphabet-converter/workflows/build/badge.svg?branch=master)](https://github.com/remarkablemark/phonetic-alphabet-converter/actions?query=workflow%3Abuild)
7[![Coverage Status](https://coveralls.io/repos/github/remarkablemark/phonetic-alphabet-converter/badge.svg?branch=master)](https://coveralls.io/github/remarkablemark/phonetic-alphabet-converter?branch=master)
8
9Converts string to [NATO phonetic alphabet](https://en.wikipedia.org/wiki/NATO_phonetic_alphabet) words:
10
11```
12PhoneticAlphabetConverter(string[, alphabet])
13```
14
15#### Example
16
17```js
18import converter from 'phonetic-alphabet-converter';
19converter('abc'); // ['alpha', 'bravo', 'charlie']
20```
21
22[Site](https://b.remarkabl.org/phonetic-alphabet-converter) | [JSFiddle](https://jsfiddle.net/remarkablemark/g4r6fu7j/) | [Repl.it](https://repl.it/@remarkablemark/phonetic-alphabet-converter)
23
24## Install
25
26[NPM](https://www.npmjs.com/package/phonetic-alphabet-converter):
27
28```sh
29npm install phonetic-alphabet-converter --save
30```
31
32[Yarn](https://yarnpkg.com/package/phonetic-alphabet-converter):
33
34```sh
35yarn add phonetic-alphabet-converter
36```
37
38[CDN](https://unpkg.com/phonetic-alphabet-converter/):
39
40```html
41<script src="https://unpkg.com/phonetic-alphabet-converter@latest/umd/phonetic-alphabet-converter.min.js"></script>
42<script>
43 window.PhoneticAlphabetConverter.default(/* string */);
44</script>
45```
46
47## Usage
48
49Import module:
50
51```js
52// ES Modules
53import converter from 'phonetic-alphabet-converter';
54
55// CommonJS
56const converter = require('phonetic-alphabet-converter').default;
57```
58
59Parse string:
60
61```js
62converter('Hello, world!');
63// ['hotel', 'echo', 'lima', 'lima', 'oscar', 'whiskey', 'oscar', 'romeo', 'lima', 'delta']
64```
65
66> The string is **lowercased** and characters not found on the alphabet map are **ignored**.
67
68If the string is blank, an empty array is returned:
69
70```js
71converter('');
72// []
73```
74
75If the first argument is not a string, then an error will be thrown:
76
77```js
78converter();
79// TypeError: First argument must be a string
80```
81
82### Second Argument
83
84By default, the converter uses a mapping of the NATO phonetic alphabet:
85
86```js
87import { NATO_PHONETIC_ALPHABET } from 'phonetic-alphabet-converter';
88```
89
90To override that, you can pass a custom object to the second argument:
91
92```js
93converter('abc', {
94 a: 'Amsterdam',
95 b: 'Baltimore',
96 c: 'Casablanca',
97});
98// ['Amsterdam', 'Baltimore', 'Casablanca']
99```
100
101Or you can assign values to the default alphabet map:
102
103```js
104import { NATO_PHONETIC_ALPHABET } from 'phonetic-alphabet-converter';
105
106converter('abc', {
107 ...NATO_PHONETIC_ALPHABET,
108 a: 'alfa',
109});
110// ['alfa', 'bravo', 'charlie']
111```
112
113## Testing
114
115Run tests with coverage:
116
117```sh
118npm test
119```
120
121Run tests in watch mode:
122
123```sh
124npm run test:watch
125```
126
127Lint files:
128
129```sh
130npm run lint
131```
132
133Fix lint errors:
134
135```sh
136npm run lint:fix
137```
138
139## Release
140
141Only collaborators with credentials can release and publish:
142
143```sh
144npm run release
145git push --follow-tags && npm publish
146```
147
148## License
149
150[MIT](https://github.com/remarkablemark/phonetic-alphabet-converter/blob/master/LICENSE)