Compare commits

...

7 commits

Author SHA1 Message Date
Killer Boss Original
c902d92711
Fix 2023-04-12 18:42:15 +02:00
Killer Boss Original
90670ebb7b
. 2023-04-12 18:37:16 +02:00
Killer Boss Original
363492aef5
test 2023-04-12 18:29:31 +02:00
Killer Boss Original
41d589ccbc
Merge pull request #13 from ThunderNetworkRaD/dependabot/npm_and_yarn/typescript-5.0.3
Bump typescript from 4.9.5 to 5.0.3
2023-04-03 12:36:28 +02:00
dependabot[bot]
74f4f42e50
Bump typescript from 4.9.5 to 5.0.3
Bumps [typescript](https://github.com/Microsoft/TypeScript) from 4.9.5 to 5.0.3.
- [Release notes](https://github.com/Microsoft/TypeScript/releases)
- [Commits](https://github.com/Microsoft/TypeScript/commits)

---
updated-dependencies:
- dependency-name: typescript
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-04-03 08:05:46 +00:00
Killer Boss Original
492c49a086
Update package.json 2023-02-23 12:26:39 +01:00
Killer Boss Original
c8410b0c6f
2023.02.23.4 2023-02-23 12:17:13 +01:00
2 changed files with 17 additions and 15 deletions

View file

@ -1,6 +1,6 @@
{
"name": "mit.db",
"version": "2023.02.23.3",
"version": "2023.04.12",
"description": "An easy and quick database",
"main": "build/index.js",
"types": "build/index.d.ts",
@ -11,7 +11,7 @@
"type": "git",
"url": "git+https://github.com/ThunderNetworkRaD/mit.db.git"
},
"author": "Thunder Network Development | Killer Boss Original",
"author": "ThunderNetworkRaD | Killer Boss Original",
"license": "ISC",
"bugs": {
"url": "https://github.com/ThunderNetworkRaD/mit.db/issues"
@ -20,6 +20,6 @@
"devDependencies": {
"@types/node": "^18.14.0",
"tslib": "^2.4.1",
"typescript": "^4.9.5"
"typescript": "^5.0.3"
}
}

View file

@ -5,6 +5,9 @@ const writeDB = promisify(fs.writeFile);
class MitDB {
readonly db;
filename: string;
options: any;
dirname: string;
/**
* @constructor
@ -13,17 +16,18 @@ class MitDB {
* @param options Options to pass in the constructor
* @param options.dirname where to put the database?
*/
constructor(fn: string, options?: { dirname: string }) {
let dirname;
constructor(filename: string, options?: { dirname: string }) {
if (options && options.dirname) {
dirname = options.dirname;
this.dirname = options.dirname;
} else {
dirname = 'data';
this.dirname = 'data';
}
if (!fs.existsSync(dirname)) fs.mkdirSync(dirname);
this.filename = filename;
this.db = `./${dirname}/${fn}`
if (!fs.existsSync(this.dirname)) fs.mkdirSync(this.dirname);
this.db = `./${this.dirname}/${this.filename}`;
}
/**
@ -97,13 +101,13 @@ class MitDB {
/**
*
* @param callbackfn
* @param callbackfilename
*/
forEach(callback: (value: any, key: any, map: Map<any, any>) => void) {
forEach(callback: (value: any, key: any) => void) {
const file = fs.readFileSync(this.db);
const data: any[] = JSON.parse(file.toString());
data.forEach((pair: any) => callback(pair.value, pair.key, map));
data.forEach((pair: any) => callback(pair.value, pair.key));
}
/**
@ -122,8 +126,6 @@ class MitDB {
await writeDB(this.db, JSON.stringify(data));
return true;
} else if (!map) {
return false;
}
} catch {}
return 'error';