Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String.prototype.toDataProp = function() {
- var min = "A".charCodeAt(0),
- max = "Z".charCodeAt(0),
- res = "data-";
- this.split("").forEach(function(char, i) {
- var cc = char.charCodeAt(0);
- if (cc >= min && cc <= max) {
- res += ((i > 0) ? "-" : "") + String.fromCharCode(cc + 32);
- } else {
- res += char;
- }
- });
- return res;
- }
- String.prototype.fromDataProp = function() {
- var min = "A".charCodeAt(0),
- max = "Z".charCodeAt(0),
- res = "",
- temp = this.split('data-')[1];
- temp.split("-").forEach(function(word, i) {
- if (i > 0) {
- res += String.fromCharCode(word.charCodeAt(0) - 32) + word.substr(1, word.length - 1);
- } else {
- res += word;
- }
- });
- return res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement