bajo-extra 2.3.0 → 2.5.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/extend/bajo/intl/en-US.json +3 -1
- package/extend/bajo/intl/id.json +3 -1
- package/index.js +62 -0
- package/package.json +2 -1
- package/wiki/CHANGES.md +10 -0
|
@@ -18,5 +18,7 @@
|
|
|
18
18
|
"decryption type": "decryption type",
|
|
19
19
|
"fetching%s": "Fetching %s",
|
|
20
20
|
"peerError%s": "Peer error: %s",
|
|
21
|
-
"disabled%s": "%s is disabled"
|
|
21
|
+
"disabled%s": "%s is disabled",
|
|
22
|
+
"tnUnsupportedFormat%s%s": "Unsupported thumbnail format in '%s', available: %s",
|
|
23
|
+
"tnInvalidSize%s%s": "Unsupported thumbnail size '%s' for '%s'"
|
|
22
24
|
}
|
package/extend/bajo/intl/id.json
CHANGED
|
@@ -18,5 +18,7 @@
|
|
|
18
18
|
"decryption type": "Tipe dekripsi",
|
|
19
19
|
"fetching%s": "Fetching %s",
|
|
20
20
|
"peerError%s": "Kesalahan dari peer: %s",
|
|
21
|
-
"disabled%s": "%s dinonaktifkan"
|
|
21
|
+
"disabled%s": "%s dinonaktifkan",
|
|
22
|
+
"tnUnsupportedFormat%s%s": "Format thumbnail tidak didukung di '%s', tersedia: %s",
|
|
23
|
+
"tnInvalidSize%s%s": "Ukuran thumbnail '%s' tidak didukung, tersedia: '%s'"
|
|
22
24
|
}
|
package/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import { createGzip, createGunzip } from 'zlib'
|
|
|
3
3
|
import path from 'path'
|
|
4
4
|
import { Readable } from 'stream'
|
|
5
5
|
import numbro from 'numbro'
|
|
6
|
+
import sharp from 'sharp'
|
|
6
7
|
|
|
7
8
|
async function fetching ({ url, opts, bulk, spin }) {
|
|
8
9
|
const { setImmediate, print } = this.app.bajo
|
|
@@ -129,6 +130,10 @@ async function factory (pkgName) {
|
|
|
129
130
|
autoSelectFamilyAttemptTimeout: 1000,
|
|
130
131
|
autoSelectFamily: true
|
|
131
132
|
}
|
|
133
|
+
},
|
|
134
|
+
thumbnail: {
|
|
135
|
+
inputFormats: ['.png', '.jpg', '.jpeg', '.webp', '.gif', '.avif', '.tiff', '.svg'],
|
|
136
|
+
outputFormats: ['.png']
|
|
132
137
|
}
|
|
133
138
|
}
|
|
134
139
|
}
|
|
@@ -366,6 +371,10 @@ async function factory (pkgName) {
|
|
|
366
371
|
return /^[a-f0-9]{64}$/i.test(text)
|
|
367
372
|
}
|
|
368
373
|
|
|
374
|
+
isHtmlLink = (text) => {
|
|
375
|
+
return /<a\s+[^>]*href="([^"]*)"[^>]*>(.*?)<\/a>/gi.test(text)
|
|
376
|
+
}
|
|
377
|
+
|
|
369
378
|
encrypt = async (text, { type = 'short', subType = 'qr' } = {}) => {
|
|
370
379
|
const { importPkg } = this.app.bajo
|
|
371
380
|
const { ShortCrypt } = await importPkg('bajoExtra:short-crypt')
|
|
@@ -399,6 +408,59 @@ async function factory (pkgName) {
|
|
|
399
408
|
if (!alpha) return num
|
|
400
409
|
return String.fromCharCode(96 + num)
|
|
401
410
|
}
|
|
411
|
+
|
|
412
|
+
thumbnailSizes = name => {
|
|
413
|
+
switch (name) {
|
|
414
|
+
case 's': return [36, 36]
|
|
415
|
+
case 'm': return [100, 100]
|
|
416
|
+
case 'l': return [250, 250]
|
|
417
|
+
default: {
|
|
418
|
+
const [w, h] = name.split('x').map(s => parseInt(s))
|
|
419
|
+
if (!w || !h) return [0, 0]
|
|
420
|
+
return [w, h]
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
createThumbnail = async (file, options = {}) => {
|
|
426
|
+
const { fs } = this.app.lib
|
|
427
|
+
const { isString } = this.app.lib._
|
|
428
|
+
let {
|
|
429
|
+
dir = path.dirname(file),
|
|
430
|
+
silent = true,
|
|
431
|
+
size = this.config.thumbnail.sizes,
|
|
432
|
+
format = this.config.thumbnail.outputFormats,
|
|
433
|
+
opts = {}
|
|
434
|
+
} = options
|
|
435
|
+
if (isString(size)) size = [size]
|
|
436
|
+
if (isString(format)) format = [format]
|
|
437
|
+
const ext = path.extname(file)
|
|
438
|
+
|
|
439
|
+
if (!this.config.thumbnail.inputFormats.includes(ext)) {
|
|
440
|
+
if (silent) return
|
|
441
|
+
throw this.error('tnUnsupportedFormat%s%s', file, this.config.thumbnail.inputFormats)
|
|
442
|
+
}
|
|
443
|
+
const base = path.basename(file, ext)
|
|
444
|
+
fs.ensureDirSync(dir)
|
|
445
|
+
for (const s of size) {
|
|
446
|
+
const [w, h] = this.thumbnailSizes(s)
|
|
447
|
+
if (w === 0 || h === 0) {
|
|
448
|
+
if (silent) continue
|
|
449
|
+
throw this.error('tnInvalidSize%s%s', file, [...size, '<width>x<height>'])
|
|
450
|
+
}
|
|
451
|
+
for (const to of format) {
|
|
452
|
+
const dest = `${dir}/${base}-${s}${to}`
|
|
453
|
+
try {
|
|
454
|
+
await sharp(file)
|
|
455
|
+
.resize(w, h, opts)
|
|
456
|
+
.toFile(dest)
|
|
457
|
+
} catch (err) {
|
|
458
|
+
if (silent) continue
|
|
459
|
+
throw err
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
}
|
|
402
464
|
}
|
|
403
465
|
|
|
404
466
|
return BajoExtra
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bajo-extra",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"description": "Extra package for Bajo Framework",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"fast-xml-parser": "^5.3.3",
|
|
39
39
|
"numbro": "^2.5.0",
|
|
40
40
|
"performant-array-to-tree": "^1.11.0",
|
|
41
|
+
"sharp": "^0.34.5",
|
|
41
42
|
"short-crypt": "^4.0.0",
|
|
42
43
|
"undici": "^7.16.0"
|
|
43
44
|
},
|
package/wiki/CHANGES.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2026-05-03
|
|
4
|
+
|
|
5
|
+
- [2.5.0] Add ```isHtmlLink```
|
|
6
|
+
|
|
7
|
+
## 2026-05-02
|
|
8
|
+
|
|
9
|
+
- [2.4.0] Add ```sharp``` as library
|
|
10
|
+
- [2.4.0] Add ```thumbnailSizes()```
|
|
11
|
+
- [2.4.0] Add ```createThumbnail()```
|
|
12
|
+
|
|
3
13
|
## 2026-04-25
|
|
4
14
|
|
|
5
15
|
- [2.3.0] Add ```isSha256()```
|