2020-12-10 08:33:00 +00:00
|
|
|
const Glib = require('../glib');
|
|
|
|
|
|
|
|
Object.defineProperty(Array.prototype, 'glib', {
|
|
|
|
enumerable: false,
|
|
|
|
configurable: false,
|
|
|
|
get() {
|
|
|
|
return Glib.fromIterable(this);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
Object.defineProperty(Array.prototype, 'set', {
|
|
|
|
enumerable: false,
|
|
|
|
configurable: false,
|
|
|
|
get() {
|
|
|
|
return new Set(this);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-12-13 06:52:00 +00:00
|
|
|
Object.defineProperty(Array.prototype, 'lengthN', {
|
|
|
|
enumerable: false,
|
|
|
|
configurable: false,
|
|
|
|
get() {
|
|
|
|
return BigInt(this.length);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-12-10 08:33:00 +00:00
|
|
|
Array.prototype.safeSplice = function safeSplice(...args) {
|
|
|
|
const spliced = this.slice();
|
|
|
|
spliced.splice(...args);
|
|
|
|
return spliced;
|
|
|
|
};
|
|
|
|
|
|
|
|
Array.prototype.chainSplice = function chainSplice(...args) {
|
|
|
|
this.splice(...args);
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
Array.prototype.chainPush = function chainPush(...args) {
|
|
|
|
this.push(...args);
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
Array.prototype.safePush = function safePush(...args) {
|
|
|
|
const clone = this.slice();
|
|
|
|
clone.push(...args);
|
|
|
|
return clone;
|
|
|
|
};
|
|
|
|
|
|
|
|
Array.prototype.safeReverse = function safeReverse(...args) {
|
|
|
|
const clone = this.slice();
|
|
|
|
clone.reverse(...args);
|
|
|
|
return clone;
|
|
|
|
};
|
|
|
|
|
|
|
|
Array.prototype.safeSort = function safeSort(...args) {
|
|
|
|
const clone = this.slice();
|
|
|
|
clone.sort(...args);
|
|
|
|
return clone;
|
|
|
|
};
|
2020-12-12 06:59:44 +00:00
|
|
|
|
|
|
|
Array.prototype.sortInts = function sortInts() {
|
|
|
|
return this.safeSort((a, b) => (a < b ? -1 : 1));
|
|
|
|
};
|