Skip to content

Commit

Permalink
ObjectSource
Browse files Browse the repository at this point in the history
  • Loading branch information
nulldef committed Jun 16, 2021
1 parent ddf8412 commit dcb8eef
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 5 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
Node.js configuration engine

```js
const { Cofman, FileSource, EnvSource } = require("@umbrellio/cofman")
const { Cofman, FileSource, EnvSourc, ObjectSource } = require("@umbrellio/cofman")

const instance = new Cofman()

instance.use(new FileSource({ path: "/path/to/file.yml" }))
instance.use(new FileSource({ path: "/path/to/file.json" }))
instance.use(new ObjectSource({ custom: "value" }))
instance.use(new EnvSource({ prefix: "APP" }))

const config = instance.parse()
Expand Down Expand Up @@ -89,6 +90,14 @@ interface Parser {
}
```

### ObjectSource

Just your custom object

```js
new ObjectSource(object)
```

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/umbrellio/cofman.
Expand Down
5 changes: 4 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
const Cofman = require("./Cofman")

const FileSource = require("./sources/FileSource")
const EnvSource = require("./sources/EnvSource")
const Cofman = require("./Cofman")
const ObjectSource = require("./sources/ObjectSource")

module.exports = {
Cofman,
FileSource,
EnvSource,
ObjectSource,
}
4 changes: 2 additions & 2 deletions lib/sources/FileSource/YamlParser/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test("parses yaml", () => {

test("returns empty object if nothing to parse", () => {
const parser = new YamlParser()
const result = parser.parse("")

expect(result).toStrictEqual({})
expect(parser.parse("")).toStrictEqual({})
expect(parser.parse(null)).toStrictEqual({})
})
11 changes: 11 additions & 0 deletions lib/sources/ObjectSource/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class ObjectSource {
constructor(object) {
this.object = object
}

parse() {
return this.object
}
}

module.exports = ObjectSource
8 changes: 8 additions & 0 deletions lib/sources/ObjectSource/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const ObjectSource = require("./index")

test("it parses json file", () => {
const source = new ObjectSource({ custom: "value" })
const result = source.parse()

expect(result).toStrictEqual({ custom: "value" })
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@umbrellio/cofman",
"version": "1.0.0",
"version": "1.1.0",
"description": "Node.js configuration engine",
"main": "lib/index.js",
"repository": "git@github.com:umbrellio/cofman.git",
Expand Down

0 comments on commit dcb8eef

Please sign in to comment.