123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- /**
- * JSONfn - javascript (both node.js and browser) plugin to stringify,
- * parse and clone objects with Functions, Regexp and Date.
- *
- * Version - 1.1.0
- * Copyright (c) Vadim Kiryukhin
- * vkiryukhin @ gmail.com
- * http://www.eslinstructor.net/jsonfn/
- *
- * Licensed under the MIT license ( http://www.opensource.org/licenses/mit-license.php )
- *
- * USAGE:
- * browser:
- * JSONfn.stringify(obj);
- * JSONfn.parse(str[, date2obj]);
- * JSONfn.clone(obj[, date2obj]);
- *
- * nodejs:
- * var JSONfn = require('path/to/json-fn');
- * JSONfn.stringify(obj);
- * JSONfn.parse(str[, date2obj]);
- * JSONfn.clone(obj[, date2obj]);
- *
- *
- * @obj - Object;
- * @str - String, which is returned by JSONfn.stringify() function;
- * @date2obj - Boolean (optional); if true, date string in ISO8061 format
- * is converted into a Date object; otherwise, it is left as a String.
- */
- (function (exports) {
- "use strict";
- exports.stringify = function (obj) {
- return JSON.stringify(obj, function (key, value) {
- var fnBody;
- if (value instanceof Function || typeof value == 'function') {
- fnBody = value.toString();
- if (fnBody.length < 8 || fnBody.substring(0, 8) !== 'function') { //this is ES6 Arrow Function
- return '_NuFrRa_' + fnBody;
- }
- return fnBody;
- }
- if (value instanceof RegExp) {
- return '_PxEgEr_' + value;
- }
- return value;
- });
- };
- exports.parse = function (str, date2obj) {
- var iso8061 = date2obj ? /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/ : false;
- return JSON.parse(str, function (key, value) {
- var prefix;
- if (typeof value != 'string') {
- return value;
- }
- if (value.length < 8) {
- return value;
- }
- prefix = value.substring(0, 8);
- if (iso8061 && value.match(iso8061)) {
- return new Date(value);
- }
- if (prefix === 'function') {
- return eval('(' + value + ')');
- }
- if (prefix === '_PxEgEr_') {
- return eval(value.slice(8));
- }
- if (prefix === '_NuFrRa_') {
- return eval(value.slice(8));
- }
- return value;
- });
- };
- exports.clone = function (obj, date2obj) {
- return exports.parse(exports.stringify(obj), date2obj);
- };
- }(typeof exports === 'undefined' ? (window.JSONfn = {}) : exports));
- function fl_slugify($attribute) {
- let string = encodeURIComponent($attribute.toString().toLowerCase().trim().replace(/["',]/g, "").replace(/\s/g, '-')).toLowerCase();
- const a = 'àáâäæãåāăąçćčđďèéêëēėęěğǵḧîïíīįìłḿñńǹňôöòóœøōõṕŕřßśšşșťțûüùúūǘůűųẃẍÿýžźż·/,:;'
- const b = 'aaaaaaaaaacccddeeeeeeeegghiiiiiilmnnnnooooooooprrsssssttuuuuuuuuuwxyyzzz-----'
- const p = new RegExp(a.split('').join('|'), 'g')
- return string.toString().toLowerCase()
- .replace(/\.+/g, '-') // Replace . with
- .replace(/\:+/g, '') // Replace : with blank space
- .replace(/\s+/g, '-') // Replace spaces with -
- .replace(p, c => b.charAt(a.indexOf(c))) // Replace special characters
- .replace(/&/g, '-and-') // Replace & with 'and'
- .replace(/[^\w\-]+/g, '') // Remove all non-word characters
- .replace(/\-\-+/g, '-') // Replace multiple - with single -
- .replace(/^-+/, '') // Trim - from start of text
- .replace(/-+$/, '') // Trim - from end of text
- }
|