Travis build: 733 [ci skip]

This commit is contained in:
Travis CI
2017-12-31 13:18:31 +00:00
parent 2cf844ebf5
commit 0dd10dd757
3 changed files with 7 additions and 5 deletions

View File

@ -4246,13 +4246,13 @@ isSymbol(Symbol('x')); // true
Checks if the provided argument is a valid JSON. Checks if the provided argument is a valid JSON.
Use `JSON.parse()` and a `try... catch` block to check if the provided argument is a valid JSON and non-null. Use `JSON.parse()` and a `try... catch` block to check if the provided argument is a valid JSON.
```js ```js
const isValidJSON = obj => { const isValidJSON = obj => {
try { try {
JSON.parse(obj); JSON.parse(obj);
return !!obj; return true;
} catch (e) { } catch (e) {
return false; return false;
} }
@ -4265,6 +4265,7 @@ const isValidJSON = obj => {
```js ```js
isValidJSON('{"name":"Adam","age":20}'); // true isValidJSON('{"name":"Adam","age":20}'); // true
isValidJSON('{"name":"Adam",age:"20"}'); // false isValidJSON('{"name":"Adam",age:"20"}'); // false
isValidJSON(null); // true
``` ```
</details> </details>

View File

@ -882,16 +882,17 @@ isString('10'); // true
</code></pre></div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="issymbol">isSymbol</h3></div><div class="section double-padded"><p>Checks if the given argument is a symbol.</p><p>Use <code>typeof</code> to check if a value is classified as a symbol primitive.</p><pre><code class="language-js">const isSymbol = val =&gt; typeof val === 'symbol'; </code></pre></div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="issymbol">isSymbol</h3></div><div class="section double-padded"><p>Checks if the given argument is a symbol.</p><p>Use <code>typeof</code> to check if a value is classified as a symbol primitive.</p><pre><code class="language-js">const isSymbol = val =&gt; typeof val === 'symbol';
</code></pre><pre><code class="language-js">isSymbol('x'); // false </code></pre><pre><code class="language-js">isSymbol('x'); // false
isSymbol(Symbol('x')); // true isSymbol(Symbol('x')); // true
</code></pre></div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="isvalidjson">isValidJSON</h3></div><div class="section double-padded"><p>Checks if the provided argument is a valid JSON.</p><p>Use <code>JSON.parse()</code> and a <code>try... catch</code> block to check if the provided argument is a valid JSON and non-null.</p><pre><code class="language-js">const isValidJSON = obj =&gt; { </code></pre></div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="isvalidjson">isValidJSON</h3></div><div class="section double-padded"><p>Checks if the provided argument is a valid JSON.</p><p>Use <code>JSON.parse()</code> and a <code>try... catch</code> block to check if the provided argument is a valid JSON.</p><pre><code class="language-js">const isValidJSON = obj =&gt; {
try { try {
JSON.parse(obj); JSON.parse(obj);
return !!obj; return true;
} catch (e) { } catch (e) {
return false; return false;
} }
}; };
</code></pre><pre><code class="language-js">isValidJSON('{&quot;name&quot;:&quot;Adam&quot;,&quot;age&quot;:20}'); // true </code></pre><pre><code class="language-js">isValidJSON('{&quot;name&quot;:&quot;Adam&quot;,&quot;age&quot;:20}'); // true
isValidJSON('{&quot;name&quot;:&quot;Adam&quot;,age:&quot;20&quot;}'); // false isValidJSON('{&quot;name&quot;:&quot;Adam&quot;,age:&quot;20&quot;}'); // false
isValidJSON(null); // true
</code></pre></div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="randomhexcolorcode">randomHexColorCode</h3></div><div class="section double-padded"><p>Generates a random hexadecimal color code.</p><p>Use <code>Math.random</code> to generate a random 24-bit(6x4bits) hexadecimal number. Use bit shifting and then convert it to an hexadecimal String using <code>toString(16)</code>.</p><pre><code class="language-js">const randomHexColorCode = () =&gt; { </code></pre></div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="randomhexcolorcode">randomHexColorCode</h3></div><div class="section double-padded"><p>Generates a random hexadecimal color code.</p><p>Use <code>Math.random</code> to generate a random 24-bit(6x4bits) hexadecimal number. Use bit shifting and then convert it to an hexadecimal String using <code>toString(16)</code>.</p><pre><code class="language-js">const randomHexColorCode = () =&gt; {
let n = ((Math.random() * 0xfffff) | 0).toString(16); let n = ((Math.random() * 0xfffff) | 0).toString(16);
return '#' + (n.length !== 6 ? ((Math.random() * 0xf) | 0).toString(16) + n : n); return '#' + (n.length !== 6 ? ((Math.random() * 0xf) | 0).toString(16) + n : n);

View File

@ -18,5 +18,5 @@ const isValidJSON = obj => {
```js ```js
isValidJSON('{"name":"Adam","age":20}'); // true isValidJSON('{"name":"Adam","age":20}'); // true
isValidJSON('{"name":"Adam",age:"20"}'); // false isValidJSON('{"name":"Adam",age:"20"}'); // false
isValidJSON(null) // true isValidJSON(null); // true
``` ```