0.0.7 • Published 8 years ago

jsdictionary v0.0.7

Weekly downloads
18
License
Unlicense
Repository
github
Last release
8 years ago

jsdictionary

A key value map which allows objects as keys.

Example

    
    nullKey     = null
    stringKey   = 'string'
    numberKey   = 1
    boolenKey   = false
    arrayKey    = []
    objectKey   = {}
    functionKey = () -> null
    
    JSDictionary = require 'jsdictionary'
    dict         = new JSDictionary()
    
    # map key, value
    dict.map nullKey,     'nullValue'
    dict.map stringKey,   'stringValue'
    dict.map numberKey,   'numberValue'
    dict.map boolenKey,   'boolenValue'
    dict.map arrayKey,    'arrayValue'
    dict.map objectKey,   'objectValue'
    dict.map functionKey, 'functionValue'
    
    # get key
    console.log 'null:     ', dict.get nullKey     # 'nullValue'
    console.log 'string:   ', dict.get stringKey   # 'stringValue'
    console.log 'number:   ', dict.get numberKey   # 'numberValue'
    console.log 'boolen:   ', dict.get boolenKey   # 'boolenValue'
    console.log 'array:    ', dict.get arrayKey    # 'arrayValue'
    console.log 'object:   ', dict.get objectKey   # 'objectValue'
    console.log 'function: ', dict.get functionKey # 'functionValue'
    
    # has key
    dict.has boolenKey # true
    dict.has true      # false
    
    # isEmpty()
    dict.isEmpty()     # false
    
    # length()
    dict.length()      # 7
    
    # forEach
    dict.forEach (key, value) ->
        console.log key + ':' + value
    
    # clear()
    dict.clear()    
    

The dict defines a not enumerable property, which holds a uid, on each object.
The default name for this property is '__dict_uid__'.

If, however, you have to change the name of this property, you can do:

JSDictionary.key = 'whatEver'

One more:

    a = key:'value'
    b = {}
    
    # JSDictionary.hasKeys
    JSDictionary.hasKeys a # true
    JSDictionary.hasKeys b # false
    
0.0.7

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago