Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yuanchuan/cond
Lisp-like conditional statement for JSX
https://github.com/yuanchuan/cond
Last synced: about 1 month ago
JSON representation
Lisp-like conditional statement for JSX
- Host: GitHub
- URL: https://github.com/yuanchuan/cond
- Owner: yuanchuan
- License: mit
- Created: 2016-05-18T06:27:46.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-05-19T02:32:28.000Z (over 8 years ago)
- Last Synced: 2024-10-24T01:59:33.569Z (2 months ago)
- Language: JavaScript
- Homepage:
- Size: 4.88 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Cond
Lisp-like conditional statement for JSX
## Installation
```bash
npm install yuanchuan/cond --save
```## Examples
##### like if statement
```jsx
import { cond } from '@yuanchuan/cond';
{ cond(n > 0,
(hello world)
)}
```##### like if...else statement
```jsx
{ cond(
n > 0, (hello world),
true, (nothing)
)}
```##### like if...else if... statement
```jsx
{ cond(
n == 3, (hello world),
n == 6, (something),
n == 9, (something else),
true, (default)
)}
```## Shortcuts
##### If
```jsx
import { If } from '@yuanchuan/cond';
{ If(n > 0,
(hello world)
)}
```##### If...else
```jsx
{ If(n > 0,
(hello world),
(something else)
)}
```##### unless
```jsx
import { unless } from '@yuanchuan/cond';
{ unless(n != 0,
(hello world)
)}
```## Extend cond
```jsx
let condOdd = cond((a, b) => (a % 2 ? b : null));
{ condOdd(number, (
odd number
)}
``````jsx
let condThenWrap = cond((a, b) => {
if (a) {
return (
{ b }
);
}
});
{ condThenWrap(
n == 3, (hello world),
n == 6, (something),
n == 9, (something else),
true, (default)
)}
```## License
MIT