This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groupBy from 'lodash.groupby'; | |
// How to find duplicates, e.g in this example by "label" | |
// from | |
// [ | |
// { label: "brand", key: "1" }, | |
// { label: "brand", key: "2" }, | |
// { label: "state", key: "3" } | |
// { label: "state", key: "4" }, | |
// { label: "uniq", key: "5" }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mapValues = require("lodash.mapvalues"); | |
// How to convert an object of elements to an array without losing the object | |
// keys? | |
// e.g going from | |
// { | |
// "attr-enum-sfa": { mode: "UPDATE", value: undefined }, | |
// "attr-set-enum-sfa": { mode: "ADD_VALUES", value: undefined }, | |
// "attr-text-sfa-s": { mode: "UPDATE", value: undefined } | |
// } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { keyBy, mapKeys } = require("lodash"); | |
let result; | |
const current = { | |
firstName: "Ahmed", | |
lastName: "Mehri", | |
age: 30 | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { assign, cloneDeep } = require('lodash'); | |
let obj = { | |
type: { | |
values: { | |
results: [1, 2] | |
} | |
} | |
}; | |
let copy; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const crypto = require('crypto'); | |
const bytes = crypto.randomBytes(8); | |
bytes | |
console.log(bytes.toString('hex')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const queryString = require('query-string'); | |
const result = queryString.stringify({ | |
status: 'ready', | |
page: 0, | |
filterByQuery: 'filter', | |
}) | |
result |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const normalizr = require('normalizr'); | |
const job = new normalizr.schema.Entity('jobs'); | |
// normalizing [] | |
const result = normalizr.normalize([], job); | |
console.log(result); | |
console.log(result.entities.jobs); | |
// normalizing {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const _ = require('lodash'); | |
let original = [1, 2]; | |
// 2 has been removed, 3 has been added | |
let after = [1, 3]; | |
console.log('removal:', _.difference(original, after)); | |
console.log('addition:', _.difference(after, original)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const queryString = require('query-string'); | |
const result = queryString.stringify({ name: 'ahmed', items: [1] }); | |
result; | |
const arrayFormat = queryString.stringify( | |
{ name: 'ahmed', items: [1] }, | |
{ arrayFormat: 'bracket' } | |
); | |
arrayFormat; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const _ = require('lodash'); | |
function customizer(objValue, srcValue) { | |
if (_.isArray(objValue)) { | |
return srcValue; | |
} | |
} | |
var object = { ids: [1] }; | |
var other = { ids: [] }; |
NewerOlder