Skip to content

Instantly share code, notes, and snippets.

View MateusAndrade's full-sized avatar
🚀

Mateus Andrade MateusAndrade

🚀
  • Germany
  • 06:04 (UTC +02:00)
View GitHub Profile
@MateusAndrade
MateusAndrade / ObjectoToJson.js
Last active February 2, 2019 23:59
Returns all object propertys using this scope in a ES6 class parsed to a JSON
toJson(){
let _obj: any = {};
let _str:string = "";
for (const key in this) {
if (this.hasOwnProperty(key)) {
_str = key;
_str = _str.replace(_str.charAt(0),"");
_obj[_str] = this["_"+_str];
}
}
@MateusAndrade
MateusAndrade / states.js
Last active April 26, 2019 13:51
Brazillian States and Distrito Federal array of objects with key, name and value
const states = [
{
value: 'ac',
label: 'Acre',
key: 'ac',
}, {
value: 'al',
label: 'Alagoas',
key: 'al',
}, {
@MateusAndrade
MateusAndrade / stringValueToNumber.js
Created March 27, 2019 14:10
Converts a string monetary value to a integer based on cents
/**
* Converts a string monetary value 9,00 to a integer
* @param {String} stringValue
*/
const stringMoneyToCents = (stringValue) => {
const regexCleanStr = new RegExp(
/^[0-9]*$/g,
);
const regexRemoveDots = new RegExp(
@MateusAndrade
MateusAndrade / update-fork.sh
Created April 27, 2019 22:02
Update fork based on origin
git fetch upstream
git checkout master
git merge upstream/master
@MateusAndrade
MateusAndrade / removeObjKeys.ts
Created September 10, 2019 14:57
A simple function to remove obj keys
const removeObjKeys: <T>(obj: T, keys: string[]) => T = (obj, keys) => {
const objectKeys: string[] = Object.keys(obj);
keys.forEach((key: string) => {
const isPresentKey = objectKeys.find((objKey: string) => objKey === key);
if (isPresentKey) {
delete obj[key];
}
});
@MateusAndrade
MateusAndrade / initializeArray.js
Created October 21, 2019 00:45
Initializar a array with number from 0 to array lenght(N)
export default function = (lenght) => Array(lenght).fill(0).map((e, i) => i);
@MateusAndrade
MateusAndrade / cardHolderName.js
Created April 22, 2020 20:32
Card Holder name generator
/**
This a simple function to create the Holder Name of a Credit Card, mainly based
on the pattern addopted at NuBank
**/
const names = [
"Vini Lins",
"Mateus Andrade da Costa Santos",
"Bruno Dal Santos",
"Helena Strada Franco de Souza",
@MateusAndrade
MateusAndrade / remove-nested-keys.js
Created September 2, 2021 15:53
Remove recursively all object keys, matching a given name
const removeObjectKey = (target, key) => {
Object.keys(target).forEach((objKey) => {
if (typeof target[objKey] === "object") {
return removeObjectKey(target[objKey], key);
}
if (objKey.toLowerCase() === key) {
delete target[objKey];
}
});