@quenty/string 2.0.1-canary.9c1fd3b.0 → 2.2.1-canary.238.2c4d310.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/CHANGELOG.md +23 -1
- package/LICENSE.md +1 -1
- package/README.md +2 -2
- package/package.json +2 -2
- package/src/Shared/String.lua +102 -7
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
## [2.
|
|
6
|
+
## [2.2.1-canary.238.2c4d310.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/string@2.2.0...@quenty/string@2.2.1-canary.238.2c4d310.0) (2021-12-29)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @quenty/string
|
|
9
9
|
|
|
@@ -11,6 +11,28 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
+
# [2.2.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/string@2.1.0...@quenty/string@2.2.0) (2021-11-10)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
* Add string.startsWith ([eb51da1](https://github.com/Quenty/NevermoreEngine/commit/eb51da1907f28bda5a843d7fa39fe4d9d9ce9938))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# [2.1.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/string@2.0.0...@quenty/string@2.1.0) (2021-09-22)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Bug Fixes
|
|
29
|
+
|
|
30
|
+
* Add new string feature ([fc8d68c](https://github.com/Quenty/NevermoreEngine/commit/fc8d68c11b6cd7fc5dacc86f3229e81f481452f6))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
14
36
|
# [2.0.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/string@1.2.0...@quenty/string@2.0.0) (2021-09-05)
|
|
15
37
|
|
|
16
38
|
|
package/LICENSE.md
CHANGED
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
## String
|
|
2
2
|
<div align="center">
|
|
3
|
-
<a href="http://quenty.github.io/
|
|
3
|
+
<a href="http://quenty.github.io/NevermoreEngine/">
|
|
4
4
|
<img src="https://img.shields.io/badge/docs-website-green.svg" alt="Documentation" />
|
|
5
5
|
</a>
|
|
6
6
|
<a href="https://discord.gg/mhtGUS8">
|
|
7
|
-
<img src="https://img.shields.io/
|
|
7
|
+
<img src="https://img.shields.io/discord/385151591524597761?color=5865F2&label=discord&logo=discord&logoColor=white" alt="Discord" />
|
|
8
8
|
</a>
|
|
9
9
|
<a href="https://github.com/Quenty/NevermoreEngine/actions">
|
|
10
10
|
<img src="https://github.com/Quenty/NevermoreEngine/actions/workflows/build.yml/badge.svg" alt="Build and release status" />
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/string",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.1-canary.238.2c4d310.0",
|
|
4
4
|
"description": "This module provides utility functions for strings",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"publishConfig": {
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "2c4d310b84afd0570d89667dc5d4aa69a0ef304a"
|
|
32
32
|
}
|
package/src/Shared/String.lua
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
--[=[
|
|
2
|
+
This module provides utility functions for strings
|
|
3
|
+
@class String
|
|
4
|
+
]=]
|
|
3
5
|
|
|
4
6
|
local String = {}
|
|
5
7
|
|
|
8
|
+
--[=[
|
|
9
|
+
Trims the string of the given pattern
|
|
10
|
+
|
|
11
|
+
@param str string
|
|
12
|
+
@param pattern string? -- Defaults to whitespace
|
|
13
|
+
@return string
|
|
14
|
+
]=]
|
|
6
15
|
function String.trim(str, pattern)
|
|
7
16
|
if not pattern then
|
|
8
17
|
return str:match("^%s*(.-)%s*$")
|
|
@@ -14,7 +23,11 @@ function String.trim(str, pattern)
|
|
|
14
23
|
end
|
|
15
24
|
end
|
|
16
25
|
|
|
17
|
-
|
|
26
|
+
--[=[
|
|
27
|
+
Converts the string to UpperCamelCase
|
|
28
|
+
@param str string
|
|
29
|
+
@return string
|
|
30
|
+
]=]
|
|
18
31
|
function String.toCamelCase(str)
|
|
19
32
|
str = str:lower()
|
|
20
33
|
str = str:gsub("[ _](%a)", string.upper)
|
|
@@ -24,10 +37,21 @@ function String.toCamelCase(str)
|
|
|
24
37
|
return str
|
|
25
38
|
end
|
|
26
39
|
|
|
40
|
+
|
|
41
|
+
--[=[
|
|
42
|
+
Uppercases the first letter of the string
|
|
43
|
+
@param str string
|
|
44
|
+
@return string
|
|
45
|
+
]=]
|
|
27
46
|
function String.uppercaseFirstLetter(str)
|
|
28
47
|
return str:gsub("^%a", string.upper)
|
|
29
48
|
end
|
|
30
49
|
|
|
50
|
+
--[=[
|
|
51
|
+
Converts to the string to lowerCamelCase
|
|
52
|
+
@param str string
|
|
53
|
+
@return string
|
|
54
|
+
]=]
|
|
31
55
|
function String.toLowerCamelCase(str)
|
|
32
56
|
str = str:lower()
|
|
33
57
|
str = str:gsub("[ _](%a)", string.upper)
|
|
@@ -37,16 +61,37 @@ function String.toLowerCamelCase(str)
|
|
|
37
61
|
return str
|
|
38
62
|
end
|
|
39
63
|
|
|
64
|
+
--[=[
|
|
65
|
+
Converts the string to _privateCamelCase
|
|
66
|
+
@param str string
|
|
67
|
+
@return string
|
|
68
|
+
]=]
|
|
40
69
|
function String.toPrivateCase(str)
|
|
41
70
|
return "_" .. str:sub(1, 1):lower() .. str:sub(2, #str)
|
|
42
71
|
end
|
|
43
72
|
|
|
44
|
-
--
|
|
73
|
+
--[=[
|
|
74
|
+
Like trim, but only applied to the beginning of the setring
|
|
75
|
+
@param str string
|
|
76
|
+
@param pattern string? -- Defaults to whitespace
|
|
77
|
+
@return string
|
|
78
|
+
]=]
|
|
45
79
|
function String.trimFront(str, pattern)
|
|
46
80
|
pattern = pattern or "%s";
|
|
47
81
|
return (str:gsub("^"..pattern.."*(.-)"..pattern.."*", "%1"))
|
|
48
82
|
end
|
|
49
83
|
|
|
84
|
+
--[=[
|
|
85
|
+
Counts the number of times a char appears in a string.
|
|
86
|
+
|
|
87
|
+
:::note
|
|
88
|
+
Note that this is not UTF8 safe
|
|
89
|
+
:::
|
|
90
|
+
|
|
91
|
+
@param str string
|
|
92
|
+
@param char string
|
|
93
|
+
@return number
|
|
94
|
+
]=]
|
|
50
95
|
function String.checkNumOfCharacterInString(str, char)
|
|
51
96
|
local count = 0
|
|
52
97
|
for _ in string.gmatch(str, char) do
|
|
@@ -55,17 +100,30 @@ function String.checkNumOfCharacterInString(str, char)
|
|
|
55
100
|
return count
|
|
56
101
|
end
|
|
57
102
|
|
|
58
|
-
|
|
103
|
+
--[=[
|
|
104
|
+
Checks if a string is empty or nil
|
|
105
|
+
@param str string
|
|
106
|
+
@return boolean
|
|
107
|
+
]=]
|
|
59
108
|
function String.isEmptyOrWhitespaceOrNil(str)
|
|
60
109
|
return type(str) ~= "string" or str == "" or String.isWhitespace(str)
|
|
61
110
|
end
|
|
62
111
|
|
|
63
|
-
|
|
112
|
+
--[=[
|
|
113
|
+
Returns whether or not text is only whitespace
|
|
114
|
+
@param str string
|
|
115
|
+
@return boolean
|
|
116
|
+
]=]
|
|
64
117
|
function String.isWhitespace(str)
|
|
65
118
|
return string.match(str, "[%s]+") == str
|
|
66
119
|
end
|
|
67
120
|
|
|
68
|
-
|
|
121
|
+
--[=[
|
|
122
|
+
Converts text to have a ... after it if it's too long.
|
|
123
|
+
@param str string
|
|
124
|
+
@param characterLimit number
|
|
125
|
+
@return string
|
|
126
|
+
]=]
|
|
69
127
|
function String.elipseLimit(str, characterLimit)
|
|
70
128
|
if #str > characterLimit then
|
|
71
129
|
str = str:sub(1, characterLimit-3).."..."
|
|
@@ -73,6 +131,12 @@ function String.elipseLimit(str, characterLimit)
|
|
|
73
131
|
return str
|
|
74
132
|
end
|
|
75
133
|
|
|
134
|
+
--[=[
|
|
135
|
+
Removes a prefix from a string if it exists
|
|
136
|
+
@param str string
|
|
137
|
+
@param prefix string
|
|
138
|
+
@return string
|
|
139
|
+
]=]
|
|
76
140
|
function String.removePrefix(str, prefix)
|
|
77
141
|
if str:sub(1, #prefix) == prefix then
|
|
78
142
|
return str:sub(#prefix + 1)
|
|
@@ -81,6 +145,12 @@ function String.removePrefix(str, prefix)
|
|
|
81
145
|
end
|
|
82
146
|
end
|
|
83
147
|
|
|
148
|
+
--[=[
|
|
149
|
+
Removes a postfix from a string if it exists
|
|
150
|
+
@param str string
|
|
151
|
+
@param postfix string
|
|
152
|
+
@return string
|
|
153
|
+
]=]
|
|
84
154
|
function String.removePostfix(str, postfix)
|
|
85
155
|
if str:sub(-#postfix) == postfix then
|
|
86
156
|
return str:sub(1, -#(postfix) - 1)
|
|
@@ -89,6 +159,31 @@ function String.removePostfix(str, postfix)
|
|
|
89
159
|
end
|
|
90
160
|
end
|
|
91
161
|
|
|
162
|
+
--[=[
|
|
163
|
+
Returns if a string ends with a postfix
|
|
164
|
+
@param str string
|
|
165
|
+
@param postfix string
|
|
166
|
+
@return boolean
|
|
167
|
+
]=]
|
|
168
|
+
function String.endsWith(str, postfix)
|
|
169
|
+
return str:sub(-#postfix) == postfix
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
--[=[
|
|
173
|
+
Returns if a string starts with a postfix
|
|
174
|
+
@param str string
|
|
175
|
+
@param prefix string
|
|
176
|
+
@return boolean
|
|
177
|
+
]=]
|
|
178
|
+
function String.startsWith(str, prefix)
|
|
179
|
+
return str:sub(1, #prefix) == prefix
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
--[=[
|
|
183
|
+
Adds commas to a number. Not culture aware.
|
|
184
|
+
@param number string | number
|
|
185
|
+
@return string
|
|
186
|
+
]=]
|
|
92
187
|
function String.addCommas(number)
|
|
93
188
|
if type(number) == "number" then
|
|
94
189
|
number = tostring(number)
|