@ntlab/sipd-agr 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +236 -0
- package/app/configuration.js +153 -0
- package/app/index.js +94 -0
- package/assets/enable-macro.png +0 -0
- package/assets/formating-message.png +0 -0
- package/assets/run-selected-macro.png +0 -0
- package/assets/summarize-confirm.png +0 -0
- package/assets/summarize-finish.png +0 -0
- package/assets/summarize-result.png +0 -0
- package/assets/view-macro.png +0 -0
- package/config/default.json +8 -0
- package/config.json +3 -0
- package/main.js +47 -0
- package/package.json +19 -0
- package/profiles.json +29 -0
- package/sipd/index.js +257 -0
- package/sipd/modules/agr/index.js +229 -0
- package/sipd/modules/agr/writer.js +136 -0
- package/sipd/modules/app.js +161 -0
- package/sipd/modules/ref/keg.js +72 -0
- package/sipd/modules/ref/ref.js +91 -0
- package/sipd/modules/ref/rek.js +38 -0
- package/sipd/modules/refs.js +187 -0
- package/sipd/modules/subkeg.js +221 -0
- package/sipd/script.js +73 -0
- package/sipd/util.js +146 -0
- package/tools/Agr.xlsm +0 -0
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2022-2025 Toha <tohenk@yahoo.com>
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
7
|
+
* this software and associated documentation files (the "Software"), to deal in
|
|
8
|
+
* the Software without restriction, including without limitation the rights to
|
|
9
|
+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
10
|
+
* of the Software, and to permit persons to whom the Software is furnished to do
|
|
11
|
+
* so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const fs = require('fs');
|
|
26
|
+
const { glob } = require('glob');
|
|
27
|
+
const path = require('path');
|
|
28
|
+
const Queue = require('@ntlab/work/queue');
|
|
29
|
+
const Sipd = require('..');
|
|
30
|
+
const SipdAgr = require('./agr');
|
|
31
|
+
const SipdUtil = require('../util');
|
|
32
|
+
const debug = require('debug')('sipdagr:subkeg');
|
|
33
|
+
|
|
34
|
+
class SipdSubkeg {
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Constructor.
|
|
38
|
+
*
|
|
39
|
+
* @param {Sipd} owner The owner
|
|
40
|
+
*/
|
|
41
|
+
constructor(owner) {
|
|
42
|
+
this.owner = owner;
|
|
43
|
+
this.agr = new SipdAgr();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
download(outdir, subkeg, skipDownload) {
|
|
47
|
+
if (!fs.existsSync(outdir)) {
|
|
48
|
+
fs.mkdirSync(outdir);
|
|
49
|
+
}
|
|
50
|
+
return this.owner.works([
|
|
51
|
+
[w => this.downloadKegList(outdir, subkeg), w => !skipDownload],
|
|
52
|
+
[w => this.importAgr(outdir)],
|
|
53
|
+
]);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
downloadKegList(outdir, subkeg) {
|
|
57
|
+
console.log('Downloading list...');
|
|
58
|
+
return this.owner.works([
|
|
59
|
+
[w => this.owner.app.clickMenu('Penganggaran | Sub Kegiatan Belanja', {click: false})],
|
|
60
|
+
[w => this.owner.waitForResponse('/api/renja/sub_bl/list_belanja_by_tahun_daerah_unit', {encoded: false})],
|
|
61
|
+
[w => new Promise((resolve, reject) => {
|
|
62
|
+
const f = a => `${a.kode_sub_skpd}-${a.kode_sub_giat}`;
|
|
63
|
+
let items = w.getRes(1);
|
|
64
|
+
const filters = [];
|
|
65
|
+
// apply filter: unit, prog, keg, and subkeg (in dotted format)
|
|
66
|
+
for (const opts of [
|
|
67
|
+
['unit', 'kode_skpd', 'kode_sub_skpd'],
|
|
68
|
+
['prog', 'kode_program'],
|
|
69
|
+
['keg', 'kode_giat'],
|
|
70
|
+
['subkeg', 'kode_sub_giat'],
|
|
71
|
+
]) {
|
|
72
|
+
const opt = opts.shift();
|
|
73
|
+
if (this.owner.options[opt]) {
|
|
74
|
+
filters.push(opt);
|
|
75
|
+
const values = Array.isArray(this.owner.options[opt]) ? this.owner.options[opt] : [this.owner.options[opt]];
|
|
76
|
+
items = items.filter(a => {
|
|
77
|
+
const datas = opts.map(k => a[k]);
|
|
78
|
+
for (const v of values) {
|
|
79
|
+
if (datas.includes(v)) {
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return false;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (items.length) {
|
|
88
|
+
items.sort((a, b) => f(a).localeCompare(f(b)));
|
|
89
|
+
const q = new Queue(items, item => {
|
|
90
|
+
let doit = SipdUtil.makeFloat(item.rincian) > 0;
|
|
91
|
+
if (doit && subkeg) {
|
|
92
|
+
if (Array.isArray(subkeg)) {
|
|
93
|
+
doit = subkeg.indexOf(SipdUtil.cleanKode(item.kode_sub_giat)) >= 0;
|
|
94
|
+
} else {
|
|
95
|
+
doit = subkeg === SipdUtil.cleanKode(item.kode_sub_giat);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (doit) {
|
|
99
|
+
this.owner.works([
|
|
100
|
+
[x => this.downloadKeg(outdir, item)],
|
|
101
|
+
])
|
|
102
|
+
.then(() => q.next())
|
|
103
|
+
.catch(err => reject(err));
|
|
104
|
+
} else {
|
|
105
|
+
q.next();
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
q.once('done', () => resolve(true));
|
|
109
|
+
} else {
|
|
110
|
+
reject(`Nothing to download when applying ${filters.join(', ')} filter!`)
|
|
111
|
+
}
|
|
112
|
+
})],
|
|
113
|
+
]);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
downloadKeg(outdir, data, options) {
|
|
117
|
+
options = options || {};
|
|
118
|
+
const maxretry = options.retry !== undefined ? options.retry : 10;
|
|
119
|
+
const timeout = options.timeout !== undefined ? options.timeout : 30000;
|
|
120
|
+
const keg = data.kode_sub_giat;
|
|
121
|
+
const title = data.nama_sub_giat
|
|
122
|
+
const url = `${this.owner.url}/penganggaran/anggaran/cascading/rincian/sub-kegiatan/${data.id_sub_bl}`;
|
|
123
|
+
const fname = SipdUtil.cleanKode(keg);
|
|
124
|
+
outdir = path.join(outdir, data.kode_sub_skpd);
|
|
125
|
+
if (!fs.existsSync(outdir)) {
|
|
126
|
+
fs.mkdirSync(outdir);
|
|
127
|
+
}
|
|
128
|
+
if (this.skpd !== data.kode_sub_skpd) {
|
|
129
|
+
this.skpd = data.kode_sub_skpd;
|
|
130
|
+
console.log('-- %s --', data.nama_sub_skpd);
|
|
131
|
+
}
|
|
132
|
+
let retry = maxretry;
|
|
133
|
+
const s = title.replace(/\n+/g, ' ');
|
|
134
|
+
console.log('Downloading %s...', s);
|
|
135
|
+
return new Promise((resolve, reject) => {
|
|
136
|
+
const f = () => {
|
|
137
|
+
this.owner.works([
|
|
138
|
+
[w => this.owner.getDriver().get(url)],
|
|
139
|
+
[w => this.owner.waitForResponse([
|
|
140
|
+
'/api/renja/rinci_sub_bl/get_by_id_sub_bl',
|
|
141
|
+
'/api/renja/subs_sub_bl/find_by_id_list',
|
|
142
|
+
'/api/renja/ket_sub_bl/find_by_id_list',
|
|
143
|
+
], {timeout})],
|
|
144
|
+
[w => this.mergeDataset(w.getRes(1)[0], w.getRes(1)[1], w.getRes(1)[2])],
|
|
145
|
+
[w => Promise.resolve(fs.writeFileSync(path.join(outdir, fname + '.meta'), JSON.stringify(data, null, 2)))],
|
|
146
|
+
[w => Promise.resolve(fs.writeFileSync(path.join(outdir, fname + '.json'), JSON.stringify(w.getRes(1)[0], null, 2)))],
|
|
147
|
+
])
|
|
148
|
+
.then(res => resolve(res))
|
|
149
|
+
.catch(err => {
|
|
150
|
+
debug('%s: %s', s, err);
|
|
151
|
+
if (--retry) {
|
|
152
|
+
console.log('Downloading %s (retry %d of %d)...', s, maxretry - retry + 1, maxretry);
|
|
153
|
+
f();
|
|
154
|
+
} else {
|
|
155
|
+
reject(err);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
f();
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
mergeDataset(rinci, sub, ket) {
|
|
164
|
+
return new Promise((resolve, reject) => {
|
|
165
|
+
const subs = {}, kets = {};
|
|
166
|
+
sub.forEach(item => {
|
|
167
|
+
subs[item.id_subs_sub_bl] = item.subs_bl_teks;
|
|
168
|
+
});
|
|
169
|
+
ket.forEach(item => {
|
|
170
|
+
kets[item.id_ket_sub_bl] = item.ket_bl_teks;
|
|
171
|
+
});
|
|
172
|
+
for (const r of rinci) {
|
|
173
|
+
if (subs[r.id_subs_sub_bl] !== undefined) {
|
|
174
|
+
r.subs_bl_teks = subs[r.id_subs_sub_bl];
|
|
175
|
+
}
|
|
176
|
+
if (kets[r.id_ket_sub_bl] !== undefined) {
|
|
177
|
+
r.ket_bl_teks = kets[r.id_ket_sub_bl];
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
resolve(rinci);
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
importAgr(outdir) {
|
|
185
|
+
return this.owner.works([
|
|
186
|
+
[w => glob(path.join(outdir, '*', '*.json'), {withFileTypes: true, windowsPathsNoEscape: true})],
|
|
187
|
+
[w => new Promise((resolve, reject) => {
|
|
188
|
+
let count = 0;
|
|
189
|
+
const files = w.getRes(0);
|
|
190
|
+
const q = new Queue(files, f => {
|
|
191
|
+
const data = JSON.parse(fs.readFileSync(path.join(f.path, f.name)));
|
|
192
|
+
const metadata = JSON.parse(fs.readFileSync(path.join(f.path, f.name.replace('.json', '.meta'))));
|
|
193
|
+
this.agr.clear();
|
|
194
|
+
this.agr.import(data, metadata);
|
|
195
|
+
this.agr.exportXls(f.path)
|
|
196
|
+
.then(() => {
|
|
197
|
+
count++;
|
|
198
|
+
q.next();
|
|
199
|
+
})
|
|
200
|
+
.catch(err => reject(err))
|
|
201
|
+
;
|
|
202
|
+
});
|
|
203
|
+
q.once('done', () => {
|
|
204
|
+
console.log('Done importing %d files...', count);
|
|
205
|
+
resolve(count)
|
|
206
|
+
});
|
|
207
|
+
})]
|
|
208
|
+
]);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
exportXls(outdir) {
|
|
212
|
+
return new Promise((resolve, reject) => {
|
|
213
|
+
this.agr.exportXls(outdir)
|
|
214
|
+
.then(() => resolve())
|
|
215
|
+
.catch(err => reject(err))
|
|
216
|
+
;
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
module.exports = SipdSubkeg;
|
package/sipd/script.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2022-2025 Toha <tohenk@yahoo.com>
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
7
|
+
* this software and associated documentation files (the "Software"), to deal in
|
|
8
|
+
* the Software without restriction, including without limitation the rights to
|
|
9
|
+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
10
|
+
* of the Software, and to permit persons to whom the Software is furnished to do
|
|
11
|
+
* so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
class SipdScript {
|
|
26
|
+
|
|
27
|
+
static bootstrapModal(title, message, button = 'Oke') {
|
|
28
|
+
let id = 'x-modal-' + parseInt(Math.random() * 1000000 + 1);
|
|
29
|
+
return `
|
|
30
|
+
$(document.body).append(\`
|
|
31
|
+
<ngb-modal-window id="${id}" class="d-block modal fade show" tabindex="-1" role="dialog">
|
|
32
|
+
<div class="modal-dialog modal-md" role="document">
|
|
33
|
+
<div class="modal-content">
|
|
34
|
+
<div class="modal-header py-2">
|
|
35
|
+
<h2 class="modal-title fw-bold">${title}</h2>
|
|
36
|
+
<button type="button" class="btn-close" aria-label="Close" onclick="const dlg=document.querySelector('#${id}');dlg.remove();return false;"></button>
|
|
37
|
+
</div>
|
|
38
|
+
<div class="modal-body">
|
|
39
|
+
<p class="fs-1 fw-bold text-danger">${message}</p>
|
|
40
|
+
</div>
|
|
41
|
+
</div>
|
|
42
|
+
</div>
|
|
43
|
+
</ngb-modal-window>\`);
|
|
44
|
+
if (!$.modalStyleIncluded) {
|
|
45
|
+
$.modalStyleIncluded = true;
|
|
46
|
+
// https://stackoverflow.com/questions/18422223/bootstrap-3-modal-vertical-position-center
|
|
47
|
+
$(document.head).append(\`
|
|
48
|
+
<style>
|
|
49
|
+
@media screen and (min-width: 768px) {
|
|
50
|
+
.modal:before {
|
|
51
|
+
display: inline-block;
|
|
52
|
+
vertical-align: middle;
|
|
53
|
+
content: " ";
|
|
54
|
+
height: 100%;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
.modal {
|
|
58
|
+
text-align: center;
|
|
59
|
+
}
|
|
60
|
+
.modal-dialog {
|
|
61
|
+
display: inline-block;
|
|
62
|
+
text-align: left;
|
|
63
|
+
vertical-align: middle;
|
|
64
|
+
}
|
|
65
|
+
</style>
|
|
66
|
+
\`
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
`;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
module.exports = SipdScript;
|
package/sipd/util.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2022-2025 Toha <tohenk@yahoo.com>
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
7
|
+
* this software and associated documentation files (the "Software"), to deal in
|
|
8
|
+
* the Software without restriction, including without limitation the rights to
|
|
9
|
+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
10
|
+
* of the Software, and to permit persons to whom the Software is furnished to do
|
|
11
|
+
* so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
class SipdUtil {
|
|
26
|
+
|
|
27
|
+
static cleanText(text) {
|
|
28
|
+
if (typeof text === 'string') {
|
|
29
|
+
if (text.substr(0, 3) === '[-]' || text.substr(0, 3) === '[#]') {
|
|
30
|
+
text = text.substr(3).trim();
|
|
31
|
+
}
|
|
32
|
+
if (text) {
|
|
33
|
+
text = this.decodeEntities(text);
|
|
34
|
+
text = this.cleanDup(text, '\'"');
|
|
35
|
+
}
|
|
36
|
+
let stage = 0
|
|
37
|
+
while (true) {
|
|
38
|
+
if (stage > 1) {
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
const c = stage === 0 ? text.substr(0, 1) : text.substr(-1);
|
|
42
|
+
if (this.cleanses.indexOf(c) >= 0) {
|
|
43
|
+
// check for quote
|
|
44
|
+
if (stage > 0 && c === '"') {
|
|
45
|
+
if (text.indexOf('"') > 0 && text.indexOf('"') < text.length - 1) {
|
|
46
|
+
stage++;
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
text = stage === 0 ? text.substr(1) : text.substr(0, text.length - 1);
|
|
51
|
+
} else {
|
|
52
|
+
stage++;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return text;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
static cleanKode(kode) {
|
|
60
|
+
let result = '';
|
|
61
|
+
if (typeof kode === 'string') {
|
|
62
|
+
for (let i = 0; i < kode.length; i++) {
|
|
63
|
+
if (kode.charAt(i).match(/[A-Za-z0-9]/)) {
|
|
64
|
+
result += kode.charAt(i);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static cleanDup(str, c) {
|
|
72
|
+
str = str.trim();
|
|
73
|
+
if (str) {
|
|
74
|
+
for (let i = 0; i < c.length; i++) {
|
|
75
|
+
let d = c[i];
|
|
76
|
+
let dup = d + d;
|
|
77
|
+
while (str.indexOf(dup) >= 0) str = str.replace(dup, d);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return str;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
static splitKode(s) {
|
|
84
|
+
let p = s.indexOf(' ');
|
|
85
|
+
if (p >=0) {
|
|
86
|
+
return [s.substr(0, p).trim(), s.substr(p).trim()]
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
static padnum(num, len) {
|
|
91
|
+
let str = num.toString();
|
|
92
|
+
while (str.length < len) {
|
|
93
|
+
str = '0' + str;
|
|
94
|
+
}
|
|
95
|
+
return str;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
static makeFloat(value) {
|
|
99
|
+
if (value) {
|
|
100
|
+
value = parseFloat(value);
|
|
101
|
+
}
|
|
102
|
+
return value;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
static floatValue(value) {
|
|
106
|
+
if (value != undefined && value != null) {
|
|
107
|
+
if (value - Math.trunc(value) > 0) {
|
|
108
|
+
value = value.toString().replace('.', ',');
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return value;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// https://stackoverflow.com/questions/44195322/a-plain-javascript-way-to-decode-html-entities-works-on-both-browsers-and-node
|
|
115
|
+
static decodeEntities(encodedString) {
|
|
116
|
+
let translate_re = /&(nbsp|amp|quot|lt|gt);/g;
|
|
117
|
+
let translate = {
|
|
118
|
+
"nbsp": " ",
|
|
119
|
+
"amp" : "&",
|
|
120
|
+
"quot": "\"",
|
|
121
|
+
"lt" : "<",
|
|
122
|
+
"gt" : ">"
|
|
123
|
+
};
|
|
124
|
+
return encodedString
|
|
125
|
+
.replace(translate_re, (match, entity) => {
|
|
126
|
+
return translate[entity];
|
|
127
|
+
})
|
|
128
|
+
.replace(/&#(\d+);/gi, (match, numStr) => {
|
|
129
|
+
let num = parseInt(numStr, 10);
|
|
130
|
+
return String.fromCharCode(num);
|
|
131
|
+
})
|
|
132
|
+
;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
static isAlamat(s) {
|
|
136
|
+
if (s) {
|
|
137
|
+
return s.toLowerCase().match(/(kota|kab(upaten)?|kec(amatan)?|desa|ds|kel(urahan)?)(\.)?\s/g);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
static get cleanses() {
|
|
142
|
+
return ['\'', '"', ',', '.', '~', '!', '@', '#', '$', '%', '^', '&', '*'];
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
module.exports = SipdUtil;
|
package/tools/Agr.xlsm
ADDED
|
Binary file
|