Skip to content

Instantly share code, notes, and snippets.

@williammustaffa
Last active March 6, 2018 18:10
Show Gist options
  • Save williammustaffa/e586c288081612ae03b8ce53a73e4b29 to your computer and use it in GitHub Desktop.
Save williammustaffa/e586c288081612ae03b8ce53a73e4b29 to your computer and use it in GitHub Desktop.
/**
* "string".cuckalize(value)
* transform any word into a custom object
*
* @param {Any} v Variable value
*
* @return {Object}
*/
String.prototype.cuckalize = function (v) { return this.split('').reverse().reduce((p, c) => ({ [c]: p }), v) };
/**
* "String".encode_cuck(value)
* encode a string with a value
*
* @param {Any} v Variable value
*
* @return {Object}
*/
String.prototype.encode_cuck = function (v) { return window[`c_${btoa(this)}`] = JSON.stringify(this.split('').reverse().reduce((p, c) => ({ [btoa(c)]: p }), btoa(v))); };
/**
* "String".decode_cuck()
* decode the giving string
*
* @return {any}
*/
String.prototype.decode_cuck = function () { return o = window[`c_${btoa(this)}`], o && atob(this.split('').reduce((p, c) => p[btoa(c)], JSON.parse(o))); };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment