In this Article we will go through how to check if a string contains whitespace 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 containsWhitespace = str => str => /\s/.test(str);
In this Article we will go through how to check if a string is a hexadecimal color 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 isHexColor = color => /^#([0-9A-F]{3}|[0-9A-F]{4}|[0-9A-F]{6}|[0-9A-F]{8})$/i.test(color);
In this Article we will go through how to check if a string is a mongodb objectid 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 isMongoId = str => str.length === 24 && /^[A-F0-9]+$/i.test(str);
In this Article we will go through how to check if a string is upper case 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 isUpperCase = str => str === str.toUpperCase();
In this Article we will go through how to check if a value is an object 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 isObject = v => (v !== null && typeof v === 'object');
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;
In this Article we will go through how to check if a date is a weekday 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 isWeekday = (date = new Date()) => date.getDay() % 6 !== 0;
In this Article we will go through how to check if a date is between two dates 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 isBetween = (date, min, max) => (date.getTime() >= min.getTime() && date.getTime() <= max.getTime());
In this Article we will go through how to check if a date occurs in the current 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 isCurrentYear = (date) => date.getUTCFullYear() === new Date().getUTCFullYear();
In this Article we will go through how to check if a number is a power of 2 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 isPowerOfTwo = number => (number & (number - 1)) === 0;