Skip to content

Instantly share code, notes, and snippets.

View caio-ribeiro-pereira's full-sized avatar
👨‍💻
Working from home

Caio caio-ribeiro-pereira

👨‍💻
Working from home
View GitHub Profile
@caio-ribeiro-pereira
caio-ribeiro-pereira / array2string-3-ways.js
Created December 27, 2018 16:10
Três maneiras de converter string para array
// Usando o clássico método String.prototype.split()
const title = 'Book';
// É necessário string vazia em argumento
console.log(title.split('')); // ['B', 'o', 'o', 'k']
// split sem argumento vai retornar um array com uma única string
console.log(title.split()); // ['Book']
// Usando Array.from()
const title = 'Book';
console.log(Array.from(title)); // ['B', 'o', 'o', 'k']
@caio-ribeiro-pereira
caio-ribeiro-pereira / search-string-object.js
Created December 27, 2018 16:04
Pesquisando palavras nos atributos de um objeto
const pessoa = {
nome: 'John Connor',
twitter: '@john'
};
Object.values(pessoa)
.toString()
.includes('Connor');
@caio-ribeiro-pereira
caio-ribeiro-pereira / html-extract.js
Created December 27, 2018 16:03
Extraindo conteúdo de string tags html
const conteudo = '<h1>JavaScript</h1> <h2>é o melhor!</h2>';
const texto = conteudo.replace(/<[a-zA-Z/][^>]*>/g, '');
console.log(texto); // "JavaScript é o melhor!"
@caio-ribeiro-pereira
caio-ribeiro-pereira / slug-strings-prototype.js
Created December 27, 2018 16:01
Criando slug strings usando regex com prototype
String.prototype.slugify = function() {
return this.toLowerCase().replace(/\s/g, '-').trim();
}
"Escrevendo JavaScript Melhor".slugify();
// "escrevendo-javascript-melhor"
@caio-ribeiro-pereira
caio-ribeiro-pereira / slug-strings.js
Created December 27, 2018 15:59
Criando slug strings usando regex
function slugify(content) {
return content.toLowerCase().replace(/\s/g, '-').trim();
}
slugify("Escrevendo JavaScript Melhor");
// "escrevendo-javascript-melhor"
@caio-ribeiro-pereira
caio-ribeiro-pereira / index.html
Last active February 26, 2020 17:01
Simple Voice Recognition in JS
<!DOCTYPE html>
<html>
<head>
<title>Simple Command Voice</title>
</head>
<body>
<p id="output"></p>
<button id="start">Click and say something!</button>
<script>
(() => {