New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

unquoted-property-validator

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unquoted-property-validator

Unquoted JavaScript property name validator

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.4K
decreased by-10.99%
Maintainers
1
Weekly downloads
 
Created
Source

unquoted-property-validator

Unquoted JavaScript property name validator

NPM Version NPM Downloads Build Status

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. So this is a node-port of his website implementation.

Installation

$ npm install unquoted-property-validator --save

Usage

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:

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:

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

needsBrackets

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

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:

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

Keywords

FAQs

Package last updated on 13 Feb 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc