# glob-build

> Globs for files in a directory, processes them all and builds up a nested object

Latest version **1.1.0** (published 2015-01-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install glob-build
pnpm add glob-build
yarn add glob-build
bun add glob-build
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2015-01-14 |
| First published | 2015-01-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | rangermauve |
| Maintainers | rangermauve |
| Keywords | glob, process, tree, directory |

## Links

- npm: https://www.npmjs.com/package/glob-build
- Repository: https://github.com/RangerMauve/glob-build
- Issues: https://github.com/RangerMauve/glob-build/issues
- npm.io page: https://npm.io/package/glob-build

## Dependencies (5)

- [par](https://npm.io/package/par.md) ^0.3.0
- [glob](https://npm.io/package/glob.md) ^4.3.2
- [dotty](https://npm.io/package/dotty.md) 0.0.2
- [fs-promise](https://npm.io/package/fs-promise.md) ^0.3.1
- [any-promise](https://npm.io/package/any-promise.md) ^0.1.0

## Recent versions

- 1.1.0 (latest) — 2015-01-14
- 1.0.1 — 2015-01-14
- 1.0.0 — 2015-01-10

## README

glob-build
==========

Globs for files in a directory, processes them all and builds up a nested object

`npm install --save glob-build`

Example
-------

Say you have a directory with a bunch of [mustache](https://www.npmjs.com/package/mustache) templates in a complex directory, and you want an easy way to get to them via a JS api.

The directory might look like

```
example/
	foo.html
	bar/baz.html
```

With this library, you can easily turn that into a JS object that looks like

```javascript
{
	foo: render(data),
	bar: {
		baz: render(data)
	}
}
```

With some simple code:

```javascript
var globBuild = require("../").build;
var mustache = require("mustache");

globBuild(__dirname, "html", builder).then(function(templates) {
	console.log("Result:", templates);
	console.log(templates.foo({
		place: "World"
	}));
	console.log(templates.bar.baz({
		place: "World"
	}));
}).catch(function(err) {
	console.log("Error:", err, err.stack);
})

function builder(contents, name) {
	// Name doesn't matter for this
	return function(data) {
		return mustache.render(contents, data);
	}
}
```

API
---

### `build([directory], [extension], [builder])`

Takes in a directory, a file extension to match for, and a function for modifying files before they're saved to a tree.

#### arguments

-	[directory] `String`: The directory to crawl through. Uses present working directory by default.
-	[extension] `String`: What file extensions to traget, `*` by default
-	[builder] `Function(contents,name)` A function for building the value for that file in the tree. `contents` is the contents of that file (assumes `utf8`), `name` is a key path for the file in the tree (`looks.like.this`). By default it just sets the value to the contents.

### returns

-	`Promise`: Resolves to the generated tree from the files and the builder.

> Note: this library uses [any-promise](https://www.npmjs.com/package/any-promise), so make sure to have a compatible promise implementation installed.

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