# unquoted-property-validator

> Unquoted JavaScript property name validator

Latest version **1.1.0** (published 2019-02-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install unquoted-property-validator
pnpm add unquoted-property-validator
yarn add unquoted-property-validator
bun add unquoted-property-validator
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2019-02-13 |
| First published | 2014-08-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=6.0.0 |
| Dependencies | 0 |
| Unpacked size | 13.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Gilad Peleg |
| Maintainers | pgilad |
| Keywords | string, literal, mathias, brackets, dot notation, validation, code-style |

## Links

- npm: https://www.npmjs.com/package/unquoted-property-validator
- Repository: https://github.com/pgilad/unquoted-property-validator
- Homepage: https://github.com/pgilad/unquoted-property-validator#readme
- Issues: https://github.com/pgilad/unquoted-property-validator/issues
- npm.io page: https://npm.io/package/unquoted-property-validator

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2019-02-13
- 1.0.2 — 2017-10-26
- 1.0.1 — 2017-10-25
- 1.0.0 — 2014-10-27
- 0.1.2 — 2014-08-30

## README

# unquoted-property-validator
> Unquoted JavaScript property name validator

[![NPM Version](http://img.shields.io/npm/v/unquoted-property-validator.svg?style=flat)](https://npmjs.org/package/unquoted-property-validator)
[![NPM Downloads](http://img.shields.io/npm/dm/unquoted-property-validator.svg?style=flat)](https://npmjs.org/package/unquoted-property-validator)
[![Build Status](http://img.shields.io/travis/pgilad/unquoted-property-validator.svg?style=flat)](https://travis-ci.org/pgilad/unquoted-property-validator)

This module checks if a given property name can be used without quotes and/or with dot notation.

It is based on Mathias Bynens brilliant [javascript-properties article](https://mathiasbynens.be/notes/javascript-properties).
So this is a **node-port** of his [website implementation](https://github.com/mathiasbynens/mothereff.in/tree/master/js-properties).

## Installation

```bash
$ npm install unquoted-property-validator --save
```

## Usage

```js
var unquotedValidator = require('unquoted-property-validator');

var results = unquotedValidator('myCoolLiteral');
console.log(results);
/* {
    needsQuotes: false,
    needsBrackets: false,
    es3Warning: false,
    quotedValue: 'myCoolLiteral'
   }
*/
```

In ES6/Typescript the first line should look like this instead:

```js
import unquotedValidator = require('unquoted-property-validator');
```

## Results

Your property input will be checked and you will get 3 flags as output:

### needsQuotes

Quotes can only be omitted if the property name is a numeric literal or a valid identifier name:

```js
var obj = {
        nonQuoted: true,
        'must-be-quoted' : true
    };
```

### needsBrackets

Dot notation can only be used when the property name is a valid identifier name:

```js
obj.bracketFree = true; //use the supreme dot notation
obj['requires-brackets'] = true; //string must be inside brackets to be used as property
```

### es3Warning

Should you want to support ES3, you cannot use some identifiers:
```js
obj['var'] //-> invalid in ES3
var obj = {
        goto: true //-> invalid in ES3
    };
```

### quotedValue

Your quoted string in case there are problematic characters.

## API

`unquotedValidator(input)`

### input

Type: `String`

Property to validate

## License

MIT © [Gilad Peleg](https://www.giladpeleg.com)

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