1.0.1 • Published 3 years ago

@protagonists/locked-array v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

About

An array that can be completely locked from adding/removing elements on demand


Table of content


How to use?

Description

This is a simple array package that can prevent users from modifying the array itself
Elements within it can still be modified and accessed as normal

Import

Terminal

npm install @protagonists/locked-array

Node.js

const LockedArray = require("@protagonists/locked-array");

Example

Code:

// Imports
const LockedArray = require("@protagonists/locked-array");
// Create LockedArray instance
const fruits = new LockedArray(["apple", "orange"]);

// Add "tomato" in the array
fruits.add("tomato");
// Lock the array
fruits.lock();

// Log the array's value
console.log(fruits.value);
// try to add element to the direct value
fruits.value.push("banana");
// Log the array's value
console.log(fruits.value);

Output:

[ 'apple', 'orange', 'tomato' ]
[ 'apple', 'orange', 'tomato' ]