slang-ts 0.0.9 → 0.1.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/README.md +12 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -38,6 +38,10 @@ npm i slang-ts
|
|
|
38
38
|
|
|
39
39
|
All utilities fully tested. See [tests](https://github.com/Hussseinkizz/slang/tree/main/tests)
|
|
40
40
|
|
|
41
|
+
## New in v0.0.10
|
|
42
|
+
|
|
43
|
+
- **Ok messages**: `Ok(value, message?)` keeps an optional success message on the result, such as text to show the user. Results without one have no `message` property.
|
|
44
|
+
|
|
41
45
|
## New in v0.0.9
|
|
42
46
|
|
|
43
47
|
- **SafeTry**: unwraps nested Result, Option, and Atom values into one result; nested failures now become the outer `Err`, while plain object properties and array elements stay unchanged.
|
|
@@ -134,8 +138,16 @@ const user = await fetchUser("123");
|
|
|
134
138
|
if (user.isOk) {
|
|
135
139
|
println("User:", user.value.name);
|
|
136
140
|
}
|
|
141
|
+
|
|
142
|
+
// Optional success message as the second argument
|
|
143
|
+
const saved = Ok({ id: "123" }, "Profile saved");
|
|
144
|
+
if (saved.isOk) {
|
|
145
|
+
println(saved.message); // "Profile saved"
|
|
146
|
+
}
|
|
137
147
|
```
|
|
138
148
|
|
|
149
|
+
`andThen` and `safeTry` return new results, so a message stays with the value it described.
|
|
150
|
+
|
|
139
151
|
### Expect
|
|
140
152
|
|
|
141
153
|
Unwraps values or throws with custom message. Use when failure is unrecoverable.
|