Sep 9, 2021 JavaScript
How to convert the name of an excel column to number in JavaScript

In this Article we will go through how to convert the name of an excel column to number only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.

Let's define this short function:

const getIndex = col => col.split('').reduce((prev, next) => prev * 26 + parseInt(next, 36) - 9, 0);

Sep 9, 2021 JavaScript
How to get the base url without any parameters in JavaScript

In this Article we will go through how to get the base url without any parameters only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.

Let's define this short function:

const baseUrl = url => url.indexOf('?') === -1 ? url : url.slice(0, url.indexOf('?'));

Sep 9, 2021 JavaScript
How to get the file name from a url in JavaScript

In this Article we will go through how to get the file name from a url only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.

Let's define this short function:

const fileName = url => url.substring(url.lastIndexOf('/') + 1);

Sep 9, 2021 JavaScript
How to get the number of a character in a string in JavaScript

In this Article we will go through how to get the number of a character in a string only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.

Let's define this short function:

const characterCount = (str, char) => str.split(char).length - 1;

Sep 9, 2021 JavaScript
How to make the first character of a string lowercase in JavaScript

In this Article we will go through how to make the first character of a string lowercase only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.

Let's define this short function:

const lowercaseFirst = str => `${str.charAt(0).toLowerCase()}${str.slice(1)}`;

Sep 9, 2021 JavaScript
How to normalize file path slashes in JavaScript

In this Article we will go through how to normalize file path slashes only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.

Let's define this short function:

const normalizePath = path => path.replace(/[\\/]+/g, '/');

Sep 9, 2021 JavaScript
How to strip ansi codes from a string in JavaScript

In this Article we will go through how to strip ansi codes from a string only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.

Let's define this short function:

const stripAnsiCodes = str => str.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '');

Sep 9, 2021 JavaScript
How to trim slashes at the beginning and the end of a string in JavaScript

In this Article we will go through how to trim slashes at the beginning and the end of a string only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.

Let's define this short function:

const trimSlashes = str => str.replace(/^\/+|\/+$/g, '');

Sep 9, 2021 JavaScript
How to trim the file extension from a file name in JavaScript

In this Article we will go through how to trim the file extension from a file name only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.

Let's define this short function:

const trimExt = fileName => fileName.indexOf('.') === -1 ? fileName : fileName.split('.').slice(0, -1).join('.');

Sep 9, 2021 JavaScript
How to truncate a string at full words in JavaScript

In this Article we will go through how to truncate a string at full words only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.

Let's define this short function:

const truncate = (str, max, suffix) => str.length < max ? str : `${str.substr(0, str.substr(0, max - suffix.length).lastIndexOf(' '))}${suffix}`;