Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

angular2-locker

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular2-locker - npm Package Compare versions

Comparing version 0.1.5 to 0.1.6

src/index.ts

176

dist/locker.js

@@ -59,86 +59,8 @@ (function webpackUniversalModuleDefinition(root, factory) {

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Driver_1 = __webpack_require__(1);
var MemoryStorage_1 = __webpack_require__(2);
var DRIVERS = {
SESSION: new Driver_1.Driver(sessionStorage),
LOCAL: new Driver_1.Driver(localStorage),
MEMORY: new Driver_1.Driver(new MemoryStorage_1.MemoryStorage())
};
exports.DRIVERS = DRIVERS;
exports.Driver = Driver_1.Driver;
var Locker_1 = __webpack_require__(2);
exports.Locker = Locker_1.Locker;
exports.DRIVERS = Locker_1.DRIVERS;
var Locker = function () {
function Locker(_ref) {
var driverNamespace = _ref.driverNamespace;
var _ref$defaultDriverTyp = _ref.defaultDriverType;
var defaultDriverType = _ref$defaultDriverTyp === undefined ? DRIVERS.SESSION : _ref$defaultDriverTyp;
_classCallCheck(this, Locker);
this.setNamespace(driverNamespace);
this.driver = defaultDriverType;
}
_createClass(Locker, [{
key: 'setNamespace',
value: function setNamespace() {
var namespace = arguments.length <= 0 || arguments[0] === undefined ? '' : arguments[0];
this.namespace = namespace;
}
}, {
key: 'useDriver',
value: function useDriver(driver) {
return new Locker({
defaultDriverType: driver.isSupported() ? driver : DRIVERS.MEMORY,
driverNamespace: this.namespace
});
}
}, {
key: 'set',
value: function set(key, data, expiry) {
if (expiry) console.warn('Expiry is not implimented yet');
this.driver.set(this._makeKey(key), data);
}
}, {
key: 'get',
value: function get(key) {
return this.driver.get(this._makeKey(key));
}
}, {
key: 'has',
value: function has(key) {
return this.driver.has(this._makeKey(key));
}
}, {
key: 'remove',
value: function remove(key) {
this.driver.remove(this._makeKey(key));
}
}, {
key: 'key',
value: function key(index) {
return this.driver.key(index);
}
}, {
key: 'clear',
value: function clear() {
this.driver.clear();
}
}, {
key: '_makeKey',
value: function _makeKey(key) {
return this.namespace + ':' + key;
}
}]);
return Locker;
}();
Locker.DRIVERS = DRIVERS;
exports.Locker = Locker;
/***/ },

@@ -227,2 +149,92 @@ /* 1 */

/* 2 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Driver_1 = __webpack_require__(1);
var MemoryStorage_1 = __webpack_require__(3);
var DRIVERS = {
SESSION: new Driver_1.Driver(sessionStorage),
LOCAL: new Driver_1.Driver(localStorage),
MEMORY: new Driver_1.Driver(new MemoryStorage_1.MemoryStorage())
};
exports.DRIVERS = DRIVERS;
var Locker = function () {
function Locker(_ref) {
var driverNamespace = _ref.driverNamespace;
var _ref$defaultDriverTyp = _ref.defaultDriverType;
var defaultDriverType = _ref$defaultDriverTyp === undefined ? DRIVERS.SESSION : _ref$defaultDriverTyp;
_classCallCheck(this, Locker);
this.setNamespace(driverNamespace);
this.driver = defaultDriverType;
}
_createClass(Locker, [{
key: 'setNamespace',
value: function setNamespace() {
var namespace = arguments.length <= 0 || arguments[0] === undefined ? '' : arguments[0];
this.namespace = namespace;
}
}, {
key: 'useDriver',
value: function useDriver(driver) {
return new Locker({
defaultDriverType: driver.isSupported() ? driver : DRIVERS.MEMORY,
driverNamespace: this.namespace
});
}
}, {
key: 'set',
value: function set(key, data, expiry) {
if (expiry) console.warn('Expiry is not implimented yet');
this.driver.set(this._makeKey(key), data);
}
}, {
key: 'get',
value: function get(key) {
return this.driver.get(this._makeKey(key));
}
}, {
key: 'has',
value: function has(key) {
return this.driver.has(this._makeKey(key));
}
}, {
key: 'remove',
value: function remove(key) {
this.driver.remove(this._makeKey(key));
}
}, {
key: 'key',
value: function key(index) {
return this.driver.key(index);
}
}, {
key: 'clear',
value: function clear() {
this.driver.clear();
}
}, {
key: '_makeKey',
value: function _makeKey(key) {
return this.namespace ? this.namespace + ':' + key : key;
}
}]);
return Locker;
}();
Locker.DRIVERS = DRIVERS;
exports.Locker = Locker;
/***/ },
/* 3 */
/***/ function(module, exports) {

@@ -229,0 +241,0 @@

@@ -1,1 +0,1 @@

Error.stackTraceLimit = Infinity require('es6-shim') require('angular2/bundles/angular2-polyfills.js') require('angular2/testing') /* Ok, this is kinda crazy. We can use the the context method on require that webpack created in order to tell webpack what files we actually want to require or import. Below, context will be an function/object with file names as keys. using that regex we are saying look in client/app and find any file that ends with spec.js and get its path. By passing in true we say do this recursively */ var appContext = require.context('./src', true, /\.spec\.ts/) // get all the files, for each file, call the context function // that will require the file and load it up here. Context will // loop and require those spec files here appContext.keys().forEach(appContext) // Select BrowserDomAdapter. // see https://github.com/AngularClass/angular2-webpack-starter/issues/124 // Somewhere in the test setup var testing = require('angular2/testing') var browser = require('angular2/platform/testing/browser') testing.setBaseTestProviders(browser.TEST_BROWSER_PLATFORM_PROVIDERS, browser.TEST_BROWSER_APPLICATION_PROVIDERS)
Error.stackTraceLimit = Infinity require('babel-register') require('phantomjs-polyfill') require('es6-shim') require('angular2/bundles/angular2-polyfills.js') require('angular2/testing') /* Ok, this is kinda crazy. We can use the the context method on require that webpack created in order to tell webpack what files we actually want to require or import. Below, context will be an function/object with file names as keys. using that regex we are saying look in client/app and find any file that ends with spec.js and get its path. By passing in true we say do this recursively */ var appContext = require.context('./test', true, /\.spec\.ts/) // get all the files, for each file, call the context function // that will require the file and load it up here. Context will // loop and require those spec files here appContext.keys().forEach(appContext) // Select BrowserDomAdapter. // see https://github.com/AngularClass/angular2-webpack-starter/issues/124 // Somewhere in the test setup var testing = require('angular2/testing') var browser = require('angular2/platform/testing/browser') testing.setBaseTestProviders(browser.TEST_BROWSER_PLATFORM_PROVIDERS, browser.TEST_BROWSER_APPLICATION_PROVIDERS)

@@ -42,3 +42,3 @@ // Karma configuration

// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
reporters: ['spec'],

@@ -45,0 +45,0 @@

{
"name": "angular2-locker",
"version": "0.1.5",
"version": "0.1.6",
"description": "angular2 library for managing session and locker storage, has backup for inmemory if neither are supported",

@@ -41,3 +41,2 @@ "main": "index.js",

"karma-jasmine": "^0.3.7",
"karma-phantomjs-shim": "^1.2.0",
"karma-phantomjs2-launcher": "^0.5.0",

@@ -47,2 +46,3 @@ "karma-sourcemap-loader": "^0.3.7",

"karma-webpack": "^1.7.0",
"phantomjs-polyfill": "0.0.1",
"phantomjs-prebuilt": "^2.1.4",

@@ -49,0 +49,0 @@ "reflect-metadata": "^0.1.3",

@@ -20,3 +20,3 @@ declare const sessionStorage, localStorage

constructor({driverNamespace, defaultDriverType = DRIVERS.SESSION}) {
constructor({driverNamespace, defaultDriverType = DRIVERS.SESSION}: {driverNamespace?: string, defaultDriverType?: Driver}) {
this.setNamespace(driverNamespace)

@@ -56,3 +56,3 @@ this.driver = defaultDriverType

public key(index) {
public key(index?) {
return this.driver.key(index)

@@ -66,4 +66,4 @@ }

private _makeKey(key: string): string {
return `${this.namespace}:${key}`
return this.namespace ? `${this.namespace}:${key}` : key
}
}

@@ -1,46 +0,9 @@

import {
it,
inject,
injectAsync,
beforeEachProviders,
TestComponentBuilder,
} from 'angular2/testing'
import {provide} from "angular2/core"
import {TestDriver} from './TestDriver'
import {Locker} from '../src/Locker'
import {DRIVERS} from '../src/Locker'
const CUSTOM_NAMESPACE = 'angular2-locker'
const SEPERATOR = ':'
describe('Locker', function() {
describe('Default Config', function() {
beforeEachProviders(() => [Locker])
it('uses session cache', inject([Locker], function(locker: Locker) {
expect(locker.driver).toEqual(Locker.DRIVERS.SESSION)
}))
})
describe('Custom Namespace', function() {
beforeEachProviders(() => provide(Locker, {useValue: new Locker({driverNamespace: CUSTOM_NAMESPACE})}))
it('uses namespace in keys', inject([Locker], function(locker: Locker) {
var dummy = {
key: 'TEST',
data: `TEST-${Math.random() * 1000}`
}
locker.set(dummy.key, dummy.data)
expect(locker.key()).toEqual(CUSTOM_NAMESPACE + SEPERATOR + dummy.key)
}))
})
describe('Session Cache', function() {
beforeEachProviders(() => provide(Locker, {useValue: new Locker({defaultDriverType: Locker.DRIVERS.SESSION})}))
})
describe('Local Storage', function() {
beforeEachProviders(() => provide(Locker, {useValue: new Locker({defaultDriverType: Locker.DRIVERS.LOCAL})}))
})
TestDriver('MemoryDriver', DRIVERS.MEMORY)
TestDriver('SessionDriver', DRIVERS.SESSION)
TestDriver('LocalDriver', DRIVERS.LOCAL)
})

@@ -12,5 +12,4 @@ {

"typings/browser.d.ts",
"typings/browser/",
"test"
"typings/browser/"
]
}

@@ -6,3 +6,5 @@ {

"ambientDependencies": {},
"ambientDevDependencies": {}
"ambientDevDependencies": {
"jasmine": "github:DefinitelyTyped/DefinitelyTyped/jasmine/jasmine.d.ts#dd638012d63e069f2c99d06ef4dcc9616a943ee4"
}
}

@@ -11,3 +11,3 @@ import path from 'path'

context: CONTEXT,
entry: './src/Locker.ts',
entry: './src/index.ts',

@@ -25,3 +25,3 @@ output: {

loader: 'babel!ts',
include: [createPath('src')],
include: [createPath('src'), createPath('test')],
exclude: [createPath('node_modules')]

@@ -28,0 +28,0 @@ }]

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc