Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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