# bauer-factory

> General utilities for nodejs.

Latest version **2.0.6** (published 2016-01-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install bauer-factory
pnpm add bauer-factory
yarn add bauer-factory
bun add bauer-factory
```

## 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 | 2.0.6 |
| Published | 2016-01-16 |
| First published | 2014-06-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Yuri Neves Silveira |
| Maintainers | yneves |
| Keywords | class, method, type, signature, overload, function, object, create |

## Links

- npm: https://www.npmjs.com/package/bauer-factory
- Repository: https://github.com/yneves/node-bauer-factory
- Issues: https://github.com/yneves/node-bauer-factory/issues
- npm.io page: https://npm.io/package/bauer-factory

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 2.0.6 (latest) — 2016-01-16
- 2.0.5 — 2015-11-26
- 2.0.4 — 2015-07-25
- 2.0.3 — 2015-06-11
- 2.0.2 — 2015-06-11
- 2.0.1 — 2015-06-11
- 2.0.0 — 2015-06-09
- 1.2.8 — 2015-01-24
- 1.2.7 — 2015-01-24
- 1.2.6 — 2015-01-24
- 1.2.5 — 2015-01-24
- 1.2.4 — 2015-01-24
- 1.2.3 — 2015-01-21
- 1.2.2 — 2015-01-21
- 1.2.1 — 2015-01-17
- … 15 more at https://npm.io/package/bauer-factory/versions

## README

node-bauer-factory
========================

General utilities for nodejs.

## Installation

```
npm install bauer-factory
```

## Usage

```js
var factory = require("bauer-factory");
```

## .type

Returned value can be string, number, boolean, date, regexp, error, array, object, arguments, null, undefined or function.


```js
// returns type of given argument
var type = factory.type(arg);
```

## .isNull

```js
factory.isNull(arg)
// same as
factory.type(arg) === "null"
```

## .isDefined

```js
factory.isDefined(arg)
// same as
factory.type(arg) !== "undefined"
```

## .isUndefined

```js
factory.isUndefined(arg)
// same as
factory.type(arg) === "undefined"
```

## .isDate

```js
factory.isDate(arg)
// same as
factory.type(arg) === "date"
```

## .isError

```js
factory.isError(arg)
// same as
factory.type(arg) === "error"
```

## .isBoolean

```js
factory.isBoolean(arg)
// same as
factory.type(arg) === "boolean"
```

## .isArray

```js
factory.isArray(arg)
// same as
factory.type(arg) === "array"
```

## .isNumber

```js
factory.isNumber(arg)
// same as
factory.type(arg) === "number"
```

## .isString

```js
factory.isString(arg)
// same as
factory.type(arg) === "string"
```

## .isObject

```js
factory.isObject(arg)
// same as
factory.type(arg) === "object"
```

## .isRegExp

```js
factory.isRegExp(arg)
// same as
factory.type(arg) === "regexp"
```

## .isFunction

```js
factory.isFunction(arg)
// same as
factory.type(arg) === "function"
```

## .isArguments

```js
factory.isArguments(arg)
// same as
factory.type(arg) === "arguments"
```

## .createMethod

Accepts an object containing types/lengths as keys and values as functions.

```js
var func = factory.createMethod({
	0: function() {}, // executed if called with zero arguments
	s: function(s) {}, // executed if called with one string
	sf: function(s) {}, // executed if called with a string and a function
	_: function() {}, // executed if none of the above is matched
});
```

Letters are taken as the first character of the argument's type as returned by `factory.type`. Any combination can be used to route the function execution. This takes priority over argument's length routing.

```js
var func = factory.createMethod({
	o: function() {}, // executed if called with object
	a: function(s) {}, // executed if called with array or arguments
	sffb: function(s,f0,f1,b) {}, // executed if called with a string, two functions and a boolean
});
```

Numbers are taken as the length of the arguments object. Nested rules are supported.

```js
var func = factory.createMethod({
	5: { // executed if called with five arguments
		sssss: function() {}, // five strings
		assss: function() {}, // one array and four strings
	},
	1: function(arg) {}, // executed if called with one argument
});
```

Underscore holds the default code. If no rule is matched and there's no `_` throws an `ReferenceError`.

```js
var func = factory.createMethod({
	_: function() {},
});
```

Strings can be used as code. They are converted to functions internally with the defined arguments.

```js
var func = factory.createMethod({
	s: "return this.get(s)", // the given string can be refered as 's'
	ss: "return this.both(s0,s1)", // if it's two strings, just add the index
	f: "this.on('ready',f)", // easy to define aliases
});
```

If the code does not use any external vars its possible to optimize the generated function by passing a second argument as `true`.

```js
var optimized = factory.createMethod({
	s: "return this.get(s)",
	ss: "return this.both(s0,s1)",
	f: "this.on('ready',f)",
},true); // tell factory.method that this function does not use any external var
```

## .createClass

Creates a class with given methods, constructor and inheritance.

```js
var Bauer = factory.createClass({

	// requires 'events' and inherits EventEmitter from it
	// also accepts functions
	inherits: require("events").EventEmitter,

	// called when new Bauer() is executed
	// it can also be routed by factory.method if needed
	constructor: function() {
	},

	// methods are created by factory.method
	killTerrorists: {
	},

	tortureSuspects: {
	},

	doWhateverIsNecessary: function() {},

});
```

The created class can be instantiated and inherited just like any other class.

```js
var jack = new Bauer();

jack.killTerrorists();

jack.tortureSuspects();

jack.doWhateverIsNecessary();
```

## .createObject

Creates a class just like .class does and returns an instance of it.

```js
// accepts same arguments as .createClass
var jack = factory.createObject({

	// requires 'events' and inherits EventEmitter from it
	// also accepts functions
	inherits: require("events").EventEmitter,

	// called when new Bauer() is executed
	// it can also be routed by factory.method if needed
	constructor: function() {
	},

	// methods are created by factory.method
	killTerrorists: {
		s: function() {},
		n: function() {},
	},

	tortureSuspects: {
		1: function() {},
		2: function() {},
	},

	doWhateverIsNecessary: function() {},

});
```

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