locutus 2.0.35 → 2.0.36
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/package.json +1 -1
- package/perl/core/index.js +3 -0
- package/perl/core/lc.js +11 -0
- package/perl/core/substr.js +44 -0
- package/perl/core/uc.js +11 -0
package/package.json
CHANGED
package/perl/core/index.js
CHANGED
package/perl/core/lc.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module.exports = function lc(str) {
|
|
2
|
+
// discuss at: https://locutus.io/perl/lc/
|
|
3
|
+
// parity verified: Perl 5.40
|
|
4
|
+
// original by: Kevin van Zonneveld (https://kvz.io)
|
|
5
|
+
// example 1: lc('HELLO')
|
|
6
|
+
// returns 1: 'hello'
|
|
7
|
+
// example 2: lc('Hello World')
|
|
8
|
+
// returns 2: 'hello world'
|
|
9
|
+
|
|
10
|
+
return String(str).toLowerCase()
|
|
11
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
module.exports = function substr(str, offset, length) {
|
|
2
|
+
// discuss at: https://locutus.io/perl/substr/
|
|
3
|
+
// parity verified: Perl 5.40
|
|
4
|
+
// original by: Kevin van Zonneveld (https://kvz.io)
|
|
5
|
+
// note 1: Perl's offset is 0-based, negative counts from end
|
|
6
|
+
// example 1: substr('hello', 0, 3)
|
|
7
|
+
// returns 1: 'hel'
|
|
8
|
+
// example 2: substr('hello', 1)
|
|
9
|
+
// returns 2: 'ello'
|
|
10
|
+
// example 3: substr('hello', -2)
|
|
11
|
+
// returns 3: 'lo'
|
|
12
|
+
|
|
13
|
+
str = String(str)
|
|
14
|
+
const len = str.length
|
|
15
|
+
|
|
16
|
+
// Handle negative offset (count from end)
|
|
17
|
+
let start = offset < 0 ? len + offset : offset
|
|
18
|
+
|
|
19
|
+
// Clamp start to valid range
|
|
20
|
+
if (start < 0) {
|
|
21
|
+
start = 0
|
|
22
|
+
}
|
|
23
|
+
if (start > len) {
|
|
24
|
+
return ''
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// If length is undefined, return rest of string
|
|
28
|
+
if (length === undefined) {
|
|
29
|
+
return str.substring(start)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Handle negative length (leave that many chars at end)
|
|
33
|
+
let end
|
|
34
|
+
if (length < 0) {
|
|
35
|
+
end = len + length
|
|
36
|
+
if (end < start) {
|
|
37
|
+
return ''
|
|
38
|
+
}
|
|
39
|
+
} else {
|
|
40
|
+
end = start + length
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return str.substring(start, end)
|
|
44
|
+
}
|
package/perl/core/uc.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module.exports = function uc(str) {
|
|
2
|
+
// discuss at: https://locutus.io/perl/uc/
|
|
3
|
+
// parity verified: Perl 5.40
|
|
4
|
+
// original by: Kevin van Zonneveld (https://kvz.io)
|
|
5
|
+
// example 1: uc('hello')
|
|
6
|
+
// returns 1: 'HELLO'
|
|
7
|
+
// example 2: uc('Hello World')
|
|
8
|
+
// returns 2: 'HELLO WORLD'
|
|
9
|
+
|
|
10
|
+
return String(str).toUpperCase()
|
|
11
|
+
}
|