Sep 9, 2021 JavaScript
How to check if a string contains only ascii characters in JavaScript

In this Article we will go through how to check if a string contains only ascii characters 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 isAscii = str => /^[\x00-\x7F]+$/.test(str);

Sep 9, 2021 JavaScript
How to check if a string contains only digits in JavaScript

In this Article we will go through how to check if a string contains only digits 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 isNumeric = str => !/[^0-9]/.test(str);

Sep 9, 2021 JavaScript
How to check if a string is a hexadecimal number in JavaScript

In this Article we will go through how to check if a string is a hexadecimal 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 isHexadecimal = str => /^[A-F0-9]+$/i.test(str);

Sep 9, 2021 JavaScript
How to check if a string is an octal number in JavaScript

In this Article we will go through how to check if a string is an octal 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 isOctal = str => /^(0o)?[0-7]+$/i.test(str);

Sep 9, 2021 JavaScript
How to check if a value is a number in JavaScript

In this Article we will go through how to check if a value is a 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 isNumber = value => !isNaN(parseFloat(value)) && isFinite(value);

Sep 9, 2021 JavaScript
How to check if a value is base32 encoded in JavaScript

In this Article we will go through how to check if a value is base32 encoded 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 isBase32 = value => value.length % 8 === 0 && /^[A-Z2-7]+=*$/.test(value);

Sep 9, 2021 JavaScript
How to check if a value is base58 encoded in JavaScript

In this Article we will go through how to check if a value is base58 encoded 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:

// It doesn't accept the I, O, l characters 
const isBase58 = value => /^[A-HJ-NP-Za-km-z1-9]*$/.test(value);

Sep 9, 2021 JavaScript
How to check if a year is leap year in JavaScript

In this Article we will go through how to check if a year is leap year 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 isLeapYear = year => (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0));

Sep 9, 2021 JavaScript
How to check if all items in an array are equal in JavaScript

In this Article we will go through how to check if all items in an array are equal 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 areEqual = arr => arr.length > 0 && arr.every(item => item === arr[0]);

Sep 9, 2021 JavaScript
How to check if an array is not empty in JavaScript

In this Article we will go through how to check if an array is not empty 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 isNotEmpty = arr => Array.isArray(arr) && Object.keys(arr).length > 0;