locutus 2.0.34 → 2.0.35

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.
@@ -1,3 +1,5 @@
1
1
  module.exports.int = require('./int')
2
2
  module.exports.length = require('./length')
3
3
  module.exports.substr = require('./substr')
4
+ module.exports.tolower = require('./tolower')
5
+ module.exports.toupper = require('./toupper')
@@ -0,0 +1,11 @@
1
+ module.exports = function tolower(s) {
2
+ // discuss at: https://locutus.io/awk/tolower/
3
+ // parity verified: GNU AWK 5.3
4
+ // original by: Kevin van Zonneveld (https://kvz.io)
5
+ // example 1: tolower('HELLO')
6
+ // returns 1: 'hello'
7
+ // example 2: tolower('Hello World')
8
+ // returns 2: 'hello world'
9
+
10
+ return String(s).toLowerCase()
11
+ }
@@ -0,0 +1,11 @@
1
+ module.exports = function toupper(s) {
2
+ // discuss at: https://locutus.io/awk/toupper/
3
+ // parity verified: GNU AWK 5.3
4
+ // original by: Kevin van Zonneveld (https://kvz.io)
5
+ // example 1: toupper('hello')
6
+ // returns 1: 'HELLO'
7
+ // example 2: toupper('Hello World')
8
+ // returns 2: 'HELLO WORLD'
9
+
10
+ return String(s).toUpperCase()
11
+ }
@@ -0,0 +1,3 @@
1
+ module.exports.lower = require('./lower')
2
+ module.exports.sub = require('./sub')
3
+ module.exports.upper = require('./upper')
@@ -0,0 +1,11 @@
1
+ module.exports = function lower(s) {
2
+ // discuss at: https://locutus.io/lua/lower/
3
+ // parity verified: Lua 5.4
4
+ // original by: Kevin van Zonneveld (https://kvz.io)
5
+ // example 1: lower('HELLO')
6
+ // returns 1: 'hello'
7
+ // example 2: lower('Hello World')
8
+ // returns 2: 'hello world'
9
+
10
+ return String(s).toLowerCase()
11
+ }
@@ -0,0 +1,33 @@
1
+ module.exports = function sub(s, i, j) {
2
+ // discuss at: https://locutus.io/lua/sub/
3
+ // parity verified: Lua 5.4
4
+ // original by: Kevin van Zonneveld (https://kvz.io)
5
+ // note 1: Lua uses 1-based indexing, negative indices count from end
6
+ // example 1: sub('Hello', 1, 3)
7
+ // returns 1: 'Hel'
8
+ // example 2: sub('Hello', 2)
9
+ // returns 2: 'ello'
10
+ // example 3: sub('Hello', -2)
11
+ // returns 3: 'lo'
12
+
13
+ s = String(s)
14
+ const len = s.length
15
+
16
+ // Convert Lua 1-based index to JS 0-based
17
+ // Negative indices count from end in Lua
18
+ let start = i < 0 ? len + i : i - 1
19
+ let end = j === undefined ? len : j < 0 ? len + j + 1 : j
20
+
21
+ // Clamp to valid range
22
+ if (start < 0) {
23
+ start = 0
24
+ }
25
+ if (end > len) {
26
+ end = len
27
+ }
28
+ if (start >= end) {
29
+ return ''
30
+ }
31
+
32
+ return s.substring(start, end)
33
+ }
@@ -0,0 +1,11 @@
1
+ module.exports = function upper(s) {
2
+ // discuss at: https://locutus.io/lua/upper/
3
+ // parity verified: Lua 5.4
4
+ // original by: Kevin van Zonneveld (https://kvz.io)
5
+ // example 1: upper('hello')
6
+ // returns 1: 'HELLO'
7
+ // example 2: upper('Hello World')
8
+ // returns 2: 'HELLO WORLD'
9
+
10
+ return String(s).toUpperCase()
11
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "locutus",
3
- "version": "2.0.34",
3
+ "version": "2.0.35",
4
4
  "description": "Locutus other languages' standard libraries to JavaScript for fun and educational purposes",
5
5
  "keywords": [
6
6
  "php",