khalby786 / jsoning Goto Github PK
View Code? Open in Web Editor NEW✨ A simple key-value JSON-based lightweight database. ✨
Home Page: http://jsoning.js.org/
License: MIT License
✨ A simple key-value JSON-based lightweight database. ✨
Home Page: http://jsoning.js.org/
License: MIT License
If jsoning has written at least one value, and the json file is changed in the file system by a different process, and then set()
is called with some value, then jsoning overwrites the json file with the previously known values.
let db = new jsoning("database.json");
db.set("one", "one");
// Now remove database.json from the file system
db.set("two", "two");
After executing the sample code (note the comment about removing the file), the expected behavior would be that database.json contains {"two": "two"}
.
Faulty behavior: The database.json contains {"one": "one", "two": "two"}
.
db.math("money", "add", 200); not work
Is your feature request related to a problem? Please describe.
I want to use your package in a Typescript project
Describe the solution you'd like
Add Typings for jsoning
Describe alternatives you've considered
Only alternative would be using another package
It's a good practice. Add it to .gitignore
the test Jsoning#has - existing element
checks for key bar
, but an earlier test of clear
has deleted it. and the test checks for false
instead of true
n/a
the test exercises a case where the key exists
n/a
Hello, im dream.
so i would like suggest some function and modules that you can add.
im thinking of adding these functions to your npm package so i was just asking for permission if its okay!
if its okay then i can start the code.
Following the instruction, we can add to the array. But I could not find a way how to remove an element from array.
// push stuff to an array for a particular key
await db.push("transformers", "optimus prime");
await db.push("transformers", "bumblebee");
await db.push("transformers", "iron hide");
Is it possible to include just the source file directly?
I've got a PHP project called anonupload ( supernova3339/anonupload )
The kicker is it doesn't use a database. I want to add in multi-user support and finish off plugins. Instead of going crazy, I found your kick-ass project and would like to know if this is possible.
If yes, I'll integrate your project into anonupload as a JsonDB
If no, I'll finish off what I already started.
If confused, other, whatever, feel free to ask me questions.
If implementable, I'll write code to make it possible, then I'll send a PR for said code
Prototype pollution by setting a value with a key of "hasOwnProperty"
await db.set("hasOwnProperty", "something");
await db.has("hasOwnProperty"); // Error is thrown
This vulnerability causes the addition or modification of an existing property that will exist on all objects and may lead to Denial of Service or Code Execution under specific circumstances.
i also already made a PR to patch this vulnerability #8
the async-ness is an internal implementation detail. as far as callers and typescript are concerned, they're methods that return a Promise.
const c = db.clear();
// c is Promise, not boolean
n/a
in jsoning.d.ts
Line 144 in 46e0f1b
any
because I am working with objects here and keep getting an lint errorIs your feature request related to a problem? Please describe.
No problem per se
Describe the solution you'd like
I would like for the class to take a type parameter upon creation, restricting the database to that specific type and thus simplifying the programming.
Describe alternatives you've considered
I ended up doing this in my code, but it would be helpful if the class itself already accepted the type parameter.
class Database<T> extends Jsoning {
constructor(path: string) {
super(path);
}
async set(key: string, value: T): Promise<boolean> {
return await super.set(key, value);
}
get(key: string): Promise<T> {
return super.get(key);
}
all(): { [key: string]: T } {
return super.all();
}
}
Additional context
TypeScript v4.9.5
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.