Phony

JavaScript library for translating the phonetic alphabet

Phony is a pure JavaScript library for translating messages to and from the NATO phonetic alphabet.

Its API is extremely easy to use and exposes the simple translation functionality through the global variable, phony. The predefined phonetic alphabet is based on the ITU but Phony allows this to be easily extended by adding and/or modifying characters.

Translating messages

The API allows either a data object or string message to be passed as the first argument. If a string is used all options will use their default value; otherwise they can be set using the following properties;

  • alphabet - The phonetic alphabet to be used to translate the message
    • Optional: The "ITU" alphabet is used by default
    • Only used by phony.to
  • caseSensitive - Whether or not the translation should be case sensitive
    • Optional: Translation is case-sensitive by default
  • message - The string to be translated
  • omitSpace - Whether or not words should be split up by "Space"
    • Optional: "Space" is not omitted by default
    • Only used by phony.to
  • round - Whether or not hundreds and thousands should be rounded (e.g. "100" => "One Hundred")
    • Optional: Hundreds and thousands are rounded by default

To...

phony.to([data|message][, callback(error, result)])

Returns the phonetic alphabet representation of the message provided.

From...

phony.from([data|message][, callback(error, result)])

Returns the human-readable version translated from the phonetic alphabet message provided.

Customizing

The full potential of Phony can be accessed by customizing your interactions with the API via the exposed method which allows you to define (or redefine) supported characters.

Defining characters

phony.defineChar(character, translation[, callback(error)])

Maps a phonetic alphabet translation for a supported character (existing/new). When defining a character it's recommended (but not required) to specify its value using a Unicode escape sequence (codes can easily be found on Wikipedia) and follow these guidelines when specifying the translation;

  • Must be either a string or an array of strings.
  • The string (or strings) must contain only a single word, which should be in title case (e.g. Alfa).
  • May be a duplicate but not recommended as phony.from chooses the character that matches the translation first.

Miscellaneous

The Phony API exposes some properties and methods which may only be useful to users in special cases.

phony.noConflict([callback(error)])

Relinquish Phony's control of the phony global variable. If another library uses this variable calling this method will reassign it back to that library.

phony.ALPHABETS

The phonetic alphabet acronyms supported by Phony.

phony.VERSION

The current version of Phony.

Changes

Version 1.0.1

  • Add documentation (generated using docco)
  • #1: Add support for single string or object argument to the to and from methods

View historical changes

Bugs

If you have any problems with this library or would like to see the changes currently in development browse our issues.

Developers should run all tests (locally) and ensure they pass before submitting a pull request.

Questions?

Take a look at the documentation to get a better understanding of what the code is doing.

If that doesn't help, feel free to follow me on Twitter, @neocotic.