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

@p9m/local-storage-service

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@p9m/local-storage-service - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

README.md

1

dist/esm/index.d.ts

@@ -9,3 +9,2 @@ interface Model {

private localStorage;
private static jsonData;
constructor(name: string);

@@ -12,0 +11,0 @@ private save;

@@ -1,57 +0,29 @@

function S4() {
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
}
;
function guid() {
return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
}
;
import { v4 as uuidv4 } from 'uuid';
var LocalStorageService = (function () {
function LocalStorageService(name) {
this.localStorage = function () {
return localStorage;
};
this.localStorage = window.localStorage;
if (!name) {
throw new Error("Namespace is required.");
throw new Error('Namespace is required.');
}
this.name = name;
var store = this.localStorage().getItem(this.name);
this.records = (store && store.split(",")) || [];
var store = this.localStorage.getItem(this.name);
this.records = (store && store.split(',')) || [];
}
LocalStorageService.jsonData = function (data) {
return data && JSON.parse(data);
};
;
LocalStorageService.prototype.save = function () {
this.localStorage().setItem(this.name, this.records.join(","));
this.localStorage.setItem(this.name, this.records.join(','));
};
;
LocalStorageService.prototype.get = function (id) {
var data = this.localStorage().getItem(this.name + "-" + id);
if (!data) {
return null;
}
else {
return LocalStorageService.jsonData(data);
}
var data = this.localStorage.getItem("".concat(this.name, "-").concat(id));
return data ? JSON.parse(data) : null;
};
;
LocalStorageService.prototype.getAll = function () {
var _this = this;
return this.records.map(function (recordId) {
var record = _this.localStorage().getItem(_this.name + "-" + recordId);
if (record) {
return LocalStorageService.jsonData(record);
}
else {
return null;
}
});
return this.records.map(function (recordId) { return _this.get(recordId); });
};
LocalStorageService.prototype.create = function (model) {
if (!model.id) {
model.id = guid();
model.id = uuidv4();
}
this.localStorage().setItem(this.name + "-" + model.id, JSON.stringify(model));
this.records.push(model.id.toString());
this.localStorage.setItem("".concat(this.name, "-").concat(model.id), JSON.stringify(model));
this.records.push(model.id);
this.save();

@@ -61,5 +33,5 @@ return this.get(model.id);

LocalStorageService.prototype.update = function (model) {
this.localStorage().setItem(this.name + "-" + model.id, JSON.stringify(model));
if (!this.records.find(function (element) { return element === model.id.toString(); })) {
this.records.push(model.id.toString());
this.localStorage.setItem("".concat(this.name, "-").concat(model.id), JSON.stringify(model));
if (!this.records.includes(model.id)) {
this.records.push(model.id);
this.save();

@@ -70,15 +42,10 @@ }

LocalStorageService.prototype.delete = function (id) {
this.localStorage().removeItem(this.name + "-" + id);
this.records = this.records.filter(function (recordId) {
return recordId !== id.toString();
});
this.localStorage.removeItem("".concat(this.name, "-").concat(id));
this.records = this.records.filter(function (recordId) { return recordId !== id; });
this.save();
return true;
};
;
LocalStorageService.prototype.deleteAll = function () {
var _this = this;
this.records.forEach(function (recordId) {
_this.localStorage().removeItem(_this.name + "-" + recordId);
});
this.records.forEach(function (recordId) { return _this.localStorage.removeItem("".concat(_this.name, "-").concat(recordId)); });
this.records = [];

@@ -85,0 +52,0 @@ this.save();

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

!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.LocalStorageService=e():t.LocalStorageService=e()}(this,(()=>(()=>{"use strict";var t={d:(e,r)=>{for(var o in r)t.o(r,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:r[o]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};function r(){return(65536*(1+Math.random())|0).toString(16).substring(1)}t.d(e,{default:()=>o});const o=function(){function t(t){if(this.localStorage=function(){return localStorage},!t)throw new Error("Namespace is required.");this.name=t;var e=this.localStorage().getItem(this.name);this.records=e&&e.split(",")||[]}return t.jsonData=function(t){return t&&JSON.parse(t)},t.prototype.save=function(){this.localStorage().setItem(this.name,this.records.join(","))},t.prototype.get=function(e){var r=this.localStorage().getItem(this.name+"-"+e);return r?t.jsonData(r):null},t.prototype.getAll=function(){var e=this;return this.records.map((function(r){var o=e.localStorage().getItem(e.name+"-"+r);return o?t.jsonData(o):null}))},t.prototype.create=function(t){return t.id||(t.id=r()+r()+"-"+r()+"-"+r()+"-"+r()+"-"+r()+r()+r()),this.localStorage().setItem(this.name+"-"+t.id,JSON.stringify(t)),this.records.push(t.id.toString()),this.save(),this.get(t.id)},t.prototype.update=function(t){return this.localStorage().setItem(this.name+"-"+t.id,JSON.stringify(t)),this.records.find((function(e){return e===t.id.toString()}))||(this.records.push(t.id.toString()),this.save()),this.get(t.id)},t.prototype.delete=function(t){return this.localStorage().removeItem(this.name+"-"+t),this.records=this.records.filter((function(e){return e!==t.toString()})),this.save(),!0},t.prototype.deleteAll=function(){var t=this;return this.records.forEach((function(e){t.localStorage().removeItem(t.name+"-"+e)})),this.records=[],this.save(),!0},t}();return e.default})()));
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.LocalStorageService=e():t.LocalStorageService=e()}(this,(()=>(()=>{"use strict";var t={d:(e,r)=>{for(var o in r)t.o(r,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:r[o]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};t.d(e,{default:()=>u});const r={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};var o,n=new Uint8Array(16);function i(){if(!o&&!(o="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return o(n)}for(var a=[],c=0;c<256;++c)a.push((c+256).toString(16).slice(1));const s=function(t,e,o){if(r.randomUUID&&!e&&!t)return r.randomUUID();var n=(t=t||{}).random||(t.rng||i)();if(n[6]=15&n[6]|64,n[8]=63&n[8]|128,e){o=o||0;for(var c=0;c<16;++c)e[o+c]=n[c];return e}return function(t,e=0){return(a[t[e+0]]+a[t[e+1]]+a[t[e+2]]+a[t[e+3]]+"-"+a[t[e+4]]+a[t[e+5]]+"-"+a[t[e+6]]+a[t[e+7]]+"-"+a[t[e+8]]+a[t[e+9]]+"-"+a[t[e+10]]+a[t[e+11]]+a[t[e+12]]+a[t[e+13]]+a[t[e+14]]+a[t[e+15]]).toLowerCase()}(n)},u=function(){function t(t){if(this.localStorage=window.localStorage,!t)throw new Error("Namespace is required.");this.name=t;var e=this.localStorage.getItem(this.name);this.records=e&&e.split(",")||[]}return t.prototype.save=function(){this.localStorage.setItem(this.name,this.records.join(","))},t.prototype.get=function(t){var e=this.localStorage.getItem("".concat(this.name,"-").concat(t));return e?JSON.parse(e):null},t.prototype.getAll=function(){var t=this;return this.records.map((function(e){return t.get(e)}))},t.prototype.create=function(t){return t.id||(t.id=s()),this.localStorage.setItem("".concat(this.name,"-").concat(t.id),JSON.stringify(t)),this.records.push(t.id),this.save(),this.get(t.id)},t.prototype.update=function(t){return this.localStorage.setItem("".concat(this.name,"-").concat(t.id),JSON.stringify(t)),this.records.includes(t.id)||(this.records.push(t.id),this.save()),this.get(t.id)},t.prototype.delete=function(t){return this.localStorage.removeItem("".concat(this.name,"-").concat(t)),this.records=this.records.filter((function(e){return e!==t})),this.save(),!0},t.prototype.deleteAll=function(){var t=this;return this.records.forEach((function(e){return t.localStorage.removeItem("".concat(t.name,"-").concat(e))})),this.records=[],this.save(),!0},t}();return e.default})()));
{
"name": "@p9m/local-storage-service",
"version": "1.0.2",
"version": "1.0.3",
"description": "localStorage wrapper for CRUD operations",

@@ -30,6 +30,10 @@ "main": "dist/umd/index.js",

"devDependencies": {
"@types/uuid": "^9.0.8",
"typescript": "^5.4.5",
"webpack": "^5.91.0",
"webpack-cli": "^5.1.4"
},
"dependencies": {
"uuid": "^10.0.0"
}
}

@@ -1,9 +0,3 @@

function S4() {
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
};
import { v4 as uuidv4 } from 'uuid';
function guid() {
return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
};
interface Model {

@@ -17,41 +11,24 @@ id: string;

private records: string[];
private localStorage = () => {
return localStorage;
};
private localStorage = window.localStorage;
private static jsonData(data: string) {
return data && JSON.parse(data);
};
constructor(name: string) {
if (!name) {
throw new Error("Namespace is required.");
throw new Error('Namespace is required.');
}
this.name = name;
const store = this.localStorage().getItem(this.name);
this.records = (store && store.split(",")) || [];
const store = this.localStorage.getItem(this.name);
this.records = (store && store.split(',')) || [];
}
private save() {
this.localStorage().setItem(this.name, this.records.join(","));
};
this.localStorage.setItem(this.name, this.records.join(','));
}
public get(id: string) {
const data = this.localStorage().getItem(this.name + "-" + id);
if (!data) {
return null;
} else {
return LocalStorageService.jsonData(data);
}
};
const data = this.localStorage.getItem(`${this.name}-${id}`);
return data ? JSON.parse(data) : null;
}
public getAll() {
return this.records.map((recordId) => {
const record = this.localStorage().getItem(this.name + "-" + recordId);
if (record) {
return LocalStorageService.jsonData(record);
} else {
return null;
}
})
return this.records.map((recordId) => this.get(recordId));
}

@@ -61,6 +38,6 @@

if (!model.id) {
model.id = guid();
model.id = uuidv4();
}
this.localStorage().setItem(this.name + "-" + model.id, JSON.stringify(model));
this.records.push(model.id.toString());
this.localStorage.setItem(`${this.name}-${model.id}`, JSON.stringify(model));
this.records.push(model.id);
this.save();

@@ -71,5 +48,5 @@ return this.get(model.id);

public update(model: Model) {
this.localStorage().setItem(this.name + "-" + model.id, JSON.stringify(model));
if (!this.records.find(element => element === model.id.toString())) {
this.records.push(model.id.toString());
this.localStorage.setItem(`${this.name}-${model.id}`, JSON.stringify(model));
if (!this.records.includes(model.id)) {
this.records.push(model.id);
this.save();

@@ -81,14 +58,10 @@ }

public delete(id: string) {
this.localStorage().removeItem(this.name + "-" + id);
this.records = this.records.filter((recordId) => {
return recordId !== id.toString();
});
this.localStorage.removeItem(`${this.name}-${id}`);
this.records = this.records.filter((recordId) => recordId !== id);
this.save();
return true;
};
}
public deleteAll() {
this.records.forEach((recordId) => {
this.localStorage().removeItem(this.name + "-" + recordId)
});
this.records.forEach((recordId) => this.localStorage.removeItem(`${this.name}-${recordId}`));
this.records = [];

@@ -95,0 +68,0 @@ this.save();

@@ -6,3 +6,2 @@ {

"outDir": "./dist/esm",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,

@@ -16,4 +15,7 @@ "strict": true,

"noImplicitReturns": true,
"declaration": true
"declaration": true,
"moduleResolution": "Node",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true
}
}
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