Skip to content

Instantly share code, notes, and snippets.

@marcrobledo
marcrobledo / stringTransformations.js
Last active May 8, 2025 10:04
JavaScript functions to transform strings to: slug, camelCase, PascalCase, snake_case and kebab-case
/**
* JavaScript functions to transform strings to:
* - slug
* - camelCase
* - PascalCase
* - snake_case
* - kebab-case
*
* Usage: ' *** This is just a test! *** '.slug(); //returns 'this-is-just-a-test'
* 'Do you like jalapeños and Pokémon!?'.slug(true); //returns 'do_you_like_jalapenos_and_pokemon'
@marcrobledo
marcrobledo / numberToStringFormatted.js
Last active February 2, 2025 18:44
JavaScript functions to turn Number objects into formatted number strings
/**
* JavaScript functions to turn Number objects into formatted number strings:
* - zero padded
* - hex bytes
*
* Usage: (1).toStringZeroPadded(); //returns '01';
* (10).toStringZeroPadded(3); //returns '010';
* (0x0f).toStringHexBytes(); //returns '0f';
* (0x0100).toStringHexBytes(); //returns '0100';
* (0x010200).toStringHexBytes(); //returns '00010200';
@marcrobledo
marcrobledo / warnOnLeave.js
Last active February 2, 2025 18:27
JavaScript function that enables or disables warning before closing page
/**
* JavaScript function that enables or disables warning before closing
* page
* Usage: warnOnLeave(true|false);
*
* by Marc Robledo
* Released under no license
*/
const warnOnLeave=(function(){
@marcrobledo
marcrobledo / isNavigatorMobile.js
Created February 2, 2025 17:22
JavaScript function that returns if the browser is running under a mobile device, based on userAgent data
/**
* JavaScript function that returns if the browser is running under a
* mobile device, based on userAgent data
*
* by Marc Robledo
* Released under no license
*/
const isNavigatorMobile=function(){
if(navigator.userAgentData && typeof navigator.userAgentData.mobile!=='undefined')
@marcrobledo
marcrobledo / foobar2000_jscript_panel_now_playing_export.js
Last active April 22, 2025 15:08
foobar2000 now playing track export to file
// ==PREPROCESSOR==
// @name "Now Playing exporter"
// @author "Marc Robledo"
// @version "1.0"
// ==/PREPROCESSOR==
// for use with https://github.com/jscript-panel
/* CONFIGURATION */