Socket
Socket
Sign inDemoInstall

smart-fs

Package Overview
Dependencies
Maintainers
1
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

smart-fs

Abstraction Layer for File Management.


Version published
Weekly downloads
1.5K
increased by108.87%
Maintainers
1
Weekly downloads
 
Created
Source

smart-fs

Build Status Test Coverage Dependabot Status Dependencies NPM Downloads Semantic-Release Gardener

Abstraction Layer for File Management.

Getting Started

$ npm install --save smart-fs

Functions

To ignore file extension and force treat the file as a certain type, you can pass the option treatAs as e.g. json.

smartRead(filepath, options = { treatAs = null })

Read and parse file based on file extension.

The following extensions are handled in order:

  • .json: Loads file using JSON.parse.
  • .yml and .yaml: Loads file using yaml-boost.
  • .js: Loads file using require, but invalidating the cache before doing so.
  • .*: Treats file as text file and loads as array of lines.

smartWrite(filepath. content, options = { treatAs = null, mergeStrategy = (existing, changeset) => changeset })

Serialize and write content to file based on file extension.

The file and all necessary folders are created if not present.

The file is only actually written if the content has changed. Returns true if the file was written, false otherwise.

The following extension are handled in order:

  • .json: Serialize uses JSON.stringify.
  • .yml and .yaml: Serialize uses yaml-boost.
  • .*: Expects content as array and serializes by joining array using new line character.

The mergeStrategy option can be used to customize how the new content is merged if the target file already exists. By default the file is simply overwritten.

Important

Do not use this library for loading if you don't trust the source of the files you are loading!

Keywords

FAQs

Package last updated on 11 Mar 2019

Did you know?

Socket

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.

Install

Related posts

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