A lightweight Python
Run this in a terminal:
npm install parse-repr
or, with Yarn:
yarn add parse-repr
- Import the library into your code:
// with es6+ import import ParseRepr from 'parse-repr'; // or, with require var ParseRepr = require('parse-repr');
- Create an instance of the class, passing the repr in as the only argument:
var foo = new ParseRepr('<MyClass example repr here yay>');
- Access the
ParseReprAPI to get what you need out of it. See the API section.
Argument repr (string): The unparsed repr.
Error: If you don't pass a repr or pass undefined.
Parses the repr. This is automatically called by the constructor and should only be called if you change the repr.
Get the name of the object type (e.g. in
"<User me>", the object type would be "User").
Returns: The name of the object type
Returns: The unparsed repr.
Get the repr parts. In the case your repr looks like
"<User 123456 Billy>",
["123456", "Billy"] will be returned.
In the case your repr looks like
"<User id=123456 firstName=Billy>", this will be
If you want actual key-value pairs for this, see
Returns: The list of elements in the repr.
Gives you an object with the key-value pairs named in the repr.
Returns: An object as described above. Throws
Error: If the repr doesn't use key-value pairs.
The source can be found on GitHub.