Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
browser-config
Advanced tools
Readme
You can use localStorage
or sessionStorage
. But is this convenient and performed like accessing property from an object ? No it's not.
yarn add browser-config
Importing the library
import Store from "browser-config";
const config = new Store();
// setting value
config.name = "Hello"
// By default it save data to the cache only and update/serialize data in next event loop.
// getting value
config.name // "hello"
// you can get config.name again and again it won't request to storage or deserialize,
// instead it will get data from the cache only.
[...Store.keys(config)] // ["name"]
// Store.keys return generators, you need to spread it to use as an array.
Object.fromEntries(config) // { name: "Hello" }
// or
Store.values(config) // { name: "Hello" }
// deleting
delete config.name
config.name // undefined
// clearing all the data
Store.clear(config) // length of cleared items;
// can support any serializable data
config.users = [{ name: 'Hello' }]
config.users // [{ name: 'Hello' }]
// mutation is not supported
config.users.push({name: 'New User'}); // x will not work
// adding new value to array
config.users = [ ...config.users, { name: 'New User'}]
const config1 = new Store('abcd'); // id
const config2 = new Store('dcba'); // id
config1.name = 'Something'
config2.name = 'Something else'
config1.name // Something
config2.name // Something else
const config = new Store('default')
config.name = 'Something'
config.email = 'johndoe@example.com'
for (const [ key, value ] of config) {
console.log({ key, value }) // { key: 'email', value: 'Something' } and so on...
}
By default it will save to localStorage and it is permanent, you can save it sessionStorage as well.
const config = new Store('some_id', {
validity: "session"
});
config.name = "Hello" // will be saved till browser closed.
interface IPerson {
name?: string;
age?: number
}
const person = Store.create<IPerson>();
person.age = 'hello' // error
person.age = 20 // pass
Sometimes you need to save data to other than localStorage, sessionStorage let's say in cookies.
import Store, { IDriver } from "browser-config";
class Driver implements IDriver {
set(key: string, val: string) {
// sourced from https://www.w3schools.com/js/js_cookies.asp
document.cookie = `${key}=${val}`;
return this;
}
get(key: string) {
// sourced from https://www.w3schools.com/js/js_cookies.asp
let name = key + "=";
let decodedCookie = decodeURIComponent(document.cookie);
let ca = decodedCookie.split(';');
for(let i = 0; i <ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
}
remove(key: string) {
// sourced from https://www.w3schools.com/js/js_cookies.asp
document.cookie = `${key}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`;
return this;
}
keys() {
// need to be implemented
}
}
const storage = new Store("1", { driver: new Driver() });
storage.data = 'hello';
expect(storage.data).toBe('hello');
import Store from "browser-config";
const store = new Store(id, option)
id?: string
unique for unique storageoption?
validity: "session" | "permanent"
validity of the data for particular storage, default is permanent
.driver: IDriver
custom driverStore.id(store): string
generated or passed idStore.keys(store: Store): Iterable<string>
get all the keysStore.values(store: Store): {[key: string]: any}
get all the valuesStore.clear(store): string
clearing all the valuesStore.update(store, data: object)
update values in bulkStore.set(store, data: object)
it will delete all the existing value and set the provided objectFAQs
localStorage/sessionStorage wrapper for convenient access.
The npm package browser-config receives a total of 19 weekly downloads. As such, browser-config popularity was classified as not popular.
We found that browser-config demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.