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.
@kifuan/json-db
Advanced tools
Readme
This is a simple database powered by JSON files.
npm i @kifuan/json-db
# or yarn add @kifuan/json-db
It's easy to use this lightweight module.
import { connect } from '@kifuan/json-db'
type Data = {
foo: string
}
const conn = await connect<Data>({
file: './data.json',
delay: 1000,
defaultData: {
foo: 'bar'
},
onSaved() {
console.log(`Callback onSaved is called. this.foo is ${this.foo}`)
}
})
conn.foo = 'baz'
The connection object conn
is just like a normal JavaScript object.
However, if the value has changed, it would save the object to given file after delay
.
Additionally, this
will be the data object in onSaved
callback function.
If you want it to read a object directly, you can try this:
import { connect, createObjectJSONFile } from '@kifuan/json-db'
type Data = {
foo: string
}
const conn = await connect<Data>({
file: createObjectJSONFile({ foo: 114514 }),
delay: 1000,
defaultData: {
foo: 'bar'
}
})
console.assert(conn.foo === 114514)
It will create a "file" in memory for the connections to read.
Here is another example to create your own file object:
import { connect, createObjectJSONFile } from '@kifuan/json-db'
type Data = {
foo: string
}
const conn = await connect<Data>({
file: {
async read() {
return await GET()
},
async write(json) {
await PUT(json)
}
},
delay: 1000,
defaultData: {
foo: 'bar'
}
})
console.log(conn.foo)
However, this example can not run directly. The only thing I want to tell you is that you can customize the file object with two async methods: read
and write
.
FAQs
Database Based on JSON Files
We found that @kifuan/json-db 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.