lodash trimstart trims an extra character on Windows

26 Views Asked by At

I am using the lodash JS utility (v4.17.21) to do a basic trim function that is shown in the code below.

const process = require('process');
const lodash = require('lodash')

var path = "C:/Users/C5317673/repo-caches/cornerstone"
var fileName = "C:/Users/C5317673/repo-caches/cornerstone/CIC/models/advancedreturnsmanagement/FollowUpActivityCodes.cds"
console.log(lodash.trimStart(fileName, path)) //returns IC/models/advancedreturnsmanagement/FollowUpActivityCodes.cds
console.log(fileName.substring(path.length+1)) //returns CIC/models/advancedreturnsmanagement/FollowUpActivityCodes.cds

What I am curious is that the trimstart function with Lodash chops off an extra char from the output (I am expecting it to be starting with CIC). Whereas the regular substring option works fine. Incidentally I have seen this on windows systems only and not macOS for example.

Any suggestions?

1

There are 1 best solutions below

0
Vivick On BEST ANSWER

The second parameter to _.trimStart(string='', chars=whitespace) is not a "needle" but a set of characters to trim.

_.trimStart('eq eq eq eaz', 'eq ') will return 'az' and not 'eaz'.

Think of it in the same way as splitting via regex using only a character set.