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 |
|
9 | Converts string to [NATO phonetic alphabet](https://en.wikipedia.org/wiki/NATO_phonetic_alphabet) words:
|
10 |
|
11 | ```
|
12 | PhoneticAlphabetConverter(string[, alphabet])
|
13 | ```
|
14 |
|
15 | #### Example
|
16 |
|
17 | ```js
|
18 | import converter from 'phonetic-alphabet-converter';
|
19 | converter('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
|
29 | npm install phonetic-alphabet-converter --save
|
30 | ```
|
31 |
|
32 | [Yarn](https://yarnpkg.com/package/phonetic-alphabet-converter):
|
33 |
|
34 | ```sh
|
35 | yarn 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 |
|
49 | Import module:
|
50 |
|
51 | ```js
|
52 | // ES Modules
|
53 | import converter from 'phonetic-alphabet-converter';
|
54 |
|
55 | // CommonJS
|
56 | const converter = require('phonetic-alphabet-converter').default;
|
57 | ```
|
58 |
|
59 | Parse string:
|
60 |
|
61 | ```js
|
62 | converter('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 |
|
68 | If the string is blank, an empty array is returned:
|
69 |
|
70 | ```js
|
71 | converter('');
|
72 | // []
|
73 | ```
|
74 |
|
75 | If the first argument is not a string, then an error will be thrown:
|
76 |
|
77 | ```js
|
78 | converter();
|
79 | // TypeError: First argument must be a string
|
80 | ```
|
81 |
|
82 | ### Second Argument
|
83 |
|
84 | By default, the converter uses a mapping of the NATO phonetic alphabet:
|
85 |
|
86 | ```js
|
87 | import { NATO_PHONETIC_ALPHABET } from 'phonetic-alphabet-converter';
|
88 | ```
|
89 |
|
90 | To override that, you can pass a custom object to the second argument:
|
91 |
|
92 | ```js
|
93 | converter('abc', {
|
94 | a: 'Amsterdam',
|
95 | b: 'Baltimore',
|
96 | c: 'Casablanca',
|
97 | });
|
98 | // ['Amsterdam', 'Baltimore', 'Casablanca']
|
99 | ```
|
100 |
|
101 | Or you can assign values to the default alphabet map:
|
102 |
|
103 | ```js
|
104 | import { NATO_PHONETIC_ALPHABET } from 'phonetic-alphabet-converter';
|
105 |
|
106 | converter('abc', {
|
107 | ...NATO_PHONETIC_ALPHABET,
|
108 | a: 'alfa',
|
109 | });
|
110 | // ['alfa', 'bravo', 'charlie']
|
111 | ```
|
112 |
|
113 | ## Testing
|
114 |
|
115 | Run tests with coverage:
|
116 |
|
117 | ```sh
|
118 | npm test
|
119 | ```
|
120 |
|
121 | Run tests in watch mode:
|
122 |
|
123 | ```sh
|
124 | npm run test:watch
|
125 | ```
|
126 |
|
127 | Lint files:
|
128 |
|
129 | ```sh
|
130 | npm run lint
|
131 | ```
|
132 |
|
133 | Fix lint errors:
|
134 |
|
135 | ```sh
|
136 | npm run lint:fix
|
137 | ```
|
138 |
|
139 | ## Release
|
140 |
|
141 | Only collaborators with credentials can release and publish:
|
142 |
|
143 | ```sh
|
144 | npm run release
|
145 | git push --follow-tags && npm publish
|
146 | ```
|
147 |
|
148 | ## License
|
149 |
|
150 | [MIT](https://github.com/remarkablemark/phonetic-alphabet-converter/blob/master/LICENSE)
|