New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

polymorph

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

polymorph - npm Package Compare versions

Comparing version
0.0.1
to
0.0.2
+62
test/cache.coffee
should = require 'should'
Cache = require '../lib/cache'
describe 'Cache', ->
cache = null
it 'should create new `Cache` without `new` keyword', ->
cache = Cache()
cache.should.be.an.instanceof Cache
describe '#set()', ->
describe '#get()', ->
it 'should return `undefined` when the value is not present', ->
v = typeof cache.get "foo"
v.should.be.eql 'undefined'
it 'should return the correct value when is present', ->
cache.set 'foo', 'bar'
cache.get('foo').should.eql 'bar'
cache.set 'user', 'name', 'John'
cache.get('user', 'name').should.be.eql 'John'
cache.get('user').should.eql {name: 'John'}
describe '#exist()', ->
it 'should retrun `true` when value is present', ->
cache.exist('foo').should.be.true
it 'should retrun `false` when value is not present', ->
cache.exist('NOT_EXIST').should.be.false
describe '#changed()', ->
it 'should return changed if the value was changed', ->
cache.changed('foo').should.be.a.true
it 'can be changed >_<', ->
cache.changed('foo', false).should.be.an.false
describe '#cached()', ->
it 'should return binding cache by index', ->
user = cache.cached 'user'
user.get('name').should.be.eql cache.get 'user', 'name'
describe '#delele()', ->
it 'have alias del', ->
cache.should.respondTo 'delete'
cache.should.respondTo 'del'
it 'should delete value', ->
cache.exist('foo').should.be.a.true
cache.delete 'foo'
cache.exist('foo').should.be.a.false
describe '#clear()', ->
it 'shoud work', ->
cache.set 'foo', 'bar'
cache.exist('foo').should.be.a.true
cache.clear()
cache.exist('foo').should.be.false
describe '#all()', ->
it 'should return array', ->
cache.set 1, 'word', 'hello'
cache.set 2, 'word', 'world'
cache.all().should.be.an.instanceof Array
it 'should work', ->
cache.all().should.be.eql [{word:'hello',id:'1' },{word:'world',id:'2'}]
+14
-1
module.exports = class Cache
constructor: (@options = {}) ->
constructor: (options) ->
return new Cache arguments... unless @ instanceof Cache
@options ?= {}
@cache = {}
# index, [field,] value
# cache.set "PI", 3.14
# cache.set "Math", "PI", 3.14
set: (index, field, value) ->

@@ -44,3 +49,11 @@ [value, field] = [field, null] if typeof value is 'undefined'

bindApi this, [index], 'set', 'get', 'del', 'exist', 'changed'
all: () ->
@cache
clear: () ->
@cache = {}
Cache::delete = Cache::del
bindApi = (self, params, functions...) ->

@@ -47,0 +60,0 @@ result = {}

+2
-2
{
"name": "polymorph",
"description": "Polymorph Node module for compile client dev files on fly, inspired by connect-assets.",
"version": "0.0.1",
"description": "Connect middleware for transparence compile dev files.",
"version": "0.0.2",
"author": "Dmitry Bochkarev <dimabochkarev@gmail.com>",

@@ -6,0 +6,0 @@ "dependencies": {

@@ -38,2 +38,3 @@ # Polymorph

head
script(src="/sayhello.js", type="application/javascript")
body

@@ -40,0 +41,0 @@ h1 Jade template!