Meet npm Pro: unlimited public & private packages + package-based permissions.Learn more »

@mangar2/persist

1.0.4 • Public • Published

Table of Contents

Meta

  • copyright: Copyright (c) 2020 Volker Böhm

  • author: Volker Böhm

  • license: This software is licensed under the GNU LESSER GENERAL PUBLIC LICENSE Version 3. It is furnished "as is", without any support, and with no warranty, express or implied, as to its usefulness for any purpose.

Persist

Creates a new persistance support class

Parameters

  • configuration Object configuration options (optional, default {})
    • configuration.keepFiles number amount of file versions to keep (including the recently written file)

Examples

const persist = new Persist( { keepFiles: 5 })
persist.saveObjectToFile('.', 'helloworld.json', { message: 'hello world' } )
const dataRead = persist.readData('.', 'helloworld.json')
// prints 'hello world'
console.log(dataRead.message)

saveObjectToFile

Stringifies a JSON and writes it to a file. It will automatically add a timestamp to the provided "base" filename It does not throws errors, but logs write errors to the console

Parameters

  • directory string directory to delete file
  • filenameBasis string basis filename of the file. The
  • objectToSave Object object to save as JSON

Returns any undefined

readData

Reads data from a file

Parameters

  • directory string directory to delete file
  • filenameBasis string basis filename of the file. The

Returns Object the object read.

Keywords

Install

npm i @mangar2/persist

DownloadsWeekly Downloads

53

Version

1.0.4

License

LGPL-3.0-or-later

Unpacked Size

13 kB

Total Files

4

Last publish

Collaborators

  • avatar