Skip to content

Instantly share code, notes, and snippets.

View kmaida's full-sized avatar

Kim Maida kmaida

View GitHub Profile
@kmaida
kmaida / slugify.js
Last active July 5, 2020 19:32
Convert string of text into a slug separated by hyphens with no special characters.
function slugify(text) {
const a = 'ãàáäâèéëêìíïîòóöôùúüûñçßÿœæŕśńṕẃǵǹḿǘẍźḧ·/_,:;';
const b = 'aaaaaeeeeiiiioooouuuuncsyoarsnpwgnmuxzh------';
const p = new RegExp(a.split('').join('|'), 'g');
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(p, c => b.charAt(a.indexOf(c))) // Replace special chars
.replace(/&/g, '-and-') // Replace & with 'and'
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
@brucekirkpatrick
brucekirkpatrick / jquery.unserialize.js
Last active March 11, 2018 22:59 — forked from rcmachado/jquery.unserialize.js
Takes a string in format "param1=value1&param2=value2" and returns an javascript object. Improved to handle multiple values with same name and to unescape url encoded values.
/**
* $.unserialize
*
* Takes a string in format "param1=value1&param2=value2" and returns an object { param1: 'value1', param2: 'value2' }. If the "param1" ends with "[]" the param is treated as an array.
*
* Example:
*
* Input: param1=value1&param2=value2
* Return: { param1 : value1, param2: value2 }
*