@quenty/string 2.1.0 → 2.2.1-canary.238.f89c386.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 CHANGED
@@ -3,6 +3,25 @@
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.2.1-canary.238.f89c386.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/string@2.2.0...@quenty/string@2.2.1-canary.238.f89c386.0) (2021-12-30)
7
+
8
+ **Note:** Version bump only for package @quenty/string
9
+
10
+
11
+
12
+
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
+
6
25
  # [2.1.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/string@2.0.0...@quenty/string@2.1.0) (2021-09-22)
7
26
 
8
27
 
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2014 Quenty
3
+ Copyright (c) 2014-2021 Quenty
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,14 +1,21 @@
1
1
  ## String
2
2
  <div align="center">
3
- <a href="http://quenty.github.io/api/">
4
- <img src="https://img.shields.io/badge/docs-website-green.svg" alt="Documentation" />
3
+ <a href="http://quenty.github.io/NevermoreEngine/">
4
+ <img src="https://github.com/Quenty/NevermoreEngine/actions/workflows/docs.yml/badge.svg" alt="Documentation status" />
5
5
  </a>
6
6
  <a href="https://discord.gg/mhtGUS8">
7
- <img src="https://img.shields.io/badge/discord-nevermore-blue.svg" alt="Discord" />
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" />
11
11
  </a>
12
12
  </div>
13
13
 
14
- This module provides utility functions for strings
14
+ This module provides utility functions for strings
15
+
16
+ <div align="center"><a href="https://quenty.github.io/NevermoreEngine/api/string">View docs →</a></div>
17
+
18
+ ## Installation
19
+ ```
20
+ npm install @quenty/string --save
21
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/string",
3
- "version": "2.1.0",
3
+ "version": "2.2.1-canary.238.f89c386.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": "6288c63115f31544fce6663d018826e81ef01c7f"
31
+ "gitHead": "f89c3863db94c96adc936ea31a49e0c770756dd0"
32
32
  }
@@ -1,8 +1,17 @@
1
- --- This module provides utility functions for strings
2
- -- @module String
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
- --- Sets it to UpperCamelCase
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
- -- Only trims the front of the string...
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
- --- Checks if a string is empty or nil
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
- --- Returns whether or not text is whitespace
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
- --- Converts text to have a ... after it if it's too long.
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,10 +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
+ ]=]
92
168
  function String.endsWith(str, postfix)
93
169
  return str:sub(-#postfix) == postfix
94
170
  end
95
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
+ ]=]
96
187
  function String.addCommas(number)
97
188
  if type(number) == "number" then
98
189
  number = tostring(number)