Skip to content

Commit

Permalink
linted readme
Browse files Browse the repository at this point in the history
  • Loading branch information
d8corp committed Aug 14, 2021
1 parent 5df8cb6 commit 2879964
Showing 1 changed file with 37 additions and 15 deletions.
52 changes: 37 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Or you can use [minified file](https://github.com/d8corp/html-classes/blob/maste

## Usage

#### String
### String

Any string value provides as is.
```javascript
Expand All @@ -49,7 +49,7 @@ classes('test1', 'test2')
// 'test1 test2'
```

#### Array
### Array

Any array spreads like the `flat` method of an array.
```javascript
Expand All @@ -59,27 +59,42 @@ classes(['test'])
classes(['test1', 'test2'])
// 'test1 test2'

classes(['test1', ['test2']], 'test3')
classes(
[
'test1',
['test2'],
],
'test3',
)
// 'test1 test2 test3'
```

#### Object
### Object

The key of the object will be used as a class when the value equals true.
```javascript
classes({test: true})
classes({
test: true,
})
// 'test'

classes({test1: true, test2: 1, test3: NaN})
classes({
test1: true,
test2: 1,
test3: NaN,
})
// 'test1 test2'

classes({test1: () => true, test2: () => false})
classes({
test1: () => true,
test2: () => false,
})
// 'test1'
```

> The last example works that 'cause of the next definition.
#### Function
### Function

Any function will be called.
```javascript
Expand All @@ -89,32 +104,38 @@ classes(() => 'test')
classes(() => ['test1', 'test2'])
// 'test1 test2'

classes(() => ({test1: () => () => true, test2: () => () => false}))
classes(() => ({
test1: () => () => true,
test2: () => () => false,
}))
// 'test1'
```

#### Class
### Class

Any instance of class will be handled the same as an object.
```javascript
class Custom {
test1 () {
return true
}

test2 () {
return false
}

get test3 () {
return true
}

field = true
}

classes(new Custom())
// 'field'
```

#### Other
### Other

Any other type will be ignored.
```javascript
Expand All @@ -127,10 +148,10 @@ classes(0) // ''
classes(-1) // ''
classes(1) // ''
classes(NaN) // ''
classes(Symbol('test')) // ''
classes(Symbol()) // ''
```

#### ES6
## ES6

For the [ES6](https://github.com/d8corp/html-classes/blob/master/lib/es6.js) version, you can use iterable functionality.
If the type can be iterable then `html-classes` goes through values.
Expand All @@ -141,13 +162,14 @@ classes(new Set(['test1', 'test2']))
classes(new Map([
['test1', false],
['', 'test2'],
[undefined, null]
[undefined, null],
]))
// 'test1 test2'

class Test {
*[Symbol.iterator] () {
* [Symbol.iterator] () {
let i = 0

while (i++ < 3) {
yield `test${i}`
}
Expand Down

0 comments on commit 2879964

Please sign in to comment.