@quenty/string 3.3.0 → 3.3.1-canary.542.7609692.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 +8 -0
- package/package.json +2 -2
- package/src/Shared/String.lua +22 -11
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
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
|
+
## [3.3.1-canary.542.7609692.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/string@3.3.0...@quenty/string@3.3.1-canary.542.7609692.0) (2025-03-13)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @quenty/string
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
# [3.3.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/string@3.2.0...@quenty/string@3.3.0) (2024-09-25)
|
|
7
15
|
|
|
8
16
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/string",
|
|
3
|
-
"version": "3.3.0",
|
|
3
|
+
"version": "3.3.1-canary.542.7609692.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": "76096921c6c965e5c4f9c796f97642d16d628c6b"
|
|
32
32
|
}
|
package/src/Shared/String.lua
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
--!strict
|
|
1
2
|
--[=[
|
|
2
3
|
This module provides utility functions for strings
|
|
3
4
|
@class String
|
|
@@ -13,13 +14,13 @@ local String = {}
|
|
|
13
14
|
@return string
|
|
14
15
|
]=]
|
|
15
16
|
function String.trim(str: string, pattern: string?): string
|
|
16
|
-
if
|
|
17
|
-
return
|
|
17
|
+
if pattern == nil then
|
|
18
|
+
return string.match(str, "^%s*(.-)%s*$") :: string
|
|
18
19
|
else
|
|
19
20
|
-- When we find the first non space character defined by ^%s
|
|
20
21
|
-- we yank out anything in between that and the end of the string
|
|
21
22
|
-- Everything else is replaced with %1 which is essentially nothing
|
|
22
|
-
return
|
|
23
|
+
return string.match(str, "^" .. pattern .. "*(.-)" .. pattern .. "*$")
|
|
23
24
|
end
|
|
24
25
|
end
|
|
25
26
|
|
|
@@ -76,8 +77,8 @@ end
|
|
|
76
77
|
@return string
|
|
77
78
|
]=]
|
|
78
79
|
function String.trimFront(str: string, pattern: string?): string
|
|
79
|
-
|
|
80
|
-
return (string.gsub(str, "^"..
|
|
80
|
+
local strPattern = pattern or "%s"
|
|
81
|
+
return (string.gsub(str, "^" .. strPattern .. "*(.-)" .. strPattern .. "*", "%1"))
|
|
81
82
|
end
|
|
82
83
|
|
|
83
84
|
--[=[
|
|
@@ -125,13 +126,14 @@ end
|
|
|
125
126
|
]=]
|
|
126
127
|
function String.elipseLimit(str: string, characterLimit: number): string
|
|
127
128
|
if #str > characterLimit then
|
|
128
|
-
str = string.sub(str, 1, characterLimit-3).."..."
|
|
129
|
+
str = string.sub(str, 1, characterLimit - 3) .. "..."
|
|
129
130
|
end
|
|
130
131
|
return str
|
|
131
132
|
end
|
|
132
133
|
|
|
133
134
|
--[=[
|
|
134
135
|
Removes a prefix from a string if it exists
|
|
136
|
+
|
|
135
137
|
@param str string
|
|
136
138
|
@param prefix string
|
|
137
139
|
@return string
|
|
@@ -146,13 +148,14 @@ end
|
|
|
146
148
|
|
|
147
149
|
--[=[
|
|
148
150
|
Removes a postfix from a string if it exists
|
|
151
|
+
|
|
149
152
|
@param str string
|
|
150
153
|
@param postfix string
|
|
151
154
|
@return string
|
|
152
155
|
]=]
|
|
153
156
|
function String.removePostfix(str: string, postfix: string): string
|
|
154
157
|
if string.sub(str, -#postfix) == postfix then
|
|
155
|
-
return string.sub(str, 1, -#
|
|
158
|
+
return string.sub(str, 1, -#postfix - 1)
|
|
156
159
|
else
|
|
157
160
|
return str
|
|
158
161
|
end
|
|
@@ -160,6 +163,7 @@ end
|
|
|
160
163
|
|
|
161
164
|
--[=[
|
|
162
165
|
Returns if a string ends with a postfix
|
|
166
|
+
|
|
163
167
|
@param str string
|
|
164
168
|
@param postfix string
|
|
165
169
|
@return boolean
|
|
@@ -170,6 +174,7 @@ end
|
|
|
170
174
|
|
|
171
175
|
--[=[
|
|
172
176
|
Returns if a string starts with a postfix
|
|
177
|
+
|
|
173
178
|
@param str string
|
|
174
179
|
@param prefix string
|
|
175
180
|
@return boolean
|
|
@@ -180,23 +185,29 @@ end
|
|
|
180
185
|
|
|
181
186
|
--[=[
|
|
182
187
|
Adds commas to a number. Not culture aware.
|
|
188
|
+
|
|
189
|
+
See [NumberLocalizationUtils.abbreviate] for a culture aware version.
|
|
190
|
+
|
|
183
191
|
@param number string | number
|
|
184
192
|
@param seperator string?
|
|
185
193
|
@return string
|
|
186
194
|
]=]
|
|
187
195
|
function String.addCommas(number: string | number, seperator: string): string
|
|
196
|
+
local strNumber
|
|
188
197
|
if type(number) == "number" then
|
|
189
|
-
|
|
198
|
+
strNumber = tostring(number)
|
|
199
|
+
else
|
|
200
|
+
strNumber = number
|
|
190
201
|
end
|
|
191
202
|
seperator = seperator or ","
|
|
192
203
|
|
|
193
204
|
local index = -1
|
|
194
205
|
|
|
195
206
|
while index ~= 0 do
|
|
196
|
-
|
|
207
|
+
strNumber, index = string.gsub(strNumber, "^(-?%d+)(%d%d%d)", "%1" .. seperator .. "%2")
|
|
197
208
|
end
|
|
198
209
|
|
|
199
|
-
return
|
|
210
|
+
return strNumber
|
|
200
211
|
end
|
|
201
212
|
|
|
202
|
-
return String
|
|
213
|
+
return String
|