🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

abstract-value

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

abstract-value

Basic value abstraction of any kind

2.0.2
latest
Source
npm
Version published
Maintainers
1
Created
Source

Abstract-Value

Is used as helper to define any kind of value as abstract value type.
Also allows to add any properties to values, even to String and Number.

const Value = require( 'abstract-value' )( 'Value' );

var values = [
    123,
    '123',
    Value( 123, { add: 456 } ),
    Value( '123', { changeTo: '456' } ),
    Value( [ 123, 789 ] )
];

for ( var i = 0; i < values.length; ++i ) {
    
    if ( values[ i ] instanceof Value ) {
        // change value
        if ( values[ i ].changeTo ) values[ i ].set( values[ i ].changeTo );
        // operation on value
        if ( values[ i ].add ) values[ i ] += values[ i ].add;
        // get value
        console.log( values[ i ].valueOf() );
    } else {
        console.log( values[ i ] );
    }
}

Output:
123
"123"
579
"456"
Array [123, 789]

Also you can chain some methods ( "set", "setProperties" ):

const Value = require( 'abstract-value' )( 'Value' );

var val = Value( 123 );

console.log( val );
console.log( val.set( 124 ).valueOf() );
console.log( val.setProperties({ t: 1 }).t );

Output:
Value {__value: 123}
124
1

FAQs

Package last updated on 11 Oct 2016

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