UNPKG

laravelphp

Version:

laravel2js and js2laravel converter laravel php resource utils

38 lines 1.52 kB
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } var js2laravelClb = function js2laravelClb(resources, cb) { var result = "<?php\n return ["; var end = ' ];'; (function stringifyJs(obj, level) { if (obj) { var keys = Object.keys(obj); keys.forEach(function (key, index) { var value = obj[key] || ''; if (typeof value === 'string') { value = value.replace(/'/g, '\\\''); result += "\n ".concat(' '.repeat(level), "'").concat(key, "' => '").concat(value, "'"); } if (_typeof(value) === 'object') { result += "\n ".concat(' '.repeat(level), "'").concat(key, "' => ["); stringifyJs(value, level + 1); result += "\n ".concat(' '.repeat(level), "]"); } if (index + 1 < keys.length) { result += ','; } }); } })(resources, 1); result += "\n".concat(end); if (cb) return cb(null, result); return result; }; export default function js2laravel(resources, cb) { if (!cb) { return new Promise(function (resolve, reject) { return js2laravelClb(resources, function (err, ret) { return err ? reject(err) : resolve(ret); }); }); } return js2laravelClb(resources, cb); }