Skip to content

Instantly share code, notes, and snippets.

View jswhisperer's full-sized avatar
🕵️
For Sale... I mean open to work.

Gregory The JSWhisperer jswhisperer

🕵️
For Sale... I mean open to work.
View GitHub Profile
@jswhisperer
jswhisperer / isNumericString.js
Created October 4, 2023 17:43
Ensure a String is Numeric in JavaScript
/**
* Determine whether the given `input` is a number.
*
* @param {String} input
*
* @returns {Boolean}
*/
const isNumericString = (input) => typeof input === 'string' && !Number.isNaN(input)
@jswhisperer
jswhisperer / ucFirst.js
Created October 4, 2023 17:42
Capitalize the First Letter of a String in JavaScript
/**
* Uppercases the first character in the `string`.
*
* @param {String} string
*
* @returns {String}
*/
function ucFirst (string) {
if (!(typeof string !== 'string')) {
return ''
@jswhisperer
jswhisperer / isObject.js
Created October 4, 2023 17:40
isObject
const isObject = (value) => Object.prototype.toString.call(value) === '[object Object]'
@jswhisperer
jswhisperer / lowerCaseKeys.js
Created October 4, 2023 17:39
Lowercase All Keys of an Object in JavaScript
/**
* Lowercase all top-level keys of the given `object` to lowercase.
*
* @returns {Object}
*/
function lowercaseKeys(obj) {
if (!isObject(obj)) {
throw new Error(`You must provide an object to "lowercaseKeys". Received "${typeof obj}"`)
}
@jswhisperer
jswhisperer / isObjectEmpty.js
Created October 4, 2023 17:37
Detect if an Object is Empty in JavaScript or Node.js
const isEmpty = (obj) => Object.keys(obj).length === 0
@jswhisperer
jswhisperer / isUppercase.js
Created October 4, 2023 17:36
Determine Whether a JavaScript String is in UPPERCASE
/**
* Determine whether the given `input` is a string in uppercase.
*
* @param {*} input
*
* @returns {Boolean}
*/
function isUpperCase (input) {
return input === String(input).toUpperCase()
}
@jswhisperer
jswhisperer / trimFromStartStr.js
Created October 4, 2023 17:35
Trim Characters From the Start of a String Using JavaScript
/**
* Removes whitespaces from the head of the string when
* no argument value is present. It trims the provided `character`
* from the left of the string if you pass along a value.
*
* @param {String} character
*
* @returns {Boolean}
*/
function ltrim (string, character) {
@jswhisperer
jswhisperer / afterLastStr.js
Created October 4, 2023 17:34
Retrieve the String Part After the Last Delimiter Occurrence
/**
* Returns the portion of the string after the last occurrence of the given `delimiter`.
*
* @param {String} delimiter
*
* @returns {String}
*/
function afterLast (value, delimiter) {
value = value || ''
@jswhisperer
jswhisperer / beforeLAst.js
Created October 4, 2023 17:33
Retrieve the String Part Before the Last Occurrence of a Delimiter
/**
* Returns the portion of the string before the last occurrence of the given `delimiter`.
*
* @param {String} delimiter
*
* @returns {String}
*/
function beforeLast (value, delimiter) {
value = value || ''
@jswhisperer
jswhisperer / strAfterDelimeter.js
Created October 4, 2023 17:32
Retrieve the String After a Delimiter
/**
* Returns the portion of the string after the first occurrence of the given `delimiter`.
*
* @param {String} value
* @param {String} delimiter
*
* @returns {String}
*/
function after (value, delimiter) {
value = value || ''