hirosystems / stacks.js

JavaScript libraries for identity, auth, storage and transactions on the Stacks blockchain.
https://stacks.js.org
MIT License
944 stars 307 forks source link

feat: Add `Cl.parse` Clarity value parser #1681

Closed janniks closed 2 weeks ago

janniks commented 2 months ago

This PR was published to npm with the version 6.15.0 e.g. npm install @stacks/common@6.15.0 --save-exact

Examples

Cl.parse(`"my string"`);
Cl.parse('-4');
Cl.parse('u5');
Cl.parse('false');
Cl.parse('{ a: 3 }');
Cl.parse('(list 1 2 3)');
vercel[bot] commented 2 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
stacksjs-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 13, 2024 6:03am
janniks commented 2 months ago

I tried it and found this use case that throws a parse error:

{ a: 0x68656c6c6f21 }

@hugocaillard Good catch, noticed that nested values will be tricky with overlaps. I thought the entire combinator solved this, but that's not used for the nested values.. 🙃 -- updated the order to fix this case, there might be more though..

In this case it was detecting the 0x.. as 0 matches an int, and will continue instead of trying other cl-values.