json-schema-to-typescript icon indicating copy to clipboard operation
json-schema-to-typescript copied to clipboard

Allow unicode (Fixes #279)

Open iansw246 opened this issue 2 years ago • 4 comments

Fixes #279 and other issues relating to invalid characters in identifiers. It will cover the functionality of #538

This allows any type name that is valid in ES5 by removing invalid characters. Valid characters were determined according to https://mathiasbynens.be/notes/javascript-identifiers.

It uses lodash.template, regenerate, and unicode-11.0.0 to generate the regex in scripts/generate-identifier-regex.ts

It uses code from this gist https://gist.github.com/mathiasbynens/6334847

There is no given license, so I'm not sure if we can use that.

If we can target ES6 or newer, this code can be significantly simplified with Unicode-aware regex.

iansw246 avatar Jul 18 '23 20:07 iansw246

Would the Unicode-aware regex in the latest commit work? That doesn't require any other packages nor the regex-generation scripts.

iansw246 avatar Aug 30 '23 03:08 iansw246

I tried using identifierfy but faced some issues when toSafeString was called on the output of toSafeString. Also, it removes more than the minimum in some cases. Ultimately, using identifierfy should work with a few changes to calls of toSafeString

iansw246 avatar Aug 30 '23 03:08 iansw246

I tried using identifierfy but faced some issues when toSafeString was called on the output of toSafeString. Also, it removes more than the minimum in some cases. Ultimately, using identifierfy should work with a few changes to calls of toSafeString

Great -- want to try doing this?

bcherny avatar Sep 23 '23 02:09 bcherny

I've gotten Identifierfy to work

I've had to remove several calls to toSafeString() to prevent double conversion. This should be OK since the parser converts standaloneNames with generateName()

iansw246 avatar Oct 25 '23 00:10 iansw246

Closing out stale PRs.

bcherny avatar Jun 11 '24 11:06 bcherny