
Security News
Open Source Maintainers Demand Ability to Block Copilot-Generated Issues and PRs
Open source maintainers are urging GitHub to let them block Copilot from submitting AI-generated issues and pull requests to their repositories.
valuesaver
Advanced tools
A way to easily save your values with a key.
ValueSaver is an easy to use framework to easily save values by using a key. You can set values, get values, delete values and so much more.
The ValueSaver looks like a Map. The differences are tho that the ValueSaver is more flexibel and has more options. So it is for example possible to save your values with a custom id and import it again with the same custom id.
As the ValueSaver is just like a Map a class you can create one by using
const {ValueSaver} = require('valuesaver');
const save = new ValueSaver();
You can also insert values by using an array in the first argument by creating a ValueSaver. In the array you must put at least one JSON object. Every JSON object requires a key
and a value
.
const {ValueSaver} = require('valuesaver');
const save = new ValueSaver([{"key": "Some key", "value": "Some value"}]);
You can just like the Map class set a value by using the set
function. The first parameter will be seen as the key and the second parameter will be seen as the value. These value's can be accessed by using their key in the get function.
Note: By using the same key twice it will overwrite the last value. A key may only be a string or a number, a value may only be a string, number or an object.
const {ValueSaver} = require('valuesaver');
const save = new ValueSaver();
save.set(`Some key`, `Some value`);
You can get a value by calling the key in the get
function. The first key will be seen as the key and the function will return the value.
const {ValueSaver} = require('valuesaver');
const save = new ValueSaver();
save.set(`Some key`, `Some value`);
console.log(save.get(`Some key`));
// Output: Some value
You can delete a value by using the delete
function. The first parameter will be seen as the key.
const {ValueSaver} = require('valuesaver');
const save = new ValueSaver();
save.set(`Some key`, `Some value`);
console.log(save.get(`Some key`));
if(save.delete(`Some key`)) console.log(`Successfully deleted the value with the key 'Some key'!`);
else console.log(`The value with the key 'Some key' does not exist!`);
You can check if a value exists by using the hasValue
function. The first parameter is the value where you want to look for. The function will return a boolean.
const {ValueSaver} = require('valuesaver');
const save = new ValueSaver();
save.set(`Some key`, `Some value`);
if(save.hasValue(`Some value`)) console.log(`The value exists!`);
else console.log(`The value does not exist!`);
You can clear a ValueSaver by using the clear function.
const {ValueSaver} = require('valuesaver');
const save = new ValueSaver();
save.set(`Some key`, `Some value`);
save.clear();
It's sometime frustrating that you don't know the key anymore. You can use the keyByValue
function to get all the keys that have this value. The first parameter will be seen as the value. The function returns an array of all the key's.
const {ValueSaver} = require('valuesaver');
const save = new ValueSaver();
save.set(`Some key`, `Some value`);
console.log(save.keyByValue(`Some value`));
// Output: [{key: "Some key", value: "Some value"}]
You can use a filter to filter through the values. The filter required a function to filter. You can filter by key and by value.
const {ValueSaver} = require('valuesaver');
const save = new ValueSaver();
save.set(`Some key`, `Some value`);
console.log(save.filter(s => s.key === "Some key" && s.value === "Some value"));
// Output new ValueSaver with the keys and values
You can use a filter array to filter through the values. The filter required a function to filter. You can filter by key and by value.
const {ValueSaver} = require('valuesaver');
const save = new ValueSaver();
save.set(`Some key`, `Some value`);
console.log(save.filterArray(s => s.key === "Some key" && s.value === "Some value"));
// [{key: "Some key", value: "Some value"}]
You can use the foreach function which will call the callback for every value. The first parameter will be seen as the callback and must be a function.
const {ValueSaver} = require('valuesaver');
const save = new ValueSaver();
save.set(`Some key`, `Some value`);
save.forEach(value => console.log(value));
// Output: Some value
You can use the reduce function which will call the callback for every value. The first parameter will be seen as the callback and must be a function. The second parameter is the start value.
const {ValueSaver} = require('valuesaver');
const save = new ValueSaver();
save.set(`Some key`, `Some value`);
var value = save.reduce((str, item) => {
str += item;
return str;
}, ``);
// Output: Some value
You can use the map function which will call the callback for every value. The first parameter will be seen as the callback and must be a function.
const {ValueSaver} = require('valuesaver');
const save = new ValueSaver();
save.set(`Some key`, {someBoolean: true});
save.set(`Some other key`, {someBoolean: false});
var booleans = save.map(item => item.someBoolean);
// Output: [true, false]
You can concat two ValueSaver's together to one ValueSaver. The function requires one parameter which is the other ValueSaver to concat.
const {ValueSaver} = require('valuesaver');
const save1 = new ValueSaver();
const save2 = new ValueSaver();
save1.set(`Some key`, `Some value`);
save2.set(`Some other key`, `Some other value`);
var newValueSaver = save1.concat(save2);
// Output: new ValueSaver with both ValueSaver's keys and values
You can concat two ValueSaver's together to one array. The function requires one parameter which is the other ValueSaver to concat.
const {ValueSaver} = require('valuesaver');
const save1 = new ValueSaver();
const save2 = new ValueSaver();
save1.set(`Some key`, `Some value`);
save2.set(`Some other key`, `Some other value`);
var newValueSaver = save1.concatArray(save2);
// Output: [{"Some key": "Some value"}, {"Some other key": "Some other value"}]
You can easily convert a ValueSaver to an array by using the toArray
function.
const {ValueSaver} = require('valuesaver');
const save = new ValueSaver();
save.set(`Some key`, `Some value`);
console.log(save.toArray());
// Output: [{"Some key": "Some value"}]
You can easily convert a ValueSaver to a Map by using the toMap
function.
const {ValueSaver} = require('valuesaver');
const save = new ValueSaver();
save.set(`Some key`, `Some value`);
console.log(save.toMap());
// Output: Map(1) {'Some key' => 'Some value'}
You can convert the ValueSaver to a readable array for the ValueSaver. The array can be used for a new ValueSaver or to overwrite a ValueSaver.
const {ValueSaver} = require('valuesaver');
const save = new ValueSaver();
save.set(`Some key`, `Some value`);
console.log(save.toReadableArray());
// Output: [{"key": "Some key", "value": "Some value"}]
You can overwrite a ValueSaver with an array. This must be a readable array just like the output of the toReadableArray
function.
const {ValueSaver} = require('valuesaver');
const save = new ValueSaver();
save.set(`Some key`, `Some value`);
save.writeValueSaver([{"key": "New key", "value": "New value"}]);
console.log(save.toArray());
// Output: [{"New key": "New value"}]
You can create a new ValueSaver with an array by using the fromArray
function. The function requires one parameter which is the array.
const {ValueSaver} = require('valuesaver');
const save = new ValueSaver();
const array = [{'Some key': 'Some value'}];
const newValueSaver = save.fromArray(array);
console.log(newValueSaver.toArray());
// Output: [{"Some key": "Some value"}]
You can create a new ValueSaver with a map by using the fromMap
function. The function requires one parameter which is the map.
const {ValueSaver} = require('valuesaver');
const save = new ValueSaver();
const map = new Map();
map.set('Some key', 'Some value');
const newValueSaver = save.fromMap(map);
console.log(newValueSaver.toArray());
// Output: [{"Some key": "Some value"}]
To insert a new key with a new value you can use the insertValue
function. The first parameter must be an object with a key and a value.
const {ValueSaver} = require('valuesaver');
const save = new ValueSaver();
save.set(`Some key`, `Some value`);
save.insertValue({"key": "Some extra key", "value": "Some extra value"});
console.log(save.toArray());
// Output: [{"Some key": "Some value"}, {"Some extra key": "Some extra value"}]
To import a ValueSaver with an id you can use the import
function. The function requires an id which is a string or a number. The id is the custom id that you create by saving it.
const {ValueSaver} = require('valuesaver');
const save = new ValueSaver();
save.set(`Some key`, `Some value`);
(async () => {
var import = await save.import(123);
if(import) console.log(`Imported the ValueSaver with the id 123`);
else console.log(`The ValueSaver with the id 123 does not exist.`);
})();
By saving a ValueSaver you will be able to use it again when your NodeJS server was offline for example. You can use the import
function to use it again. The save
function requires a custom id which is the first parameter. The second parameter is the concat
parameter. If there is already another ValueSaver saved with this id will it by default overwrite the other ValueSaver. By setting the concat
parameter to true
it will concat the two ValueSavers to one ValueSaver.
const {ValueSaver} = require('valuesaver');
const save = new ValueSaver();
save.set(`Some key`, `Some value`);
(async () => {
await save.save(123, true);
console.log(`Saved the ValueSaver with the custom id 123`);
})();
If you forgot a save, you can use the function getAllSaves
to get all the saved ValueSavers. It will return an array with all the id's of the saved ValueSavers.
const {ValueSaver} = require('valuesaver');
const save = new ValueSaver();
save.set(`Some key`, `Some value`);
save.save(123);
console.log(save.getAllSaves());
// Output: [123]
You can remove a save by saving it or importing it and then use the removeSave
function. It will return a Promise which will be fullfilled once the save has been deleted.
const {ValueSaver} = require('valuesaver');
const save = new ValueSaver();
save.set(`Some key`, `Some value`);
save.import(123);
(async () => {
await save.removeSave();
})();
You can remove all saves by using the removeAllSaves
function. This function will remove all saves from all ValueSavers that have been saved.
const {ValueSaver} = require('valuesaver');
const save = new ValueSaver();
save.set(`Some key`, `Some value`);
(async () => {
await save.removeAllSaves();
})();
FAQs
Save values in a storage and import them later back
The npm package valuesaver receives a total of 118 weekly downloads. As such, valuesaver popularity was classified as not popular.
We found that valuesaver 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
Open source maintainers are urging GitHub to let them block Copilot from submitting AI-generated issues and pull requests to their repositories.
Research
Security News
Malicious Koishi plugin silently exfiltrates messages with hex strings to a hardcoded QQ account, exposing secrets in chatbots across platforms.
Research
Security News
Malicious PyPI checkers validate stolen emails against TikTok and Instagram APIs, enabling targeted account attacks and dark web credential sales.