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 value is base64 encoded in JavaScript

In this Article we will go through how to check if a value is base64 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 isBase64 = value => /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$/.test(value);

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

In this Article we will go through how to check if a value is nil 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 isNil = (value) => value == null;

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 array elements are equal to a given value in JavaScript

In this Article we will go through how to check if all array elements are equal to a given value 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 isEqual = (arr, value) => arr.every(item => item === value);

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 contains a value matching some criterias in JavaScript

In this Article we will go through how to check if an array contains a value matching some criterias 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 contains = (arr, criteria) => arr.some(v => criteria(v));

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;

Sep 9, 2021 JavaScript
How to check if an array is subset of other array in JavaScript

In this Article we will go through how to check if an array is subset of other array 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:

// Check if `b` is subset of `a`
const isSubset = (a, b) => (new Set(b)).size === (new Set(b.concat(a))).size;

Sep 9, 2021 JavaScript
How to check if an object is a promise in JavaScript

In this Article we will go through how to check if an object is a promise 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 isPromise = obj => !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function';