# accountdown-parser

> Facilitates account creation and user input validation using accountdown and json-schema

Latest version **0.2.0** (published 2015-06-23) · ISC license · 0 weekly downloads

## Install

```sh
npm install accountdown-parser
pnpm add accountdown-parser
yarn add accountdown-parser
bun add accountdown-parser
```

## 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.2.0 |
| Published | 2015-06-23 |
| First published | 2015-05-25 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 13 |
| Known vulnerabilities | 0 (+4 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 3 |
| Author | lukeswart |
| Maintainers | lukeswart |
| Keywords | account, form, accountdown |

## Links

- npm: https://www.npmjs.com/package/accountdown-parser
- Repository: https://github.com/LukeSwart/accountdown-parser
- Homepage: https://github.com/LukeSwart/accountdown-parser.git
- Issues: https://github.com/LukeSwart/accountdown-parser/issues
- npm.io page: https://npm.io/package/accountdown-parser

## Dependencies (13)

- [qs](https://npm.io/package/qs.md) ^3.1.0
- [body](https://npm.io/package/body.md) ^5.0.0
- [tape](https://npm.io/package/tape.md) ^4.0.0
- [extend](https://npm.io/package/extend.md) ^2.0.1
- [hammock](https://npm.io/package/hammock.md) ^1.0.2
- [levelup](https://npm.io/package/levelup.md) ^1.2.1
- [memdown](https://npm.io/package/memdown.md) ^1.0.0
- [each-async](https://npm.io/package/each-async.md) ^1.1.1
- [accountdown](https://npm.io/package/accountdown.md) ^4.1.0
- [subleveldown](https://npm.io/package/subleveldown.md) ^2.0.0
- [is-my-json-valid](https://npm.io/package/is-my-json-valid.md) ^2.12.0
- [accountdown-basic](https://npm.io/package/accountdown-basic.md) ^1.1.0
- [accountdown-model](https://npm.io/package/accountdown-model.md) ^1.0.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.2.0 (latest) — 2015-06-23
- 0.1.3 — 2015-05-25
- 0.1.2 — 2015-05-25
- 0.1.1 — 2015-05-25
- 0.1.0 — 2015-05-25

## README

# accountdown-parser

Account creation and user input validation for [accountdown](https://github.com/substack/accountdown) using json-schema. Primary usage is on the server.

# example

## create an accountdown-parser instance and define a json-schema

``` js
  var validator = require('is-my-json-valid');
  var validate = validator({
    required: true,
    type: 'object',
    properties: {
      login: {
        required: false,
        type: 'object',
        properties: {
          basic: {
            required: true,
            type: 'object',
            properties: {
              uuid: {
                required: true,
                type: 'string'
              },
              password: {
                required: true,
                type: 'string'
              }
            }
          }

        },
      value: {
        required: true,
        type: 'object',
        properties: {
          key: {
            required: true,
            type: 'string'
          },
          admin: {
            required: false,
            type: 'boolean'
          },
          color: {
            required: false,
            type: 'string'
          },
          username: {
            required: false,
            type: 'string'
          },
          email: {
            required: false,
            type: 'string'
          }
        }
      }

      }
    }
  }, {
    verbose: true
  });
  opts = {
    validate: validate,
    format: function (body) {
      body.value.admin = !!(body.value.admin);
      if (body.value.key && body.login) {
        body.login.basic.uuid = body.value.key;
      }
      return body;
    },
    updateLoginCreds: function (account) {
      return account.hasOwnProperty('login');
    }
```


# methods

## var p = accountdown-parser(accountdown, opts)

Return a parser instance `p` given an accountdown instance `a`.

Set `opts.validate` as an instance of [is-my-json-valid](https://www.npmjs.com/package/is-my-json-valid) to define the schema that will be validated for each user instance.

Set an optional `opts.format` to define how client-side requests should be parsed.

Another optional, but useful, `opts.updateLoginCreds` function defines whether the client's input is updating the login creds, which will require deletion and re-creation of the account when it returns true. Otherwise, only the account's value will be updated.


## p.create(req, res, callback)

`req`, `res`: Parses the `req` and `res` objects using the [body](https://github.com/Raynos/body)'s `body/any` module, along with a [querystring](https://www.npmjs.com/package/qs), and creates an account

Internally, all accounts are created with the key generated from [uuid](https://github.com/shtylman/node-uuid), version 1.

`callback(err, account)` fires with any errors or an `account` containing the account values.

## p.update(req, res, callback)

The same as `p.create` except the function `opts.updateLoginCreds` is checked to determine whether to delete and recreate the accounts (when `opts.updateLoginCreds` exists and returns true), otherwise the new accounts values are `put` into the new account.

# install

With [npm](https://npmjs.org/package/npm) do:

```
npm install accountdown-parser
```

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