mirror of
https://github.com/JamesIves/github-pages-deploy-action.git
synced 2023-12-15 20:03:39 +08:00
121 lines
2.9 KiB
JavaScript
121 lines
2.9 KiB
JavaScript
|
'use strict';
|
||
|
|
||
|
Object.defineProperty(exports, '__esModule', {
|
||
|
value: true
|
||
|
});
|
||
|
exports.default = exports.serialize = exports.test = void 0;
|
||
|
|
||
|
var _collections = require('../collections');
|
||
|
|
||
|
function ownKeys(object, enumerableOnly) {
|
||
|
var keys = Object.keys(object);
|
||
|
if (Object.getOwnPropertySymbols) {
|
||
|
var symbols = Object.getOwnPropertySymbols(object);
|
||
|
if (enumerableOnly)
|
||
|
symbols = symbols.filter(function(sym) {
|
||
|
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
||
|
});
|
||
|
keys.push.apply(keys, symbols);
|
||
|
}
|
||
|
return keys;
|
||
|
}
|
||
|
|
||
|
function _objectSpread(target) {
|
||
|
for (var i = 1; i < arguments.length; i++) {
|
||
|
var source = arguments[i] != null ? arguments[i] : {};
|
||
|
if (i % 2) {
|
||
|
ownKeys(Object(source), true).forEach(function(key) {
|
||
|
_defineProperty(target, key, source[key]);
|
||
|
});
|
||
|
} else if (Object.getOwnPropertyDescriptors) {
|
||
|
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
||
|
} else {
|
||
|
ownKeys(Object(source)).forEach(function(key) {
|
||
|
Object.defineProperty(
|
||
|
target,
|
||
|
key,
|
||
|
Object.getOwnPropertyDescriptor(source, key)
|
||
|
);
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
return target;
|
||
|
}
|
||
|
|
||
|
function _defineProperty(obj, key, value) {
|
||
|
if (key in obj) {
|
||
|
Object.defineProperty(obj, key, {
|
||
|
value: value,
|
||
|
enumerable: true,
|
||
|
configurable: true,
|
||
|
writable: true
|
||
|
});
|
||
|
} else {
|
||
|
obj[key] = value;
|
||
|
}
|
||
|
return obj;
|
||
|
}
|
||
|
|
||
|
const SPACE = ' ';
|
||
|
const OBJECT_NAMES = ['DOMStringMap', 'NamedNodeMap'];
|
||
|
const ARRAY_REGEXP = /^(HTML\w*Collection|NodeList)$/;
|
||
|
|
||
|
const testName = name =>
|
||
|
OBJECT_NAMES.indexOf(name) !== -1 || ARRAY_REGEXP.test(name);
|
||
|
|
||
|
const test = val =>
|
||
|
val &&
|
||
|
val.constructor &&
|
||
|
val.constructor.name &&
|
||
|
testName(val.constructor.name); // Convert array of attribute objects to props object.
|
||
|
|
||
|
exports.test = test;
|
||
|
|
||
|
const propsReducer = (props, attribute) => {
|
||
|
props[attribute.name] = attribute.value;
|
||
|
return props;
|
||
|
};
|
||
|
|
||
|
const serialize = (collection, config, indentation, depth, refs, printer) => {
|
||
|
const name = collection.constructor.name;
|
||
|
|
||
|
if (++depth > config.maxDepth) {
|
||
|
return '[' + name + ']';
|
||
|
}
|
||
|
|
||
|
return (
|
||
|
(config.min ? '' : name + SPACE) +
|
||
|
(OBJECT_NAMES.indexOf(name) !== -1
|
||
|
? '{' +
|
||
|
(0, _collections.printObjectProperties)(
|
||
|
name === 'NamedNodeMap'
|
||
|
? Array.prototype.reduce.call(collection, propsReducer, {})
|
||
|
: _objectSpread({}, collection),
|
||
|
config,
|
||
|
indentation,
|
||
|
depth,
|
||
|
refs,
|
||
|
printer
|
||
|
) +
|
||
|
'}'
|
||
|
: '[' +
|
||
|
(0, _collections.printListItems)(
|
||
|
Array.from(collection),
|
||
|
config,
|
||
|
indentation,
|
||
|
depth,
|
||
|
refs,
|
||
|
printer
|
||
|
) +
|
||
|
']')
|
||
|
);
|
||
|
};
|
||
|
|
||
|
exports.serialize = serialize;
|
||
|
const plugin = {
|
||
|
serialize,
|
||
|
test
|
||
|
};
|
||
|
var _default = plugin;
|
||
|
exports.default = _default;
|