-
Notifications
You must be signed in to change notification settings - Fork 3
/
jsfiddle.js
64 lines (56 loc) · 2.25 KB
/
jsfiddle.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// source for the tweak done on JSFiddle - http://jsfiddle.net/FloydPink/h8gkqgyz/
var gita = {}; // bring the content from the previous version of the JSON
// has a dependency of lodash
var getSlokaNumber = function (s, sloka) {
var slokaNumber = parseInt(s, 10) + 1;
var re = /\(([0-9]+)\)/gm;
if (sloka.Content.match(re)) {
var regexExecResult, slokaNumbers = [];
while ((regexExecResult = re.exec(sloka.Content)) !== null) {
slokaNumbers.push(regexExecResult[1]);
}
slokaNumber = slokaNumbers.join(', ');
}
return ((slokaNumber.toString().indexOf(',') > -1) ? 'ശ്ലോകങ്ങൾ ' : 'ശ്ലോകം ') + slokaNumber;
};
var getSlokaCount = function (s, sloka) {
var slokaCount = 1;
var re = /\(([0-9]+)\)/gm;
if (sloka.Content.match(re)) {
var regexExecResult, slokaNumbers = [];
while ((regexExecResult = re.exec(sloka.Content)) !== null) {
slokaNumbers.push(regexExecResult[1]);
}
slokaCount = slokaNumbers.length;
}
return slokaCount;
};
var output = {};
var processGita = function (gita, output) {
var chapters = [];
_.forEach(gita.Chapters, function (originalChapter, chapterIndex) {
var chapter = originalChapter;
var sections = [];
var chapterSlokasCount = 0;
_.forEach(chapter.Sections, function (originalSection, sectionIndex) {
var section = originalSection;
section.SectionSerial = section.SlokaCount;
delete section.SlokaCount;
section.SlokasCount = getSlokaCount(sectionIndex, section);
section.SlokaNumber = getSlokaNumber(sectionIndex, section);
chapterSlokasCount += section.SlokasCount;
sections.push(section);
});
chapter.Sections = sections;
chapter.ChapterSerial = chapter.ChapterCount;
delete chapter.ChapterCount;
chapter.SlokasCount = chapterSlokasCount;
chapters.push(chapter);
});
output.Chapters = chapters;
output.OriginalBookTitle = gita.OriginalBookTitle;
output.BookTitle = gita.BookTitle;
return output;
}
output = processGita(gita, output);
document.getElementById('output').innerHTML = JSON.stringify(output, null, 4);