How to use the replace function from lodash

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

8
9
10
11
12
13
14
15
16
17
const Packagers = require('./packagers');

function rebaseFileReferences(pathToPackageRoot, moduleVersion) {
  if (/^(?:file:[^/]{2}|\.\/|\.\.\/)/.test(moduleVersion)) {
    const filePath = _.replace(moduleVersion, /^file:/, '');
    return _.replace(
      `${_.startsWith(moduleVersion, 'file:') ? 'file:' : ''}${pathToPackageRoot}/${filePath}`,
      /\\/g,
      '/'
    );
fork icon408
star icon0
watch icon1

+ 3 other calls in file

323
324
325
326
327
328
329
330
331
332
module.exports.reject              = _.reject;
module.exports.remove              = _.remove;
module.exports.renameKeys          = _.renameKeys;
module.exports.repeat              = _.repeat;
module.exports.repeatContrib       = _.repeatContrib;
module.exports.replace             = _.replace;
module.exports.rest                = _.rest;
module.exports.result              = _.result;
module.exports.reverse             = _.reverse;
module.exports.reverseOrder        = _.reverseOrder;
fork icon19
star icon122
watch icon0

+ 92 other calls in file

5768
5769
5770
5771
5772
5773
5774
5775
5776
5777

_.each(objectPosition, (properties, rule) => {
	_.each(modifiersAndValues, (value, modifier) => {
		if (typeof value === 'object') {
			_.each(value, (_value, _modifier) => {
				convertedStyles += `'.${removeLastDash(`${rule}-${setModifier2(modifier, rule)}${setModifier2(_modifier)}`)}': ` + _.replace(properties, new RegExp("{value}", "g"), parseValue(_value)) + '\n';
			});
		} else {
			convertedStyles += `'.${setModifier2(rule, modifier)}${setModifier2(modifier)}': ` + _.replace(properties, new RegExp("{value}", "g"), parseValue(value)) + '\n';
		}
fork icon3
star icon24
watch icon0

+ 23 other calls in file

826
827
828
829
830
831
832
833
834
835
836
837
838
console.log(parseInt); // => 8


const repeat = _.repeat('*', 3);
console.log(repeat); // => '***'


const replace = _.replace('Hi Fred', 'Fred', 'Barney');
console.log(replace); // => 'Hi Barney'


const snakeCase = _.snakeCase('Foo Bar');
console.log(snakeCase); // => 'foo_bar'
fork icon0
star icon4
watch icon0

+ 15 other calls in file

129
130
131
132
133
134
135
136
137

let fixedRoute = _.reduce(
  pathParams,
  (fixedRoute, pathParam, i, arr) => {
    const insertion = this.config.hooks.onInsertPathParam(pathParam.name, i, arr, fixedRoute) || pathParam.name;
    return _.replace(fixedRoute, pathParam.$match, `\${${insertion}}`);
  },
  routeName || "",
);
fork icon236
star icon0
watch icon12

+ 3 other calls in file

306
307
308
309
310
311
312
313
314
315
  },
);

this.entryFunctions = _.flatMap(entries, (value, key) => {
  const entry = path.relative('.', value);
  const entryFile = _.replace(
    entry,
    new RegExp(`${path.extname(entry)}$`),
    '',
  );
fork icon0
star icon1
watch icon0

97
98
99
100
101
102
103
104
105
106
    if (r) {
        forEach(r, function (item, index, arr) {
            item = _.replace(item, '[a]', '');
            item = _.replace(item, '[/a]', '');
            var url = decode(item);
            string = _.replace(string, '[a]' + item + '[/a]', decode(url));
        });
    }
    return string;
}
fork icon0
star icon0
watch icon1

+ 17 other calls in file

372
373
374
375
376
377
378
379
380
381
 * 频闭简介敏感字
 * @param {String} word
 * @returns
 */
const senseIntroduction = (word) => {
  word = _.replace(
    word,
    /髪|髮|珐|琺|蕟|発|沷|冹|發|彂|睽|葵|揆|骙|暌|戣|藈|票|鰾|驃|慓|徱|僄|魒|飃|飄|翲|螵|彯|勡|剽|飘|旚|犥|漂|嘌|缥|瞟/g,
    '*'
  );
fork icon0
star icon0
watch icon0

576
577
578
579
580
581
582
583
584
585
}

path(location) {
    const dataPath = Path.join(Config.get('sftp.path', '/srv/daemon-data'), this.json.uuid);

    if (_.isUndefined(location) || _.replace(location, /\s+/g, '').length < 1) {
        return dataPath;
    }

    // Dangerous path, do not rely on this as the final output location until running it through
fork icon0
star icon0
watch icon0

Other functions in lodash

Sorted by popularity

function icon

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