configuration
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -5,3 +5,3 @@ import { Data, DataRaw, DataUpdate, ProviderStorageOptions } from '../types'; | ||
id: string; | ||
storage: Storage; | ||
storage?: Storage; | ||
constructor(options: Partial<Options>); | ||
@@ -8,0 +8,0 @@ readSync(): DataUpdate; |
@@ -16,4 +16,7 @@ "use strict"; | ||
this.storage = options.storage; | ||
this.init(); | ||
} | ||
readSync() { | ||
if (!this.storage) | ||
return super.readSync(); | ||
const dataRaw = this.storage.getItem(this.id) || config_1.DEFAULTS.dataRaw, data = serializer_1.default.deserialize(dataRaw); | ||
@@ -23,2 +26,4 @@ return { data, dataRaw }; | ||
writeSync(data, force = false) { | ||
if (!this.storage) | ||
return super.writeSync(data, force); | ||
if (!force && this.isEqual(data)) | ||
@@ -25,0 +30,0 @@ return; |
@@ -5,3 +5,5 @@ "use strict"; | ||
const fs = require("graceful-fs"); | ||
const path = require("path"); | ||
const util = require("util"); | ||
const folder_1 = require("./folder"); | ||
/* FILE */ | ||
@@ -12,7 +14,10 @@ const File = { | ||
write(filePath, content) { | ||
const writeFileAtomic = require('write-file-atomic'); // Lazy import for performance | ||
return util.promisify(writeFileAtomic)(filePath, content); | ||
const writeFileAtomic = util.promisify(require('write-file-atomic')); // Lazy import for performance | ||
const folderPath = path.dirname(filePath); | ||
return folder_1.default.ensure(folderPath).then(() => writeFileAtomic(filePath, content)); | ||
}, | ||
writeSync(filePath, content) { | ||
const writeFileAtomic = require('write-file-atomic'); // Lazy import for performance | ||
const folderPath = path.dirname(filePath); | ||
folder_1.default.ensureSync(folderPath); | ||
return writeFileAtomic.sync(filePath, content); | ||
@@ -19,0 +24,0 @@ }, |
{ | ||
"name": "configuration", | ||
"description": "Performant and feature rich library for managing configurations/settings.", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"main": "dist/index.js", | ||
@@ -46,3 +46,3 @@ "types": "dist/index.d.ts", | ||
"engines": { | ||
"node": ">= 10" | ||
"node": ">= 10.11" | ||
}, | ||
@@ -49,0 +49,0 @@ "dependencies": { |
@@ -14,3 +14,3 @@ | ||
id: string; | ||
storage: Storage; | ||
storage?: Storage; | ||
@@ -26,2 +26,4 @@ constructor ( options: Partial<Options> ) { | ||
this.init (); | ||
} | ||
@@ -31,2 +33,4 @@ | ||
if ( !this.storage ) return super.readSync (); | ||
const dataRaw = this.storage.getItem ( this.id ) || DEFAULTS.dataRaw, | ||
@@ -41,2 +45,4 @@ data = Serializer.deserialize ( dataRaw ); | ||
if ( !this.storage ) return super.writeSync ( data, force ); | ||
if ( !force && this.isEqual ( data ) ) return; | ||
@@ -43,0 +49,0 @@ |
@@ -6,3 +6,5 @@ | ||
import * as fs from 'graceful-fs'; | ||
import * as path from 'path'; | ||
import * as util from 'util'; | ||
import Folder from './folder'; | ||
@@ -15,7 +17,10 @@ /* FILE */ | ||
write ( filePath: string, content: string ): Promise<void> { | ||
const writeFileAtomic = require ( 'write-file-atomic' ); // Lazy import for performance | ||
return util.promisify ( writeFileAtomic )( filePath, content ); | ||
const writeFileAtomic = util.promisify ( require ( 'write-file-atomic' ) ); // Lazy import for performance | ||
const folderPath = path.dirname ( filePath ); | ||
return Folder.ensure ( folderPath ).then ( () => writeFileAtomic ( filePath, content ) ); | ||
}, | ||
writeSync ( filePath: string, content: string ): void { | ||
const writeFileAtomic = require ( 'write-file-atomic' ); // Lazy import for performance | ||
const folderPath = path.dirname ( filePath ); | ||
Folder.ensureSync ( folderPath ); | ||
return writeFileAtomic.sync ( filePath, content ); | ||
@@ -22,0 +27,0 @@ }, |
@@ -832,3 +832,3 @@ | ||
it.only ( 'works', t => { | ||
it ( 'works', t => { | ||
@@ -835,0 +835,0 @@ const foo = new ProviderJSON ({ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
93930
56
2540