diff --git a/README.md b/README.md index 8300bbf91..8fe88d411 100644 --- a/README.md +++ b/README.md @@ -278,7 +278,6 @@ average(1, 2, 3); * [`byteSize`](#bytesize) * [`capitalize`](#capitalize) * [`capitalizeEveryWord`](#capitalizeeveryword) -* [`countVowels`](#countvowels) * [`escapeHTML`](#escapehtml) * [`escapeRegExp`](#escaperegexp) * [`fromCamelCase`](#fromcamelcase) @@ -4164,29 +4163,6 @@ capitalizeEveryWord('hello world!'); // 'Hello World!'
[⬆ Back to top](#table-of-contents) -### countVowels - -Retuns `number` of vowels in provided string. - -Use a regular expression to count the number of vowels `(A, E, I, O, U)` in a `string`. - -```js -const countVowels = str => (str.match(/[aeiou]/gi) || []).length; -``` - -
-Examples - -```js -countVowels('foobar'); // 3 -countVowels('gym'); // 0 -``` - -
- -
[⬆ Back to top](#table-of-contents) - - ### escapeHTML Escapes a string for use in HTML. diff --git a/docs/index.html b/docs/index.html index 6c279b4e6..55d7ca7a2 100644 --- a/docs/index.html +++ b/docs/index.html @@ -40,7 +40,7 @@ },1700); } }, false); - }

logo 30 seconds of code Curated collection of useful JavaScript snippets that you can understand in 30 seconds or less.

 

Adapter

call

Given a key and a set of arguments, call them when given a context. Primarily useful in composition.

Use a closure to call a stored key with stored arguments.

const call = (key, ...args) => context => context[key](...args);
+      }

logo 30 seconds of code Curated collection of useful JavaScript snippets that you can understand in 30 seconds or less.

 

Adapter

call

Given a key and a set of arguments, call them when given a context. Primarily useful in composition.

Use a closure to call a stored key with stored arguments.

const call = (key, ...args) => context => context[key](...args);
 
Promise.resolve([1, 2, 3])
   .then(call('map', x => 2 * x))
   .then(console.log); //[ 2, 4, 6 ]
@@ -895,9 +895,6 @@ console.log<
 capitalize('fooBar', true); // 'Foobar'
 

capitalizeEveryWord

Capitalizes the first letter of every word in a string.

Use String.replace() to match the first character of each word and String.toUpperCase() to capitalize it.

const capitalizeEveryWord = str => str.replace(/\b[a-z]/g, char => char.toUpperCase());
 
capitalizeEveryWord('hello world!'); // 'Hello World!'
-

countVowels

Retuns number of vowels in provided string.

Use a regular expression to count the number of vowels (A, E, I, O, U) in a string.

const countVowels = str => (str.match(/[aeiou]/gi) || []).length;
-
countVowels('foobar'); // 3
-countVowels('gym'); // 0
 

escapeHTML

Escapes a string for use in HTML.

Use String.replace() with a regexp that matches the characters that need to be escaped, using a callback function to replace each character instance with its associated escaped character using a dictionary (object).

const escapeHTML = str =>
   str.replace(
     /[&<>'"]/g,
diff --git a/snippets/createEventHub.md b/snippets/createEventHub.md
index 5b11f4530..a911aa4de 100644
--- a/snippets/createEventHub.md
+++ b/snippets/createEventHub.md
@@ -9,37 +9,37 @@ to the array.
 For `off`, use `Array.findIndex()` to find the index of the handler in the event array and remove it using `Array.splice()`.
 
 ```js
-const createEventHub = () => ({
-  hub: Object.create(null),
-  emit(event, data) {
-    (this.hub[event] || []).forEach(handler => handler(data));
-  },
-  on(event, handler) {
-    if (!this.hub[event]) this.hub[event] = [];
-    this.hub[event].push(handler);
-  },
-  off(event, handler) {
-    const i = (this.hub[event] || []).findIndex(h => h === handler);
-    if (i > -1) this.hub[event].splice(i, 1);
-  }
-});
+const createEventHub = () => ({
+  hub: Object.create(null),
+  emit(event, data) {
+    (this.hub[event] || []).forEach(handler => handler(data));
+  },
+  on(event, handler) {
+    if (!this.hub[event]) this.hub[event] = [];
+    this.hub[event].push(handler);
+  },
+  off(event, handler) {
+    const i = (this.hub[event] || []).findIndex(h => h === handler);
+    if (i > -1) this.hub[event].splice(i, 1);
+  }
+});
 ```
 
 ```js
-const handler = data => console.log(data);
-const hub = createEventHub();
-let increment = 0;
-
-// Subscribe: listen for different types of events
-hub.on('message', handler);
-hub.on('message', () => console.log('Message event fired'));
-hub.on('increment', () => increment++);
-
-// Publish: emit events to invoke all handlers subscribed to them, passing the data to them as an argument
-hub.emit('message', 'hello world'); // logs 'hello world' and 'Message event fired'
-hub.emit('message', { hello: 'world' }); // logs the object and 'Message event fired'
-hub.emit('increment'); // `increment` variable is now 1
-
-// Unsubscribe: stop a specific handler from listening to the 'message' event
-hub.off('message', handler);
+const handler = data => console.log(data);
+const hub = createEventHub();
+let increment = 0;
+
+// Subscribe: listen for different types of events
+hub.on('message', handler);
+hub.on('message', () => console.log('Message event fired'));
+hub.on('increment', () => increment++);
+
+// Publish: emit events to invoke all handlers subscribed to them, passing the data to them as an argument
+hub.emit('message', 'hello world'); // logs 'hello world' and 'Message event fired'
+hub.emit('message', { hello: 'world' }); // logs the object and 'Message event fired'
+hub.emit('increment'); // `increment` variable is now 1
+
+// Unsubscribe: stop a specific handler from listening to the 'message' event
+hub.off('message', handler);
 ```