npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@theresnotime/ipa-validator

v1.5.4

Published

IPA validator

Downloads

289

Readme

Node package for validating and normalizing IPA

Node.js CI CodeQL install size

Installing

Go grab it on npmjs via npm i @theresnotime/ipa-validator

You'll then be all set to require it:

const ipaValidator = require('@theresnotime/ipa-validator');

Simples!

IPA goes in..

We pass the the IPA as a string:

let validatorResult = await ipaValidator.validate('həˈləʊ');

..and a bool comes out!

Unsurprisingly, true for valid IPA, false for invalid IPA..

A note on "valid"

As the tests show, you need to use the correct unicode — for example, həˈləʊ is valid but hə'ləʊ is not.

Functions

validate

By default, the validate function strips delimiters (/.../, [...]) and checks that the string contains only valid IPA characters.

/**
 * Validate delimiter-stripped IPA, optionally normalising it first.
 * @param {string} ipa - IPA to validate.
 * @param {boolean} strip - Strip delimiters (default: true)
 * @param {boolean} normalizeIPA - Normalize IPA (default: false)
 * @param {boolean} google - Normalize IPA for Google TTS (default: false)
 * @returns {boolean} - Whether the IPA is valid.
 */
function validate(ipa, strip = true, normalizeIPA = false, google = false)

normalize

The normalize function ensures that the IPA is using the correct unicode for similar looking characters (e.g. that you're using ˈ instead of '). By default, it does not strip delimiters.

/**
 * Normalize IPA
 * @param {string} ipa - IPA to normalize.
 * @param {boolean} strip - Strip delimiters (default: false)
 * @param {boolean} google - Normalize IPA for Google TTS (default: false)
 * @returns {string} - normalized IPA
 */
function normalize(ipa, strip = false, google = false)

stripIPA

The stripIPA function strips delimiters (/.../, [...]) from the IPA.

/**
 * Strip IPA delimiters (currently /.../ and [...])
 * @param {string} ipa - IPA to strip.
 * @returns {string} - Stripped IPA
 */
function stripIPA(ipa)

removeDiacritics

The removeDiacritics function removes diacritics from the IPA.

/**
 * Remove diacritics
 * @param {string} ipa - IPA to modify.
 * @param {boolean} strip - Strip delimiters (default: false)
 * @returns {string} - modified IPA
 */
function removeDiacritics(ipa, strip = false)

"Google" option

As part of a work project, we're feeding IPA to Google's TTS engine — Google is a little opinionated about things like diacritics. For example, the IPA ˈɔːfɫ̩ would not render correctly in Google TTS. A custom charmap is used to normalize certain characters:

let charmap = [
    ['(', ''],
    [')', ''],
    ["'", 'ˈ'],
    [':', 'ː'],
    [',', 'ˌ'],
    ['ⁿ', 'n'], // 207F
    ['ʰ', 'h'], // 02B0
    ['ɫ', 'l'], // 026B
    ['ˡ', 'l'], // 02E1
    ['ʲ', 'j'], // 02B2
];

Doing Google-y normalizing is just a call like:

await ipaValidator.normalize('ˈɔːfɫ̩', true, true);
// Returns ˈɔːfl

Some further examples can be seen in google.test.js.

Developing

  1. Fork n' clone this repo
  2. Do a npm install
  3. Run npm test because who knows, maybe its already broken
  4. Hack!

The Regex

^[().a-z|æçðøħŋœǀ-ǃɐ-ɻɽɾʀ-ʄʈ-ʒʔʕʘʙʛ-ʝʟʡʢʰʲʷʼˀˈˌːˑ˞ˠˡˤ-˩̴̘̙̜̝̞̟̠̤̥̩̪̬̯̰̹̺̻̼̀́̂̃̄̆̈̊̋̌̏̽̚͜͡βθχ᷄᷅᷈‖‿ⁿⱱ]+$

I've also placed it at https://regex101.com/r/f2Qhuk if you think you can improve it... (please do!)