npm install --save safe-identifier
=== 'Foo'=== '_enum'=== 'my_var_hk17pp'=== 'my_var_1d8fi3'=== 'Foo.bar'=== 'Foo["bar\\nbar"]'=== 'foo'=== '"void"'
identifier(key: string, unique: boolean): string
Sanitize a string for use as an identifier name
Replaces invalid character sequences with
_ and may add a
_ prefix if the
standards from ES3 up to ES2018, along with current
unique is true, a 32-bit hash of the
key is appended to the result in
order to help ensure that different inputs produce different outputs.
property(obj: string?, key: string): string
Sanitize a string for use as a property name
By default uses
obj.key notation, falling back to
obj["key"] if the key
contains invalid characters or is an ECMAScript 3rd Edition reserved word
(required for IE8 compatibility). If
obj is empty, returns only the possibly
quoted property key. The correctness of
obj is not checked.