how to use the trimstart function from the lodash library in typescript

To use the trimStart function from the Lodash library in TypeScript, first, we need to install the Lodash library by running the below command.

npm install lodash
19 chars
2 lines

Next, we can import the trimStart function from Lodash and then call it on a string to remove the whitespace from the beginning of the string.

index.ts
import { trimStart } from "lodash";

const str = "  hello world  ";
const trimmedStr = trimStart(str); // "hello world  "
122 chars
5 lines

We can also provide a second argument to specify the characters that we want to remove from the beginning of the string.

index.ts
const str = "-_-hello world-_-";
const trimmedStr = trimStart(str, "_-"); // "hello world-_-"
94 chars
3 lines

In the above example, we want to remove both underscore and hyphen characters from the beginning of the string. So we provided "_-" as the second argument to the trimStart function.

gistlibby LogSnag