Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

key-file-storage

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

key-file-storage - npm Package Compare versions

Comparing version 2.2.4 to 2.2.5

4

package.json
{
"name": "key-file-storage",
"version": "2.2.4",
"version": "2.2.5",
"description": "Simple key-value storage directly on file system, maps each key to a separate file.",

@@ -38,3 +38,3 @@ "main": "dist/index.js",

],
"author": "Hessam A Shokravi <ahs502@gmail.com>",
"author": "Hessamoddin A Shokravi <ahs502@gmail.com>",
"license": "ISC",

@@ -41,0 +41,0 @@ "dependencies": {

@@ -15,9 +15,9 @@ # key-file-storage

```javascript
var kfs = require("key-file-storage")('my/storage/path');
const kfs = require("key-file-storage")('my/storage/path');
// Write something to file 'my/storage/path/myfile'
kfs.myfile = { mydata: 123 };
kfs.myfile = { x: 123 };
// Read contents of file 'my/storage/path/myfile'
var mydata = kfs.myfile.mydata;
const x = kfs.myfile.x;

@@ -32,3 +32,3 @@ // Delete file 'my/storage/path/myfile'

Installing package on Node.js (*Node.js **6.0.0** or higher is required*) :
Installing package on Node.js:
```sh

@@ -40,7 +40,7 @@ $ npm install key-file-storage

Initializing a key-file storage :
Initializing a key-file storage:
```javascript
var keyFileStorage = require("key-file-storage");
const keyFileStorage = require("key-file-storage");
var kfs = keyFileStorage('/storage/directory/path', caching);
const kfs = keyFileStorage('/storage/directory/path', caching);
```

@@ -60,3 +60,3 @@

As simple as native javascript objects :
As simple as native javascript objects:

@@ -88,3 +88,3 @@ ```javascript

Every one of the following calls **returns a promise** :
Every one of the following calls **returns a promise**:

@@ -146,3 +146,3 @@ ```javascript

You can query the list of all containing keys (*filenames*) within a collection (*folder*) like this (_**Note** that a collection path must end with a **forward slash** `'/'`_) :
You can query the list of all containing keys (*filenames*) within a collection (*folder*) like this (_**Note** that a collection path must end with a **forward slash** `'/'`_):

@@ -152,4 +152,8 @@ #### Synchronous API

```javascript
var keys = kfs['col/path/']
// keys = ['col/path/key1', 'col/path/sub/key2', ... ]
try {
const keys = kfs['col/path/']
// keys = ['col/path/key1', 'col/path/sub/key2', ... ]
} catch(error) {
// handle error...
}
```

@@ -160,4 +164,6 @@

```javascript
kfs('col/path/').then(function(keys) {
kfs('col/path/').then(keys => {
// keys = ['col/path/key1', 'col/path/sub/key2', ... ]
}, error => {
// handle error...
});

@@ -169,3 +175,6 @@ ```

```javascript
kfs('col/path/', function(error, keys) {
kfs('col/path/', (error, keys) => {
if (error) {
// handle error...
}
// keys = ['col/path/key1', 'col/path/sub/key2', ... ]

@@ -185,10 +194,12 @@ });

- **NOTE 5 :** When activated, caching will include queries on *collections* too.
## Example
```javascript
var keyFileStorage = require("key-file-storage");
const keyFileStorage = require("key-file-storage");
// Locate 'db' folder in the current directory as the storage path,
// Require 100 latest accessed key-values to be cached:
var kfs = keyFileStorage('./db', 100);
const kfs = keyFileStorage('./db', 100);

@@ -198,15 +209,17 @@ // Create file './db/users/hessam' containing this user data, synchronously:

name: "Hessam",
skills: { java: 10, csharp: 15 }
skills: {
java: 10,
csharp: 15
}
};
// Read file './db/users/hessam' as a JSON object, asynchronously:
kfs('users/hessam').then(function(hessamData) {
console.log("Hessam's java skill is ",
hessamData.skills.java);
kfs('users/hessam').then(hessam => {
console.log(`Hessam's java skill is ${hessam.skills.java}.`);
});
// Check whether file './db/users/mahdiar' exists or not, asynchronously:
'users/mahdiar' in kfs(function(error, exists) {
if(exists) {
console.log("We have Mahdiar's data!");
'users/mahdiar' in kfs((error, exists) => {
if (exists) {
console.log("User Mahdiar exists!");
}

@@ -216,3 +229,3 @@ });

// List all the keys in './db/users/', synchronously:
var allUsers = kfs['users/'];
const allUsers = kfs['users/'];
//=> ['users/hessam', 'users/mahdiar', ... ]

@@ -223,5 +236,5 @@ ```

The code is simple! It would be appreciated if you had any suggestions or contribution on it or detected any bug or issue.
It would be appreciated if you had any suggestions or contribution on this repository or submitted any issue.
+ See the code on [GitHub.com (key-file-storage)](https://github.com/ahs502/key-file-storage)
+ Contact me by [my gmail address](ahs502@gmail.com) *(Hessam A Shokravi)*
+ See the code on [GitHub](https://github.com/ahs502/key-file-storage)
+ Contact me by [my gmail address](ahs502@gmail.com) *(Hessamoddin A Shokravi)*
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