ts-data-forge
Version:
[](https://www.npmjs.com/package/ts-data-forge) [](https://www.npmjs.com/package/ts-data-forge) [ • 5.02 kB
JavaScript
import '../../number/branded-types/finite-number.mjs';
import '../../number/branded-types/int.mjs';
import '../../number/branded-types/int16.mjs';
import '../../number/branded-types/int32.mjs';
import '../../number/branded-types/non-negative-finite-number.mjs';
import '../../number/branded-types/non-negative-int16.mjs';
import '../../number/branded-types/non-negative-int32.mjs';
import '../../number/branded-types/non-zero-finite-number.mjs';
import '../../number/branded-types/non-zero-int.mjs';
import '../../number/branded-types/non-zero-int16.mjs';
import '../../number/branded-types/non-zero-int32.mjs';
import '../../number/branded-types/non-zero-safe-int.mjs';
import '../../number/branded-types/non-zero-uint16.mjs';
import '../../number/branded-types/non-zero-uint32.mjs';
import '../../number/branded-types/positive-finite-number.mjs';
import '../../number/branded-types/positive-int.mjs';
import '../../number/branded-types/positive-int16.mjs';
import '../../number/branded-types/positive-int32.mjs';
import '../../number/branded-types/positive-safe-int.mjs';
import '../../number/branded-types/positive-uint16.mjs';
import { asPositiveUint32 } from '../../number/branded-types/positive-uint32.mjs';
import '../../number/branded-types/safe-int.mjs';
import '../../number/branded-types/safe-uint.mjs';
import '../../number/branded-types/uint.mjs';
import '../../number/branded-types/uint16.mjs';
import '../../number/branded-types/uint32.mjs';
import '../../number/enum/int8.mjs';
import '../../number/enum/uint8.mjs';
import '../../number/num.mjs';
import '../../number/refined-number-utils.mjs';
import { castMutable } from '../../others/cast-mutable.mjs';
import '@sindresorhus/is';
import { create, copy } from './array-utils-creation.mjs';
function set(...args) {
switch (args.length) {
case 3: {
const [array, index, newValue] = args;
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
return array.with(index, newValue);
}
case 2: {
const [index, newValue] = args;
return (array) => set(array, index, newValue);
}
}
}
function toUpdated(...args) {
switch (args.length) {
case 3: {
const [array, index, updater] = args;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, total-functions/no-unsafe-type-assertion
return array.with(index, updater(array[index]));
}
case 2: {
const [index, updater] = args;
return (array) => toUpdated(array, index, updater);
}
}
}
function toInserted(...args) {
switch (args.length) {
case 3: {
const [array, index, newValue] = args;
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
return array.toSpliced(index, 0, newValue);
}
case 2: {
const [index, newValue] = args;
return (array) => toInserted(array, index, newValue);
}
}
}
function toRemoved(...args) {
switch (args.length) {
case 2: {
const [array, index] = args;
return array.toSpliced(index, 1);
}
case 1: {
const [index] = args;
return (array) => toRemoved(array, index);
}
}
}
function toPushed(...args) {
switch (args.length) {
case 2: {
const [array, newValue] = args;
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
return array.toSpliced(array.length, 0, newValue);
}
case 1: {
const [newValue] = args;
return (array) => toPushed(array, newValue);
}
}
}
function toUnshifted(...args) {
switch (args.length) {
case 2: {
const [array, newValue] = args;
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
return array.toSpliced(0, 0, newValue);
}
case 1: {
const [newValue] = args;
return (array) => toUnshifted(array, newValue);
}
}
}
function toFilled(...args) {
switch (args.length) {
case 2: {
const [array, value] = args;
return create(asPositiveUint32(array.length), value);
}
case 1: {
const [value] = args;
return (array) => toFilled(array, value);
}
}
}
function toRangeFilled(...args) {
switch (args.length) {
case 3: {
const [array, value, [start, end]] = args;
const mut_cp = castMutable(copy(array));
mut_cp.fill(value, start, end);
return mut_cp;
}
case 2: {
const [value, fillRange] = args;
return (array) => toRangeFilled(array, value, fillRange);
}
}
}
export { set, toFilled, toInserted, toPushed, toRangeFilled, toRemoved, toUnshifted, toUpdated };
//# sourceMappingURL=array-utils-modification.mjs.map