coc.nvim
Version:
LSP based intellisense engine for neovim & vim8.
128 lines • 3.62 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const Is = tslib_1.__importStar(require("./is"));
function deepClone(obj) {
if (!obj || typeof obj !== 'object') {
return obj;
}
if (obj instanceof RegExp) {
// See https://github.com/Microsoft/TypeScript/issues/10990
return obj;
}
const result = Array.isArray(obj) ? [] : {};
Object.keys(obj).forEach(key => {
if (obj[key] && typeof obj[key] === 'object') {
result[key] = deepClone(obj[key]);
}
else {
result[key] = obj[key];
}
});
return result;
}
exports.deepClone = deepClone;
const _hasOwnProperty = Object.prototype.hasOwnProperty;
function deepFreeze(obj) {
if (!obj || typeof obj !== 'object') {
return obj;
}
const stack = [obj];
while (stack.length > 0) {
let obj = stack.shift();
Object.freeze(obj);
for (const key in obj) {
if (_hasOwnProperty.call(obj, key)) {
let prop = obj[key];
if (typeof prop === 'object' && !Object.isFrozen(prop)) {
stack.push(prop);
}
}
}
}
return obj;
}
exports.deepFreeze = deepFreeze;
/**
* Copies all properties of source into destination. The optional parameter "overwrite" allows to control
* if existing properties on the destination should be overwritten or not. Defaults to true (overwrite).
*/
function mixin(destination, source, overwrite = true) {
if (!Is.objectLiteral(destination)) {
return source;
}
if (Is.objectLiteral(source)) {
Object.keys(source).forEach(key => {
if (key in destination) {
if (overwrite) {
if (Is.objectLiteral(destination[key]) && Is.objectLiteral(source[key])) {
mixin(destination[key], source[key], overwrite);
}
else {
destination[key] = source[key];
}
}
}
else {
destination[key] = source[key];
}
});
}
return destination;
}
exports.mixin = mixin;
function equals(one, other) {
if (one === other) {
return true;
}
if (one === null ||
one === undefined ||
other === null ||
other === undefined) {
return false;
}
if (typeof one !== typeof other) {
return false;
}
if (typeof one !== 'object') {
return false;
}
if (Array.isArray(one) !== Array.isArray(other)) {
return false;
}
let i;
let key;
if (Array.isArray(one)) {
if (one.length !== other.length) {
return false;
}
for (i = 0; i < one.length; i++) {
if (!equals(one[i], other[i])) {
return false;
}
}
}
else {
const oneKeys = [];
for (key in one) { // tslint:disable-line
oneKeys.push(key);
}
oneKeys.sort();
const otherKeys = [];
for (key in other) { // tslint:disable-line
otherKeys.push(key);
}
otherKeys.sort();
if (!equals(oneKeys, otherKeys)) {
return false;
}
for (i = 0; i < oneKeys.length; i++) {
if (!equals(one[oneKeys[i]], other[oneKeys[i]])) {
return false;
}
}
}
return true;
}
exports.equals = equals;
//# sourceMappingURL=object.js.map