Skip to content

Instantly share code, notes, and snippets.

@gooderist
Created September 17, 2017 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gooderist/ddd1f7049852931d1f491b7b7f35668a to your computer and use it in GitHub Desktop.
Save gooderist/ddd1f7049852931d1f491b7b7f35668a to your computer and use it in GitHub Desktop.
Simple English detection
const unicode = {
basic_latin: /[\u0020-\u007F]/g
}
console.log('賛美歌い続ける'.search(unicode.basic_latin)) // -1
console.log('Sanbi utaitsuzukeru'.search(unicode.basic_latin)) // 0
console.log('10,000 Reasons'.search(unicode.basic_latin)) // 0
console.log('Bless the Lord oh my soul'.search(unicode.basic_latin)) // 0
/*
We have English and Japanese lyrics in our church services and I needed
a quick way to differentiate between the two in a script I use for
slide generation. We never mix the two in the same line.
Tried using franc but it didn't work very well.
This is much simpler and does what we need.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment