New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@gollum-js/proxy-array

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gollum-js/proxy-array

Create a proxy for array accessor

1.1.0
latest
Source
npm
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

GollumJS Proxy Array

ProxyArray

Build Status Coverage Licence NPM version Discord

Create a proxy for array accessor. Storage array data in localStorage or Buffer And all array method works on proxy

Install

npm install @gollum-js/proxy-array

Usage TS

import { createProxyArray } from '@gollum-js/proxy-array';

const storage = {};
let length = 0;

const proxy = createProxyArray({
    get(index: number): any {
        return storage[index];
    },
    set(index: number, value: any): boolean {
        storage[index] = value;
        if (length < index + 1) {
        	length = index + 1;
        }
        return true;
    },
    getLength(): number {
        return length;
    },
    setLength(value: number): boolean {
        storage.length = value;
        return true;
    }
});


proxy.push('a');
proxy.push('b');
proxy.push('c');

console.log(storage) // [ 'a', 'b', 'c' ]
console.log(length) // 3


console.log(proxy[1]) // [ 'b' ]


Usage JS


const {createProxyArray} = require("@gollum-js/proxy-array")

const storage = {};
let length = 0;

const proxy = createProxyArray({
    get(index) {
        return storage[index];
    },
    set(index, value) {
        storage[index] = value;
        if (length < index + 1) {
        	length = index + 1;
        }
        return true;
    },
    getLength() {
        return storage.length;
    },
    setLength(value) {
        storage.length = value;
        return true;
    }
});
 
 
proxy.push('a');
proxy.push('b');
proxy.push('c');
 
console.log(storage) // [ 'a', 'b', 'c' ]
console.log(length) // 3
 
 
console.log(proxy[1]) // [ 'b' ]
 

Keywords

proxy

FAQs

Package last updated on 05 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts