You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+21-21
Original file line number
Diff line number
Diff line change
@@ -20,46 +20,46 @@ The `rswitch` function takes a key and an object containing cases and actions. I
20
20
rswitch(key, casesObj, options);
21
21
```
22
22
23
-
-`key` : The value to evaluate against the cases.
24
-
-`casesObj` : An object containing cases and their actions.
25
-
-`options` : (Optional) An object to customize the behavior of the rswitch function.
26
-
-`returnFunction` (optional, default: false): If set to `false`, the `rswitch` function will call actions that are functions and return their values. If set to `true`, the function will return the functions as is.
23
+
-`key` : The value to evaluate against the cases.
24
+
-`casesObj` : An object containing cases and their actions.
25
+
-`options` : (Optional) An object to customize the behavior of the rswitch function.
26
+
-`returnFn` (optional, default: false): If set to `false`, the `rswitch` function will call actions that are functions and return their values. If set to `true`, the function will return the functions as is.
In this example, the `rswitch` function evaluates the key `'dev'` against the cases defined in `casesObj`. Since it matches the case `'dev, web'`, the corresponding action `'Freelancer'` is returned and assigned to the `result` variable. Finally, the value of `result` is logged to the console.
52
+
In this example, the `rswitch` function evaluates the key `'dev'` against the cases defined in `casesObj`. Since it matches the case `'dev, web'`, the corresponding action `'Developer'` is returned and assigned to the `result` variable. Finally, the value of `result` is logged to the console.
53
53
54
54
### Case Definitions
55
55
56
56
Cases are defined as key-value pairs in the `casesObj` object.
> Actions can be any value or a function that returns a value. If the action is a function, and the `options` object has `returnFunction` set to `false`, it is called, and the returned value is returned.
62
+
> Actions can be any value or a function that returns a value. If the action is a function, and the `options` object has `returnFn` set to `false`, it is called, and the returned value is returned.
63
63
64
64
If no cases match the evaluated key, the `rswitch` function checks for a default case. If a default case is defined, its corresponding action is performed. If no default case is defined or its action is not provided, `undefined` is returned.
Copy file name to clipboardExpand all lines: package.json
+6-2
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
{
2
2
"name": "rswitch",
3
3
"description": "The rswitch library provides a compact and flexible way to implement switch-like functionality in JavaScript. It allows you to define cases and their corresponding actions using an object literal syntax.",
0 commit comments