PageSourceSearch

https://pitaka.lk/static/scripts/singlish.js?v=1

js pitaka.lk collected 2026-10-01 12:14:15 UTC 4,496 bytes, 195 lines download raw bytes

1// sinhala unicode -> easy singlish
2var singlish_vowels = [
3	['අ', 'a'],
4	['ආ', 'aa'],
5	['ඇ', 'ae'],
6	['ඈ', 'ae, aee'],
7	['ඉ', 'i'],
8	['ඊ', 'ii'],
9	['උ', 'u'],
10	['ඌ', 'uu'],
11	['එ', 'e'],
12	['ඒ', 'ee'],
13	['ඔ', 'o'],
14	['ඕ', 'oo'],
15	['ඓ', 'ai'], // sinhala only begin
16	['ඖ', 'ou'],
17	['ඍ', 'ru'],
18	['ඎ', 'ru, ruu'],
19	['ඏ', 'li'],
20	['ඐ', 'li, lii'] // sinhala only end
21];
22
23var singlish_specials = [
24	['ඞ්', 'n'],
25	['ං', 'n, m'],
26	['ඃ', 'n, m'] // sinhala only
27];
28
29var singlish_consonants = [
30	['ක', 'k'],
31	['ග', 'g'],
32	['à¶ ', 'c, ch'],
33	['à¶¢', 'j'],
34	['ඤ', 'n, kn'],
35	['à¶§', 't'],
36	['à¶©', 'd'],
37	['à¶«', 'n'],
38	['à¶­', 'th'],
39	['ද', 'd'],
40	['à¶±', 'n'],
41	['à¶´', 'p'],
42	['à¶¶', 'b'],
43	['ම', 'm'],
44	['ය', 'y'],
45	['à¶»', 'r'],
46	['à¶½', 'l'],
47	['ව', 'v, w'],
48	['ශ', 'sh'],
49	['ෂ', 'sh'],
50	['ස', 's'],
51	['හ', 'h'],
52	['ළ', 'l'],
53	['ෆ', 'f'],
54
55	['ඛ', 'kh, k'],
56	['ඨ', 'th'],
57	['ඝ', 'gh'],
58	['ඟ', 'ng'],
59	['à¶¡', 'ch'],
60	['à¶£', 'jh'],
61	['ඦ', 'nj'],
62	['ඪ', 'dh'],
63	['ඬ', 'nd'],
64	['à¶®', 'th'],
65	['à¶°', 'dh'],
66	['à¶³', 'nd'],
67	['à¶µ', 'ph'],
68	['à¶·', 'bh'],
69	['à¶¹', 'mb'],
70	['à¶¥', 'gn'] // sinhala only
71];
72
73// sinh before, sinh after, roman after
74var singlish_combinations = [
75	['්', ''], //ක්
76	['', 'a'], //ක
77	['ා', 'a, aa'], //කා
78	['ැ', 'ae'],
79	['ෑ', 'ae, aee'],
80	['ි', 'i'],
81	['ී', 'i, ii'],
82	['ු', 'u'],
83	['ූ', 'u, uu'],
84	['ෙ', 'e'],
85	['ේ', 'e, ee'],
86	['ෛ', 'ei'],
87	['ො', 'o'],
88	['ෝ', 'o, oo'],
89
90	['්‍ර', 'ra'], //ක්‍ර
91	['්‍රා', 'ra, raa'], //ක්‍රා
92	['්‍රැ', 'rae'],
93	['්‍රෑ', 'rae, raee'],
94	['්‍රි', 'ri'],
95	['්‍රී', 'ri, rii'],
96	['්‍රෙ', 're'],
97	['්‍රේ', 're, ree'],
98	['්‍රෛ', 'rei'],
99	['්‍රො', 'ro'],
100	['්‍රෝ', 'ro, roo'],
101
102	['්‍ය', 'ya'], //ක්‍ය
103	['්‍යා', 'ya, yaa'], //ක්‍යා
104	['්‍යැ', 'yae'],
105	['්‍යෑ', 'yae, yaee'],
106	['්‍යි', 'yi'],
107	['්‍යී', 'yi, yii'],
108	['්‍යු', 'yu'],
109	['්‍යූ', 'yu, yuu'],
110	['්‍යෙ', 'ye'],
111	['්‍යේ', 'ye, yee'],
112	['්‍යෛ', 'yei'],
113	['්‍යො', 'yo'],
114	['්‍යෝ', 'yo, yoo'],
115
116	['ෘ', 'ru'],  // sinhala only begin
117	['à·²', 'ru, ruu'],
118	['ෞ', 'au'],
119	['ෟ', 'li'],
120	['à·³', 'li, lii'] // sinhala only end
121];
122
123var singlishMapping = [];
124var maxSinglishKeyLen = 0;
125function addToSinglishMapping(values, pSinhStr, pRomanStr) {
126	$.each(values, function (_1, pair) {
127		sinh = pair[0] + pSinhStr;
128
129		romans = pair[1].split(',');
130		pRomans = pRomanStr.split(',');
131		$.each(romans, function (_2, roman) {
132			$.each(pRomans, function (_2, pRoman) {
133				mapIndex = roman.trim() + pRoman.trim();
134				if (mapIndex in singlishMapping) {
135					singlishMapping[mapIndex].push(sinh);
136				} else {
137					singlishMapping[mapIndex] = [sinh];
138					maxSinglishKeyLen = Math.max(mapIndex.length, maxSinglishKeyLen);
139				}
140			});
141		});
142	});
143}
144
145addToSinglishMapping(singlish_vowels, '', '');
146addToSinglishMapping(singlish_specials, '', '');
147$.each(singlish_combinations, function(i, combi) {
148	addToSinglishMapping(singlish_consonants, combi[0], combi[1]);
149});
150console.log(singlishMapping);
151console.log('maxSinglishKeyLen: '+ maxSinglishKeyLen);
152
153
154function getPossibleMatches(input) {
155	var matches = [];
156	for (var len = 1; len <= maxSinglishKeyLen && len <= input.length; len++) {
157		var prefix = input.slice(0, len); var rest = input.slice(len);
158		matches = matches.concat(permuteMatches(prefix, rest));
159	}
160	return matches;
161}
162
163function permuteMatches(prefix, rest) {
164	// if prefix is all sinhala  then pass through the prefix - this allows sinhala and singlish mixing and ending dot
165	var prefixMappings = isSinglishQuery(prefix) ? singlishMapping[prefix] : [prefix];
166	if (!prefixMappings) { // recursion ending condition
167		return [];
168	}
169	if (!rest) {  // recursion ending condition
170		return prefixMappings;
171	}
172	var restMappings = getPossibleMatches(rest);
173	var fullMappings = [];
174	$.each(restMappings, function (_1, restM) {
175		$.each(prefixMappings, function (_2, prefixM) {
176			fullMappings.push(prefixM + restM);
177		});
178	});
179	return fullMappings;
180}
181
182function isSinglishQuery(query) {
183	var A = "A".charCodeAt(0);
184	var Z = "Z".charCodeAt(0);
185	var a = "a".charCodeAt(0);
186	var z = "z".charCodeAt(0);
187
188	for (var i = 0; i < query.length; i++) {
189		var c = query.charCodeAt(i);
190		if ((c <= Z && c >= A) || (c <= z && c >= a)) {
191			return true;
192		}
193	}
194	return false;
195}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.