How to use the trim function from lodash

Find comprehensive JavaScript lodash.trim code examples handpicked from public code repositorys.

73
74
75
76
77
78
79
80
81
82
}
var isError = !!json.errors.length;
if (isError) {
  message = _(json.errors)
    .map(function (error) {
      return _.trim(_(error).split('\n\n').compact().first());
    })
    .uniq()
    .join('\n');
  title = 'Webpack 发生错误';
fork icon58
star icon132
watch icon11

+ 3 other calls in file

400
401
402
403
404
405
406
407
408
409
module.exports.toSafeInteger       = _.toSafeInteger;
module.exports.toString            = _.toString;
module.exports.toUpper             = _.toUpper;
module.exports.trampoline          = _.trampoline;
module.exports.transform           = _.transform;
module.exports.trim                = _.trim;
module.exports.trimEnd             = _.trimEnd;
module.exports.trimStart           = _.trimStart;
module.exports.truncate            = _.truncate;
module.exports.truthy              = _.truthy;
fork icon19
star icon122
watch icon0

+ 92 other calls in file

25
26
27
28
29
30
31
32
33
34
{
  type: 'text',
  name: 'from',
  message: chalk`Send tx from which wallet in your keychain? {reset.dim (e.g. "main" or crtl+c to quit)}`,
  validate: value => !_.isEmpty(value.trim()) || 'Invalid wallet label',
  format: value => _.trim(value),
},
{
  type: 'text',
  name: 'label',
fork icon21
star icon36
watch icon10

878
879
880
881
882
883
884
885
886
887
  }
};

liquid.filters.concat = (...args) => _.concat(...args);

liquid.filters.strip = (string = '') => _.trim(string);

liquid.filters.encode = (string = '') => {
  // Escape early in case of string being `null`.
  if (!string) {
fork icon7
star icon15
watch icon0

184
185
186
187
188
189
190
191
192
193
        
        //return new (XMLSerializer()).serializeToString(xmlDoc);
}

function quoteXML(value) {
        return _.trim(value
                .replace(/&/g, '&')
                .replace(/</g, '&lt;')
                .replace(/>/g, '&gt;')
                .replace(/"/g, '&quot;'));
fork icon4
star icon3
watch icon3

+ 31 other calls in file

93
94
95
96
97
98
99
100
101
102

const isExit = F.isExit(`${CONFIG.LC_TOPIC_DIR}/${functionName}.ts`)
isExit && log(chalk.green(`方法已存在,将创建新的方法名称...`))

// 如果方法已存在同名的加个_II
const fileName = trim(isExit ? functionName + '_II' : functionName)

// 测试用例
if (jsonExampleTestcases) {
  testExampleCases = JSON.parse(jsonExampleTestcases)
fork icon3
star icon45
watch icon0

350
351
352
353
354
355
356
357
358
359
lineDescription: transaction.description,
loss: transaction.chargeElement.loss,
region: licence.region.chargeRegionId,
regionalChargingArea: licence.regions.regionalChargeArea,
section127Agreement: transaction.section127Agreement,
section130Agreement: trim(transaction.section130Agreement) === 'true',
supportedSource: !!transaction.isSupportedSource,
supportedSourceName: transaction.supportedSourceName || '',
twoPartTariff: transaction.isTwoPartSecondPartCharge,
waterCompanyCharge: transaction.isWaterCompanyCharge,
fork icon2
star icon4
watch icon8

+ 4 other calls in file

850
851
852
853
854
855
856
857
858
859
860
861
862
console.log(toLower); // => '--foo-bar--'


const toUpper = _.toUpper('--foo-bar--');
console.log(toUpper); // => '--FOO-BAR--'


const trim = _.trim('  abc  ');
console.log(trim); // => 'abc'


const trimEnd = _.trimEnd('  abc  ');
console.log(trimEnd); // => '  abc'
fork icon0
star icon4
watch icon0

+ 15 other calls in file

317
318
319
320
321
322
323
324
325
},

createCheckConstraint(checkConstraint) {
	return assignTemplates(templates.checkConstraint, {
		name: checkConstraint.name ? `CONSTRAINT ${wrapInQuotes(checkConstraint.name)}` : '',
		expression: _.trim(checkConstraint.expression).replace(/^\(([\s\S]*)\)$/, '$1'),
		noInherit: checkConstraint.noInherit ? ' NO INHERIT' : '',
	});
},
fork icon8
star icon2
watch icon0

+ 5 other calls in file

54
55
56
57
58
59
60
61
62
63
patient_contact: _.trim(lead.int_contact),
patient_city_id: getNewMappedCityId(lead.txt_current_city),
patient_state_id: getNewMappedStateId(lead.txt_lead_state),
patient_country_id: getNewMappedCountryId(lead.txt_lead_country),
patient_postal_code:
  _.trim(lead.int_zip_code) == 0 ? null : _.trim(lead.int_zip_code),
patient_address:
  _.trim(lead.txt_lead_address).length > 0
    ? _.trim(lead.txt_lead_address)
    : null,
fork icon0
star icon1
watch icon0

+ 10 other calls in file

6
7
8
9
10
11
12
13
14
    }


    if (_.startsWith(url, '#') || _.startsWith(url, 'http://') || _.startsWith(url, 'https://')) {
        return url;
    }
    const basePath = _.trim(pathPrefix, '/');
    return '/' + _.compact([basePath, _.trimStart(url, '/')]).join('/');
}
fork icon0
star icon1
watch icon0

2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
let name = lodash.get(body, 'name')
let type = lodash.get(body, 'type')

let holiday = await req.app.locals.db.main.Holiday.create({
    date: date,
    name: lodash.trim(name),
    type: type
})

flash.ok(req, 'attendance', `${holiday.name} added.`)
fork icon0
star icon1
watch icon0

23
24
25
26
27
28
29
30
31
32
33
34
35
const uuid = require('uuid/v4');


const Op = Sequelize.Op;


const updateIfValid = (oldValue, newValue) => {
  const trimmedNewValue = trim(newValue);
  return trimmedNewValue || oldValue;
};


const updateEntityFromOrganisation = (entity, organisation) => {
fork icon1
star icon0
watch icon10

119
120
121
122
123
124
125
126
127
128
	enabled: undefined,
};
if (plugin === 'matomo') {
	plugins.matomo.browserHostToEnvironmentMap = {};
	this.matomoHostToEnv
	.map(([key, value]) => ([trim(key), trim(value)]))
	.filter(([key, value]) => !!key && !!value)
	.forEach(([key, value]) => {
		plugins.matomo.browserHostToEnvironmentMap[key] = value;
	});
fork icon1
star icon0
watch icon2

+ 74 other calls in file

433
434
435
436
437
438
439
440
441
442

let [puName, puIdTxt] = _.split(resultTxt, ' PU Code: ', 2);
const [puId] = _.split(puIdTxt, ' ', 1);
const btn = await div.$('button.btn.btn-success');

puName = _.trim(puName);

const pu = {
    name: puName,
    id: _.trim(puId),
fork icon0
star icon0
watch icon1

1224
1225
1226
1227
1228
1229
1230
1231
1232
1233

puName = _.trim(puName);

const pu = {
    name: puName,
    id: _.trim(puId),
    element: div,
    docUrl: null,
    resultUrl: null,
    isResultAvailable: btn !== null,
fork icon0
star icon0
watch icon2

+ 99 other calls in file

23
24
25
26
27
28
29
30
31
32
33
 *
 * @param arn A possible S3 arn string
 */
function parseS3Arn(arn = '') {
  // arn:aws:s3:::123456789012-study/studies/Organization/org-study-a1/*
  let trimmed = _.trim(arn);
  if (_.isEmpty(arn)) return;


  if (!_.startsWith(trimmed, 'arn:')) return;

fork icon0
star icon0
watch icon1

+ 3 other calls in file

143
144
145
146
147
148
149
150
151
152
  badges.push('discogs-no-results');
} else {
  if (discogs_data.similarity === 1) {
    badges.push('discogs-title-exact-match');
  } else {
    var prepared_item_title = _.trim(
      item['title']
        .replace(/\(\d{4}\)/ig, '')
        .replace(/\[\d{4}\]/ig, '')
        .replace(/\d{0,4}kbps/ig, '')
fork icon0
star icon0
watch icon1

+ 23 other calls in file

127
128
129
130
131
132
133
134
135
136
if (depth === 0 && populate === '*') {
  return true;
}

if (typeof populate === 'string') {
  return populate.split(',').map(value => _.trim(value));
}

if (Array.isArray(populate)) {
  // map convert
fork icon0
star icon0
watch icon1

+ 5 other calls in file

29
30
31
32
33
34
35
36
37
38
39
		transactions: transactions.reverse(),
	};
}


function handleTransaction(form, data) {
	const recipient = _.trim(form.recipient);
	if (recipient === '') {
		data.errorMsg = 'Recipient missing!';
		return;
	}
fork icon0
star icon0
watch icon1

+ 2 other calls in file

Other functions in lodash

Sorted by popularity

function icon

lodash.get is the most popular function in lodash (7670 examples)