@quenty/defaultvalueutils 1.0.1-canary.402.a911cda.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 ADDED
@@ -0,0 +1,17 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ ## 1.0.1-canary.402.a911cda.0 (2023-08-23)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * Add missing dependencies ([324e3db](https://github.com/Quenty/NevermoreEngine/commit/324e3dbcd7ed260542eebe24889cbc6cd968d380))
12
+ * Remove unused code ([71930e0](https://github.com/Quenty/NevermoreEngine/commit/71930e02bfb42d9d6e84f716fbfca2a001c8a0cf))
13
+
14
+
15
+ ### Features
16
+
17
+ * Add DefaultValueUtils ([abd0df4](https://github.com/Quenty/NevermoreEngine/commit/abd0df4439e7124c81fbab6d7cf9636c872487d9))
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2014-2023 James Onnen (Quenty)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,23 @@
1
+ ## DefaultValueUtils
2
+
3
+ <div align="center">
4
+ <a href="http://quenty.github.io/NevermoreEngine/">
5
+ <img src="https://github.com/Quenty/NevermoreEngine/actions/workflows/docs.yml/badge.svg" alt="Documentation status" />
6
+ </a>
7
+ <a href="https://discord.gg/mhtGUS8">
8
+ <img src="https://img.shields.io/discord/385151591524597761?color=5865F2&label=discord&logo=discord&logoColor=white" alt="Discord" />
9
+ </a>
10
+ <a href="https://github.com/Quenty/NevermoreEngine/actions">
11
+ <img src="https://github.com/Quenty/NevermoreEngine/actions/workflows/build.yml/badge.svg" alt="Build and release status" />
12
+ </a>
13
+ </div>
14
+
15
+ Helps get the default or zero value for value types in Roblox
16
+
17
+ <div align="center"><a href="https://quenty.github.io/NevermoreEngine/api/DefaultValueUtils">View docs →</a></div>
18
+
19
+ ## Installation
20
+
21
+ ```
22
+ npm install @quenty/defaultvalueutils --save
23
+ ```
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "defaultvalueutils",
3
+ "tree": {
4
+ "$path": "src"
5
+ }
6
+ }
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@quenty/defaultvalueutils",
3
+ "version": "1.0.1-canary.402.a911cda.0",
4
+ "description": "Helps get the default or zero value for value types in Roblox",
5
+ "keywords": [
6
+ "Roblox",
7
+ "Nevermore",
8
+ "Lua",
9
+ "defaultvalueutils"
10
+ ],
11
+ "bugs": {
12
+ "url": "https://github.com/Quenty/NevermoreEngine/issues"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/Quenty/NevermoreEngine.git",
17
+ "directory": "src/defaultvalueutils/"
18
+ },
19
+ "funding": {
20
+ "type": "patreon",
21
+ "url": "https://www.patreon.com/quenty"
22
+ },
23
+ "license": "MIT",
24
+ "contributors": [
25
+ "Quenty"
26
+ ],
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "gitHead": "a911cdaf4f1039b599528cec17b027f4660e4fd8"
31
+ }
@@ -0,0 +1,80 @@
1
+ --[=[
2
+ Helps get the default or zero value for value types in Roblox
3
+ @class DefaultValueUtils
4
+ ]=]
5
+
6
+ local DefaultValueUtils = {}
7
+
8
+ -- selene: allow(incorrect_standard_library_use)
9
+ local DEFAULT_VALUES = {
10
+ ["boolean"] = false;
11
+ ["BrickColor"] = BrickColor.new();
12
+ ["CFrame"] = CFrame.new();
13
+ ["Color3"] = Color3.new();
14
+ ["ColorSequence"] = ColorSequence.new({ ColorSequenceKeypoint.new(0, Color3.new(0, 0, 0)); ColorSequenceKeypoint.new(1, Color3.new(0, 0, 0)); });
15
+ ["ColorSequenceKeypoint"] = ColorSequenceKeypoint.new(0, Color3.new(0, 0, 0));
16
+ ["number"] = 0;
17
+ ["PhysicalProperties"] = PhysicalProperties.new(Enum.Material.Plastic); -- Eww
18
+ ["NumberRange"] = NumberRange.new(0);
19
+ ["NumberSequence"] = NumberSequence.new({ NumberSequenceKeypoint.new(0, 0); NumberSequenceKeypoint.new(1, 0); });
20
+ ["NumberSequenceKeypoint"] = NumberSequenceKeypoint.new(0, 0);
21
+ ["Ray"] = Ray.new();
22
+ ["Rect"] = Rect.new();
23
+ ["Region3"] = Region3.new();
24
+ ["Region3int16"] = Region3int16.new();
25
+ ["string"] = "";
26
+ ["UDim"] = UDim.new();
27
+ ["UDim2"] = UDim2.new();
28
+ ["userdata"] = newproxy();
29
+ ["Vector2"] = Vector2.zero;
30
+ ["Vector2int16"] = Vector2int16.new();
31
+ ["Vector3"] = Vector3.zero;
32
+ ["Vector3int16"] = Vector3int16.new();
33
+ }
34
+
35
+ --[=[
36
+ Returns the default value for a given value type. If the type is mutable than
37
+ a new value will ge cosntructed.
38
+
39
+ @param typeOfName string
40
+ @return any
41
+ ]=]
42
+ function DefaultValueUtils.getDefaultValueForType(typeOfName)
43
+ if DEFAULT_VALUES[typeOfName] ~= nil then
44
+ return DEFAULT_VALUES[typeOfName]
45
+ elseif typeOfName == "table" then
46
+ return {}
47
+ elseif typeOfName == "nil" then
48
+ return nil
49
+ elseif typeOfName == "Random" then
50
+ return Random.new()
51
+ elseif typeOfName == "RaycastParams" then
52
+ return RaycastParams.new()
53
+ elseif typeOfName == "OverlapParams" then
54
+ return OverlapParams.new()
55
+ elseif typeOfName == "Instance" then
56
+ error("Cannot get a defaultValue for an instance")
57
+ else
58
+ error(string.format("Unknown type %q", typeOfName))
59
+ end
60
+ end
61
+
62
+ --[=[
63
+ Converts this value to its default value. If it's a table, it applies it recursively.
64
+
65
+ @param value T
66
+ @return T
67
+ ]=]
68
+ function DefaultValueUtils.toDefaultValue(value)
69
+ if type(value) == "table" then
70
+ local result = {}
71
+ for key, item in pairs(value) do
72
+ result[key] = DefaultValueUtils.toDefaultValue(item)
73
+ end
74
+ return result
75
+ else
76
+ return DefaultValueUtils.getDefaultValueForType(typeof(value))
77
+ end
78
+ end
79
+
80
+ return DefaultValueUtils
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "node_modules",
3
+ "globIgnorePaths": [ "**/.package-lock.json" ],
4
+ "tree": {
5
+ "$path": { "optional": "../node_modules" }
6
+ }
7
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "DefaultValueUtilsTest",
3
+ "tree": {
4
+ "$className": "DataModel",
5
+ "ServerScriptService": {
6
+ "defaultvalueutils": {
7
+ "$path": ".."
8
+ }
9
+ }
10
+ }
11
+ }