Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support UTF-16 Identifiers #323

Merged
merged 5 commits into from
Feb 15, 2023
Merged

Support UTF-16 Identifiers #323

merged 5 commits into from
Feb 15, 2023

Conversation

sinclairzx81
Copy link
Owner

This PR implements an update to support UTF-16 (unicode) schema identifiers, as well as refactoring similar logic for unicode object properties keys. In the case of schema identifiers, because schemas with identifiers are hoisted into their own functions (with the identifier used as the function name), this update encodes any non-alphanumeric character into it's unicode equivalent number as given by '...'.charCodeAt(index).

This update permits identifier URI's of the following form.

const Vector = Type.Object(
  {
    x: Type.Number(),
    y: Type.Number(),
    z: Type.Number(),
  },
  {
    $id: 'http://domain.com/schemas/Vector',
  },
)

const C = TypeCompiler.Compile(Vector)

console.log(C.Code())

// function check_http_58_47_47_domain_46_com_47_schemas_47_Vector(value) {
//   return (
//     (typeof value === 'object' && value !== null && !Array.isArray(value)) &&
//     (typeof value.x === 'number' && !isNaN(value.x)) &&
//     (typeof value.y === 'number' && !isNaN(value.y)) &&
//     (typeof value.z === 'number' && !isNaN(value.z))
//  )
// }
// return function check(value) {
//   return (
//     (check_http_58_47_47_domain_46_com_47_schemas_47_Vector(value))
//  )
// }

// ... with the identifier decodable with the following.
console.log(String.fromCharCode(58)) // :
console.log(String.fromCharCode(47)) // /
console.log(String.fromCharCode(47)) // /
console.log(String.fromCharCode(46)) // .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant