# config-file-helper

> Config File That Helper, Take default object, Save it to the wanted file, and let you Change the file programmatically.

Latest version **0.1.1** (published 2020-06-11) · ISC license · 0 weekly downloads

## Install

```sh
npm install config-file-helper
pnpm add config-file-helper
yarn add config-file-helper
bun add config-file-helper
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2020-06-11 |
| First published | 2020-06-11 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 100.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Yotam Hassin |
| Maintainers | yotamhassin |
| Keywords | Helper, Node, Node.JS, NPM, files, config, config file, fs, file system |

## Links

- npm: https://www.npmjs.com/package/config-file-helper
- Repository: https://github.com/YotamHassin/config-file-helper
- Homepage: https://github.com/YotamHassin/config-file-helper#readme
- Issues: https://github.com/YotamHassin/config-file-helper/issues
- Funding: https://www.patreon.com/YotamHassin
- npm.io page: https://npm.io/package/config-file-helper

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 0.1.1 (latest) — 2020-06-11
- 0.1.0 — 2020-06-11
- 0.0.7 — 2020-06-11
- 0.0.6 — 2020-06-11
- 0.0.5 — 2020-06-11
- 0.0.4 — 2020-06-11
- 0.0.3 — 2020-06-11
- 0.0.2 — 2020-06-11
- 0.0.1 — 2020-06-11

## README

# config-file-helper
Config File That Helper, **Take** default object, **Save** it to the wanted file, and let you **Change** the file programmatically.

- [Installation](#installation)

- [Usage](#usage)
	- [TypeScript](#typescript)
		- [TS Flat Object](#ts-flat-object)
		- [TS Complex Object](#ts-complex-object)
	- [JavaScript](#javascript)
		- [JS Flat Object](#js-flat-object)
		- [JS Complex Object](#js-complex-object)

- [Join Me](#join-me-on-the-quest-to-make-computer-software-and-development-simple)


### [npmjs/config-file-helper](https://www.npmjs.com/package/config-file-helper)

### [github/YotamHassin/config-file-helper](https://github.com/YotamHassin/config-file-helper)


## Installation
```sh
cd <my_location>
npm install config-file-helper --save
```

## Usage


### TypeScript
### TS Flat Object
```typescript
import * as configHelper from 'config-file-helper';

// No complex object
interface ConfigType {
	name: string;
	val: number;
}

// Not to be changed, saved as default and backup for file.
const _configObject: ConfigType = {
	name: "some name",
	val: 5,
};

// flat object, No complex nested objects.
const configFileObject: ConfigType = configHelper.initConfigObject<ConfigType>('configObject.js', _configObject);

console.log('print configFileObject.name: ', configFileObject.name);

console.log('print configFileObject.val: ', configFileObject.val);
configFileObject.val+=5;
console.log('after update print configFileObject.val: ', configFileObject.val);

```

### TS Complex Object
```typescript
/* --- complex object example --- */
import * as configHelper from 'config-file-helper';

// defaultObject to init if file damages/not exist
interface ConfigTypeComplex {
	name: string;
	arr: Array<{innerName: string, val: number}>
}

const defaultObjectComplex: ConfigTypeComplex = {
    name: 'some name', 
    arr: [{innerName: 'some inner name', val: 3}]
};

const fileObjectHandler = configHelper.
    FileObjectHandler._('configFileObject.js', defaultObjectComplex);

function print() {
    var val: number = fileObjectHandler.get().arr[0].val;
    console.log('val: ', val);
}

function update() {
    fileObjectHandler.set((obj: ConfigTypeComplex) => {
        obj.arr[0].val += 3;
    });
}

print();
update();
print();
```


### JavaScript
### JS Flat Object
```javascript
/* --- flat object example, Not for complex\nested objects --- */
const configHelper = require('config-file-helper');

const configFileObject = configHelper.initConfigObject('./configFileObject.js', { name: 'some name', val: 5 });

console.log('print configFileObject.name: ', configFileObject.name);

console.log('print configFileObject.val: ', configFileObject.val);
configFileObject.val+=5;
console.log('after update print configFileObject.val: ', configFileObject.val);

```

### JS Complex Object
```javascript
/* --- complex object example --- */
const configHelper = require('config-file-helper');

// defaultObject to init if file damages/not exist
const defaultObject = {
    name: 'some name', 
    arr: [{innerName: 'some inner name', val: 3}]
};

const fileObjectHandler = configHelper.
    FileObjectHandler._('configFileObject.js', defaultObject);

function print() {
    var val = fileObjectHandler.get().arr[0].val;
    console.log('val: ', val);
}

function update() {
    fileObjectHandler.set((obj) => {
        obj.arr[0].val += 3;
    });
}

print();
update();
print();

```

## Join me on the quest to make Computer, Software and Development Simple.

## [Patreon/YotamHassin](https://www.patreon.com/YotamHassin)

---
_Source: https://npm.io/package/config-file-helper · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
