How to use the chain function from lodash
Find comprehensive JavaScript lodash.chain code examples handpicked from public code repositorys.
7249 7250 7251 7252 7253 7254 7255 7256 7257 7258
* { 'name': 'barney', 'age': 36 }, * { 'name': 'fred', 'age': 40 }, * { 'name': 'pebbles', 'age': 1 } * ]; * * var youngest = _.chain(characters) * .sortBy('age') * .map(function(chr) { return chr.name + ' is ' + chr.age; }) * .first() * .value();
73
711
29
46 47 48 49 50 51 52 53 54 55
module.exports.camelCase = _.camelCase; module.exports.capitalize = _.capitalize; module.exports.castArray = _.castArray; module.exports.cat = _.cat; module.exports.ceil = _.ceil; module.exports.chain = _.chain; module.exports.chunk = _.chunk; module.exports.chunkAll = _.chunkAll; module.exports.chunkContrib = _.chunkContrib; module.exports.clamp = _.clamp;
19
122
0
+ 92 other calls in file
GitHub: Kai0071/A17
137 138 139 140 141 142 143 144 145 146
settings: {}, others: {}, sticker: {}, ...(global.db.data || {}) } global.db.chain = _.chain(global.db.data) } loadDatabase() global.db = JSON.parse(fs.readFileSync('./src/database.json')) if (global.db) global.db = {
629
36
2
GitHub: thumbsup/thumbsup
92 93 94 95 96 97 98 99 100 101 102
const sources = [ tagValue(exif, 'IPTC', 'Keywords'), tagValue(exif, 'XMP', 'Subject'), picasaValue(picasa, 'keywords') ] return _.chain(sources).flatMap(makeArray).uniq().value() } function people (exif) { return tagValue(exif, 'XMP', 'PersonInImage') || []
80
649
21
+ 4 other calls in file
136 137 138 139 140 141 142 143 144 145
}); const createFunctionStatement = getFunctionsScript(schemaName, udfs); const createProceduresStatement = getProceduresScript(schemaName, procedures); return _.chain([schemaStatement, createFunctionStatement, createProceduresStatement]) .compact() .map(_.trim) .join('\n\n') .trim()
8
2
0
94 95 96 97 98 99 100 101 102 103 104
global.chatgpt.READ = null; global.chatgpt.data = { users: {}, ...(global.chatgpt.data || {}) }; global.chatgpt.chain = lodash.chain(global.chatgpt.data); }; loadChatgptDB();
6
6
2
76 77 78 79 80 81 82 83 84 85
return { numero, suffixe, lieuDitComplementNom, parcelles: parcelles || [], sources: chain(numeroAdresses).map('source').uniq().value(), certifie, position, positionType, positions: position ? [{position, positionType}] : [],
3
7
3
+ 3 other calls in file
150 151 152 153 154 155 156 157 158 159
.map(v => ({...v, numeros: numerosGeolocalises[v.idVoie]})) if (voiesAvecNumeros.length > 0) { adressesStream.write(buildMunicipality( commune, chain(voiesAvecNumeros).map('numeros').flatten().filter(n => n.position).value() )) communesWithAdresses.push(codeCommune) const duplicateSlugs = chain(voiesAvecNumeros)
3
7
3
+ 3 other calls in file
86 87 88 89 90 91 92 93 94 95
const voies = composedVoies.map(v => ({ type: 'voie', ...omit(v, 'numeros') })) const numeros = chain(composedVoies) .map(v => v.numeros.map(n => ({ codeCommune, idVoie: v.idVoie, ...n
3
7
3
GitHub: mdmarufsarker/lodash
739 740 741 742 743 744 745 746 747 748 749 750 751
console.log(valuesIn); // => [1, 2, 3] // Seq const chain = _.chain([1, 2, 3, 4]) .filter(n => n % 2 == 0) .map(n => n * n) .value(); console.log(chain); // => [4, 16]
0
4
0
+ 15 other calls in file
70 71 72 73 74 75 76 77 78 79
} return output }, {}) topLevelDeclarations = _.chain(root.body) .map(node => { if (node.type === 'ExportDefaultDeclaration' || node.type === 'ExportNamedDeclaration') { return node.declaration }
2
3
1
+ 4 other calls in file
492 493 494 495 496 497 498 499 500 501 502
const exposedFieldsWithCounters = Array.from(exposedMap, ([name, value]) => ({ name, value })); exposedMap.clear(); return exposedFieldsWithCounters; }; const groupOptions = (options, obj) => _.chain(options) .map((option) => ({ ...option, body: jsonHelper.parseJson(option.body), ...(obj && { author_permlink: obj.author_permlink, price: obj.price, avatar: obj.avatar }),
0
3
3
+ 5 other calls in file
278 279 280 281 282 283 284 285 286
if (sat_org_id) { const batchDetailInfo = await inventory.getSystemDetailsBatch(all_systems); _.forEach(normalizedIssues, issue => { issue.systems = _.filter(issue.systems, system => { // eslint-disable-next-line security/detect-object-injection const org_id = _.chain(batchDetailInfo[system].facts) .find(SATELLITE_NAMESPACE) .get('facts.organization_id') .toString(); //organization_id is an int (boo!)
17
1
8
+ 4 other calls in file
GitHub: FinHackCN/finhack
69 70 71 72 73 74 75 76 77 78
chainWebpack: config => { /** * 添加 CDN 参数到 htmlWebpackPlugin 配置中 * 已适配多页 */ const htmlPluginNames = chain(pages).keys().map(page => 'html-' + page).value() const targetHtmlPluginNames = htmlPluginNames.length ? htmlPluginNames : ['html'] each(targetHtmlPluginNames, name => { config.plugin(name).tap(options => { set(options, '[0].cdn', process.env.NODE_ENV === 'production' ? cdn : [])
5
14
2
76 77 78 79 80 81 82 83 84 85
openaps.analyzeData = function analyzeData (sbx) { var recentHours = 6; //TODO dia*2 var recentMills = sbx.time - times.hours(recentHours).msecs; var recentData = _.chain(sbx.data.devicestatus) .filter(function(status) { return ('openaps' in status) && sbx.entryMills(status) <= sbx.time && sbx.entryMills(status) >= recentMills; }) .map(function(status) {
0
1
1
+ 3 other calls in file
17 18 19 20 21 22 23 24 25 26
var allRenderOverOptions = [5, 1, 0.5, 0.1]; if (_.isNumber(bolusSettings.renderOver) && bolusSettings.renderOver > 0 && bolusSettings.renderOver < Number.MAX_SAFE_INTEGER) { allRenderOverOptions.push(_.toNumber(bolusSettings.renderOver)); } var sortedRenderOverOptions = _.chain(allRenderOverOptions).uniq().sort().reverse().value(); _.forEach(sortedRenderOverOptions, function (optionValue) { $('#bolusRenderOver').append( $('<option></option>')
0
1
1
+ 2 other calls in file
50 51 52 53 54 55 56 57 58 59
}); } iob.isDeviceStatusAvailable = function isDeviceStatusAvailable (devicestatus) { return _.chain(devicestatus) .map(iob.fromDeviceStatus) .reject(_.isEmpty) .value() .length > 0;
0
1
1
+ 5 other calls in file
GitHub: reggi/node-reggi
62 63 64 65 66 67 68 69 70 71
}) } var getExitCode = main.getExitCode = function (mdResults) { var evaluations = _.chain(mdResults).map('evaluated').flatten().value() var evalResults = _.chain(evaluations).map('evalResult').flatten().value() var evalResultsInstanceofError = _.map(evalResults, function (evalResult) { return evalResult instanceof Error }) var evalResultsHasInstanceofError = _.contains(evalResultsInstanceofError, true)
0
1
2
+ 7 other calls in file
GitHub: LokeshBabuTG/No53Library
28 29 30 31 32 33 34 35 36 37 38 39
} module.exports.filterBooks = function (term) { return _.chain(books) .flatMap(booksCollections => booksCollections) .filter(book => _c.strContains( _c.lowerCase(book["BOOK NAME"]),
2
0
0
lodash.get is the most popular function in lodash (7670 examples)