🎭 🎸 🎀
ANGELMARKUP.JS
Simple data storage with no drama in Javascript.
📚
ABOUT I needed a data format that permits comments for some projects I was working on. Everything else seemed too complicated, so I wrote a compiler and parser for my own data format, called Angel Markup. I iplemented the compiler once in Rust and once in Javascript. This is the Javascript implementation.
🔨
USAGE Use Angelmarkup.js in a Node.js project
To use Angelmarkup.js in a Node.js project, run this command in your project's root directory:
$ npm install --save-dev angelmarkup
Be sure to also add the "type":"module"
flag to your project's manifest, package.json
.
APIs
Angelmarkup.js offers the following functions:
-
toYAML(subject, filler)
: Converts a map into a YAML string and joins each line with "filler". -
toTOML(subject, filler)
: Converts a map into a TOML string and joins each line with "filler". -
toAML(subject, filler)
: Converts a map into an AML string and joins each line with "filler". -
toJSON(subject)
: Converts a map into a JSON string. -
hasIndex(subject, index)
: Checks if the list "subject" has the index "index". -
class Token(name, value)
: A class to represent a token.name
represents the token's name andvalue
represents the parsed string slice corresponding to a regular expression for that type of token. -
patternPool()
: A function that holds the regular expression patterns that represent statements Angelmarkup.js understands. -
lexSrc(source, pool)
: A lexing function to take a string, run my algorithm for lexing, and return a list of tokens. (I deliberately made the arguments customizable for easy re-use.) -
serializeAML
: A function that parses Angel Markup statements and serializes them into a map. -
testAll()
: Tests all of the above.
Angel Markup Syntax
Angel Markup is very simple. It is similar to JSON
and only recognizes one data type. This data type is a string. Here's a small example.
# This is a comment.
# Assigns the "name" field, the value "max".
'name' => 'max'
Example
Here's a small example:
- 1.) Initialize a new Node.js project with the following command in a directory of your choosing:
$ npm init -y
- 2.) Install Angelmarkup.js as a dependency:
$ npm install --save-dev angelmarkup
- 3.) Be sure to add this line to your project's
package.json
:
"type":"module",
- 4.) Create your
index.js
file and put the following code inside it:
// index.js
import * as angelmarkup from 'angelmarkup';
function main(){
// A string of an AML key-value pair.
var amlTestString = "'name' => 'aml'";
// The parsed string as a map.
var serialized = angelmarkup.serializeAML(amlTestString);
// Printing out the resulting map.
console.log(serialized);
}
// Calling the "main" function.
main();
- 5.) Run the project:
$ node .
- 6.) Should print out this:
Map(1) { 'name' => 'aml' }
- 7.) If you're still not sure how to use this, check out the
example
project in theexample
folder.
✒️
CHANGELOG Version 1.0.0
- Initial release.
- Upload to GitHub.
- Upload to NPM.
Version 1.1.0
- Minor fixes.
- Fixed typos.
- Updated documentation.
Version 1.2.0
- Updated documentation.
- Fixed ALL typos.
- VASTLY improved the lexer and parser.
- Fixed the "messy string" bug.
Version 1.3.0
- Updated documentation.
- Added a
toJSON
method. - Updated methods for the other formats.
Version 1.4.0
- Updated documentation.
- Published and uploaded under my new name.
Version 1.5.0
- Fixed typos and dead links.
Version 1.6.0
- Fixed some administrative issues.
- Fixed some formatting issues.
📜
NOTE -
Angelmarkup.js
🎭 🎸 🎀 by Alexander Abraham🖤 a.k.a. "Angel Dollface"🎎 🎀 - Licensed under the MIT license.