Skip to content

Instantly share code, notes, and snippets.

View paceaux's full-sized avatar
🌐
Obsessing with languagey things

Paceaux paceaux

🌐
Obsessing with languagey things
View GitHub Profile
/**
* @class Locker
* @description who doesn't like Konami?
* @example const locker = new Locker(); locker.initialize();
*
*/
// I'm not going to use Babel for a tiny static site
// eslint-disable-next-line no-unused-vars
class Locker {
/**
@paceaux
paceaux / clientStorage.js
Last active March 26, 2025 20:34
ClientStorage Module for saving things in a namespaced way to local or session storage.
class ClientStorage {
/**
* Converts a string into a namespaced string
* @param {string} namespace the namespace
* @param {string} keyname keyname
* @returns {string} a string with namespace.keyname
*/
static getNamespacedKeyName(namespace, keyname) {
let namespacedKeyName = "";
@paceaux
paceaux / README.md
Created October 19, 2021 14:16
Front-end Readme
@paceaux
paceaux / classname.regex.js
Created January 5, 2021 17:07
A Regex for finding a class name in html
/*
where "title" is the full class name
/class=(.*[ "]title[ "].*)/g
*/
const className = 'title';
const regex = new RegExp(`/class=(.*[ "]${className}[ "].*)/g`);
@paceaux
paceaux / jscss.js
Last active October 29, 2020 16:25
JSCSS, The quick and easy way to do CSS in the DOM
/**
* Class for adding CSS with JavaScript that relies on the CSSOM
*/
class JSCSS {
/**
* @param {string} cssText Text for a stylesheet. Rulesets, queries, and all
*/
constructor(cssText = '') {
const sheet = JSCSS.addStyleSheet();
this.stylesheet = JSCSS.getStyleSheet(sheet.title);
@paceaux
paceaux / debug.css
Last active October 15, 2022 08:43
A Sass/SCSS debug mixin
.isDebugging .debug {
outline: 1px solid rgba(200, 100, 50, 0.9);
}
.isDebugging .debug * {
outline: 1px solid rgba(200, 100, 50, 0.9);
}
@paceaux
paceaux / iterators.arrays.js
Last active December 30, 2019 20:01
Custom Iterators
/** Creates an array that, when iterated, only returns ruthy items
* @param {array} iterable
*
* @example const mixedBag = new TruthyArray(1, 0, 'foo', '', true, false, undefined, null, 'three'])
* for (item of mixedBag) {
* console.log(item);
* }
*
*/
@paceaux
paceaux / implicit-explicit.arrays.js
Last active March 6, 2025 07:56
Samples of loops over an array that seem to show an implicit and explicit undefined for arrays
function ifIn(array) {
console.group(`ifIn======`);
let i = 0;
while (i < array.length) {
if (i++ in array) {
console.log(`${i - 1} is in the array`);
}
}
console.groupEnd();
@paceaux
paceaux / SearchMap.js
Last active June 5, 2020 16:32
SearchMap: A JavaScript Map with searchable keys
/** Evaluates an array, makes the key lowercasee and makes the value an object with original keyname
* @param {Array} iterable=[] an array of arrays:[[key,val],[key,val]]
* @returns Array
*/
function LowercaseIterable(iterable = []) {
if (iterable.length === 0) return [];
const newIterable = iterable.map(([key, val]) => {
const entry = [
key.toLowerCase(),
@paceaux
paceaux / speaker.js
Created September 3, 2019 17:16
Interface for speech synthesis in the browser
/**
* @typedef SpeakerDefaults
* @type {object}
* @property {string} voiceURI voice that the browser uses
* @property {Number} volume loudness. Between 0 and 1.0
* @property {Number} rate speed at which words are spoken. Between 0 and 2.
* @property {Number} pitch Between 0 and 2
* @property {string} lang ISO language
*/