ja-greetings
Version:
ja-greetings is a cli tool that displays Japanese greetings
78 lines (65 loc) • 1.57 kB
JavaScript
const path = require('path')
const fs = require('fs')
exports.get = (greeting, opt) => {
// exist check
try {
const file_path = path.join(__dirname, '/../greetings', greeting) + '.gr'
const text = fs.readFileSync(file_path, "utf-8")
return this.replace_ex(text, opt)
} catch(err) {
return false
}
}
exports.replace_ex = (greeting, opt) => {
opt = opt || 'origin'
greeting = greeting.replace(/\r\n?|[\n\u2028\u2029]/g, "\n").replace(/^\uFEFF/, '')
const regexp = new RegExp('\\$' + opt + '\\s*>\\n([\\s\\S]+)\\n<\\s*' + opt)
const match = greeting.match(regexp)
if (!match) greeting = "Cannot parse greeting file"
else greeting = match[1]
return greeting
}
exports.get_greetings = () => {
// if add new greeting then add below list too
const greetings = {
a: 'all',
n: 'new',
s: 'summer',
w: 'winter',
l: 'last',
t: 'thx',
so: 'sorry'
}
return greetings
}
exports.get_dialects = () => {
// if add new dialects then add below list too
const dialects = [
'kyoto',
'osaka',
'okinawa',
'hiroshima'
]
return dialects
}
exports.get_languages = () => {
// if add new languages then add below list too
const languages = [
'en',
'ch'
]
return languages
}
exports.get_surrounds = () => {
// if add new surrounds then add below list too
let surrounds = [
'no',
'w-star',
'b-star',
'w-tri',
'b-tri',
'asterisk',
'slash'
]
return surrounds
}