open-index/open-npm huggingface dataset:
npm package: @hackbg/file
Description: File utilities.
Latest version: 3.0.0-rc.5

# @hackbg/file

**Filesystem utilities.**

Your OS's filesystem isn't the most powerful database,
it's one of the more familiar and human-friendly ones out there.

This package exports:

* The `$` helper function, which concatenates paths.
* The `File` and `Directory` classes, which you can use to
  specify whether you expect a file or a directory at a given path.
* The `JSONFile`, `YAMLFile` etc. subclasses for automatically
  loading data in a given format.
* Reexports `fs`, `fs/promises`, as well as `mkdirp` and `rimraf`.

```javascript
import $, { Directory, TextFile, JSONFile } from '@hackbg/file'

const root = $(process.cwd())

// Access files through a directory
const dir = root.in('data').as(Directory).make()
dir.at('file.txt').as(TextFile).save('my data')
dir.at('file.json').as(JSONFile).save({my:'data'})
console.log(dir.list())

// Or directly
console.log(new JSONFile(root, 'data', 'file.json').load())
console.log(root.in('data').at('file.txt').as(TextFile).load())
```

<div align="center">

---

Made with **#%&!** @ [**Hack.bg**](https://foss.hack.bg)

</div>
npm package: @hackbg/kabinet
Description: File utilities.
Latest version: 3.2.7
Deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

---
literate: typescript
---
# `@hackbg/kabinet`

**Classes for accessing the filesystem.**

Your OS's filesystem isn't the most powerful database by far,
it's the most human-friendly one out there.

Exports `File` and `Directory` classes, as well as example `JSON` subclasses of the same
that take care of extensions and the data format. `YAML` and `TOML` subclasses are planned,
too.

Reexports `fs`, `fs/promises`, as well as `mkdirp` and `rimraf`.

Basis of the Receipts subsystem in Fadroma. A "receipt" is a good metaphor
for the kind of data best stored with this module: a record of a meaningful
interaction between a user and a system, which is stored *with the user*
(as it's recorded by the system's state, anyway). Think keeping track of
what programs (e.g. smart contracts) you uploaded to an append-only public
compute service (e.g. a programmable blockchain).

```javascript
import $, { OpaqueDirectory, TextFile, JSONFile } from '@hackbg/kabinet'

const root = $(process.cwd())

// Access files through a directory
const dir = root.in('data').as(OpaqueDirectory).make()
dir.at('file.txt').as(TextFile).save('my data')
dir.at('file.json').as(JSONFile).save({my:'data'})
console.log(dir.list())

// Or directly
console.log(new JSONFile(root, 'data', 'file.json').load())
console.log(root.in('data').at('file.txt').as(TextFile).load())
```
npm package: @hackbg/konfizi
Description: Command runner.
Latest version: 3.0.1
Deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

# Konfizi

Loads configuration from environment.

Parses the values of "empty string", `false`, `no`, and `0` as negatives.

Example usage with TypeScript:

```typescript
import * as Konfizi from '@hackbg/konfizi'

export class MyConfig extends Konfizi.EnvConfig {

  /** This constructor must be copied into every subclass to support the passing of defaults.
    * This is dumb, TODO fix in next version. */
  constructor (
    env:      Konfizi.Env       = {},
    cwd:      string            = '',
    defaults: Partial<MyConfig> = {}
  ) {
    super(env, cwd)
    this.override(defaults)
  }

  /* If you provide no default, when the env var is not defined and error will be thrown */
  myStringField
    = this.getString('MY_STRING_FIELD')

  /* To provide a default value pass a function that returns the default */
  myNumberField
    = this.getNumber('MY_NUMBER_FIELD', () => 0)

  /* To provide a default value pass a function that returns the default */
  myBooleanField
    = this.getBoolean('MY_BOOLEAN_FIELD', () =>
      this.getBoolean('MY_FLAG',          () =>
      this.getBoolean('MY_OTHER_FLAG',    () => {
        if (Math.random() > 0.5) {
          return true
        } else {
          return false
        }
      })))

}

const currentConfig = new MyConfig(process.env, process.cwd, /* {}: defaults */)
```