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

@technician/fs-config-source

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@technician/fs-config-source

Access config on your local filesystem with Technician.

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

@technician/fs-config-source

npm version npm downloads npm license

dependencies Build Status GitKraken

A config source for accessing config stored on the filesystem.

The FSConfigSource accesses the contents of an entire directory, allowing access to several config files stored in the same location. It useable as both an async and sync config source.

This package provides the FSConfigSource for use with the Technician manager.

Technician

Installation

npm i @technician/fs-config-source

This package is compatible with Node 10 LTS and up.

Usage Examples

The Basics

import {Technician, DefaultInterpreters} from 'technician';
import {FSConfigSource} from '@technician/fs-config-source'

const technician = new Technician(DefaultInterpreters.asText('utf8'));
technician.addSource(new FSConfigSource());

// By default, FSConfigSource reads from process.cwd();
await technician.read('.myapprc');
await technician.read('something-else.json');

Working With JSON

import {Technician, DefaultInterpreters} from 'technician';
import {FSConfigSource} from '@technician/fs-config-source'

const technician = new Technician(DefaultInterpreters.asJSON('utf8'));
technician.addSource(new FSConfigSource());

const config = await technician.read('config.json');

// The default asJSON interpreter can read and return JSON files as a js object.
// Non-JSON will be ignored with `asJSON`.
// You can use `asTextOrJSON` to optionally parse only valid JSON.
db.connect(config.dbUsername, config.dbPassword);

Specifying Directories

// ...

// Provide an absolute path to a directory.
technician.addSource(new FSConfigSource('/home/me/my-config-dir'));

// The relativeRootPath option will look inside process.cwd() for your custom path.
technician.addSource(new FSConfigSource('app-config-dir', {relativeRootPath: true}));

// ...

Recursive Reading

// ...

// Allows recursive access to subdirectories.
technician.addSource(new FSConfigSource(), {recurse: true});

// Read a file at the top level...
await technician.read('top-level-file.txt');
// ... or within nested subdirectories
await technician.read('subdirectory/another-file.txt');

// Note that subdirectories are not expanded into objects with readAll(),
// but instead keep the same flat key structure used by read().

// Ex: {"top-level-file.txt": "contents", "subdirectory/another-file.txt": "contents"}

Errors

By default, the FSConfigSource suppresses all filesystem errors (except in the case that the rootPath passed to the constructor is invalid), instead treating any unreadable files as simply nonexistent.

To throw these errors instead, use the {throwErrors: true} option. Note that this will cause readAll() to throw an error if the target directory contains any inaccessible files, even if others are valid.

Contributions

Contributions and pull requests are always welcome. Please be sure your code passes all existing tests and linting.

Pull requests with full code coverage are strongly encouraged.

License

Apache-2.0

Keywords

FAQs

Package last updated on 30 Jan 2021

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