@protagonists/locked-array

1.0.1 • Public • Published

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' ]






This is the bottom, there is nothing more.
Go back up?

Readme

Keywords

none

Package Sidebar

Install

npm i @protagonists/locked-array

Weekly Downloads

0

Version

1.0.1

License

ISC

Unpacked Size

18 kB

Total Files

4

Last publish

Collaborators

  • addikted
  • pywon