Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
mark-js
Advanced tools
Readme
Mark Notation or simply Mark, is a new unified notation for both object and markup data. The notation is a superset of what can be represented by JSON, HTML and XML, but overcomes many limitations of these popular data formats, yet still having a very clean syntax and simple data model.
Mark | JSON | HTML | XML | S-expr | YAML | |
---|---|---|---|---|---|---|
Clean syntax | yes | yes | no | verbose | yes | yes (only for basic usage) |
Fully-typed | yes | yes | no | no (when no schema) | yes | yes |
Generic | yes | yes | no | yes | yes | yes |
Mixed content support | yes | hard | yes | yes | hard (poor map support) | hard |
High-order composition | yes | possible | no | verbose | yes | possible |
Wide adoption | not (at the moment) | yes | yes | yes | limited | limited |
The major syntax extension Mark makes to JSON is the introduction of a Mark object. It is a JSON object extended with a type name and a list of content items, similar to element in HTML and XML.
For example, a HTML registration form:
<form>
<!--comment-->
<div class="form-group">
<label for="email">Email address:</label>
<input type="email" id="email">
</div>
<div class="form-group">
<label for="pwd">Password</label>
<input type="password" id="pwd">
</div>
<button class='btn btn-info'>Submit</button>
</form>
Could be represented in Mark as:
{form // object with type-name 'form'
(?comment?) // Mark pragma, like HTML comment
{div class:"form-group" // nested Mark object
{label for:email // property 'for' and its value, both unquoted
"Email address:" // text needs to be quoted
}
{input type:email id:email} // object without any contents
}
{div class:form-group
{label for:pwd "Password"}
{input type:password id:pwd} // comma is optional
}
{button class:['btn' btn-info] // property with complex values
'Submit' // text quoted with single quote
}
}
You can refer to the syntax spec for details.
Mark has a very simple and fully-typed data model.
Each Mark object has 3 facets of data:
object.constructor.name
under JavaScript.Mark utilizes a novel feature in JavaScript that a plain JS object is actually array-like, it can contain both named properties and indexed properties.
So each Mark object is mapped to just one plain JavaScript object, which is more compact and efficient comparing to other JSON-based DOM models (e.g. JsonML, virtual-dom, MicroXML), and is more intuitive to used under JS.
Roughly speaking, data models of JSON, XML, HTML are subsets of Mark data model, and Mark data model is a subset of JS data model.
You can refer to the data model spec for details.
Mark is a superset of JSON. It extends JSON notation with a type-name, and a list of content objects.
Comparing to JSON, Mark has the following advantages:
Some disadvantages of Mark, comparing to JSON would be:
Comparing to HTML, Mark has the following advantages:
Comparing to XML, Mark has the following advantages:
S-expression from Lisp gave rise to novel ideas like high-order composition, self-hosting program. The clean and flexible syntax of Mark make it ideal for many such applications (e.g. Mark Template, a new JS template engine using Mark for its template syntax), just like s-expression.
The advantage of Mark over S-expressions is that it takes a more modern, JS-first approach in its design, and can be more readily used in web and node.js environments.
mark.js
is the JS library to work with data in Mark format. It consists of 4 modules:
mark.js
, which provides parse()
and stringify()
functions, like JSON, and a direct Mark object construction function Mark()
, and some functional APIs to work with the object content.mark.mutate.js
, which provides mutative APIs to change the Mark object data model.mark.convert.js
, which provides conversion between Mark format and other formats like HTML and XML.mark.selector.js
, which provides CSS selector based query interface on the Mark object model, like jQuery.Install from NPM:
npm install mark-js --save
Then in your node script, use it as:
const Mark = require('mark-js');
var obj = Mark.parse(`{div {span 'Hello World!'}}`);
console.log("Greeting from Mark: " + Mark.stringify(obj));
To use the library in browser, you can include the mark.js
under /dist
directory into your html page, like:
<script src='mark.js'></script>
<script>
var obj = Mark(`{div {span 'Hello World!'}}`); // using a shorthand
console.log("Greeting from Mark: " + Mark.stringify(obj));
</script>
Note: /dist/mark.js has bundled all sub-modules and all dependencies with it, and is meant to run in browser. The entire script is about 14K after gzip. It supports latest browsers, including Chrome, Safari, Firefox, Edge. (Legacy browser IE is not supported.)
If you just want the core functional API, without the sub-modules, you can also use mark.core.js, which is only 7K after gzip. You can also refer to the package.json to create your own custom bundle with the sub-modules you need.
Thanks to the following platforms or services that support the open source development of Mark: NPM, GitHub, Travis CI, Codecov, BrowserStack, jsDelivr, Plunker, JS.org.
FAQs
The core library for working with Mark, an unified notation for both object and markup data.
The npm package mark-js receives a total of 27 weekly downloads. As such, mark-js popularity was classified as not popular.
We found that mark-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.