This commit is contained in:
Rico Sta. Cruz 2017-08-29 01:39:39 +08:00
parent 2c318a2678
commit 8ae383e42a
No known key found for this signature in database
GPG Key ID: CAAD38AE2962619A
3 changed files with 47 additions and 11 deletions

View File

@ -17,6 +17,8 @@
`table` supports these: `table` supports these:
{: .-shortcuts} {: .-shortcuts}
{: .-left-align}
{: .-headers}
`pre` supports these: `pre` supports these:

View File

@ -20,8 +20,10 @@
& th { & th {
padding: 8px 16px; padding: 8px 16px;
vertical-align: top; vertical-align: top;
text-align: left;
} }
& tr th:last-child,
& tr td:last-child { & tr td:last-child {
text-align: right; text-align: right;
} }
@ -50,6 +52,11 @@
& thead { & thead {
display: none; display: none;
} }
& thead th {
font-weight: normal;
color: $base-a;
}
} }
.MarkdownBody table.-shortcuts { .MarkdownBody table.-shortcuts {
@ -65,3 +72,18 @@
color: $base-text; color: $base-text;
} }
} }
.MarkdownBody table.-left-align {
& tr th,
& tr td,
& tr td:last-child {
text-align: left;
}
}
.MarkdownBody table.-headers {
& thead {
display: table-header-group;
border-bottom: solid 1px $dark-line-color;
}
}

View File

@ -1,22 +1,34 @@
--- ---
title: JavaScript lazy shortcuts title: JavaScript lazy shortcuts
category: JavaScript category: JavaScript
layout: 2017/sheet
--- ---
| What | Lazy mode | "The right way" | ## Shortcuts
| --- | --- | --- | {: .-left-reference}
| String to number | `+str` | `parseInt(str, 10)` or `parseFloat()` |
| Math floor | `num | 0` | `Math.floor(num)` |
| Number to string | `'' + num` | `num.toString()` |
| Date to UNIX timestamp | `+new Date()` | `new Date().getTime()` |
| Any to boolean | `!!value` | `Boolean(value)` |
| Check array contents | `if (~arr.indexOf(v))` | `if (arr.includes(v))` |
> `.includes` is ES6-only, otherwise use `.indexOf(val) !== -1` if you don't polyfill ### Examples
## Examples
```js ```js
n = +'4096' // n === 4096 n = +'4096' // n === 4096
s = '' + 200 // s === '200' s = '' + 200 // s === '200'
``` ```
```js
now = +new Date()
isPublished = !!post.publishedAt
```
### Shortcuts
| What | Lazy mode | "The right way" |
| --- | --- | --- |
| String to number | `+str` | `parseInt(str, 10)` _or_ `parseFloat()` |
| Math floor | `num | 0` | `Math.floor(num)` |
| Number to string | `'' + num` | `num.toString()` |
| Date to UNIX timestamp | `+new Date()` | `new Date().getTime()` |
| Any to boolean | `!!value` | `Boolean(value)` |
| Check array contents | `if (~arr.indexOf(v))` | `if (arr.includes(v))` |
{: .-left-align.-headers}
`.includes` is ES6-only, otherwise use `.indexOf(val) !== -1` if you don't polyfill.