-
Notifications
You must be signed in to change notification settings - Fork 0
/
t-number.js
44 lines (38 loc) · 946 Bytes
/
t-number.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* `t-number`
*
* @customElement
* @demo demo/index.html
*/
function toBengaliNum (t) {
const arabicToBengaliMap = {
0:"০",
1:"১",
2:"২",
3:"৩",
4:"৪",
5:"৫",
6:"৬",
7:"৭",
8:"৮",
9:"৯"
}
return Object.keys(arabicToBengaliMap)
.reduce((translation, key) => {
const re = new RegExp(key, 'g');
return translation.replace(re, arabicToBengaliMap[key])
}, t)
}
export class TNumber extends HTMLElement {
connectedCallback() {
this._originalContents = `${this.innerHTML}`
this.render()
document.body.addEventListener('lang-change', this.render.bind(this))
}
render() {
this.innerHTML = document.documentElement.lang.toLowerCase() === 'ben' || document.documentElement.lang.toLowerCase() === 'bn'
? toBengaliNum(this._originalContents)
: this._originalContents
}
}
window.customElements.define('t-number', TNumber);