New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

bemhtml-syntax

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bemhtml-syntax - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

2

package.json
{
"name": "bemhtml-syntax",
"version": "0.0.1",
"version": "0.0.2",
"description": "BEMHTML syntax converter",

@@ -5,0 +5,0 @@ "main": "lib/syntax.js",

@@ -0,34 +1,57 @@

Convert BEMHTML in old-syntax into new JS-style syntax.
####Install
`git clone https://github.com/vkz/bemhtml-syntax.git`
`cd bemhtml-syntax`
`npm install`
`npm -g install bemhtml-syntax`
`npm test` will run tests.
**TODO** final indentation should obviously be in bem-style not generic produced by Esprima+Escodegen combo.
####Use
```shell
bemhtml-syntax [OPTIONS] [ARGS]
```
kozin@:~/Documents/bemhtml-syntax$ bin/bemhtml-syntax -h
For example, convert
```js
// cat test/basic/info6.bemhtml
// ----------------------------
block b-wrapper {
tag: 'wrap'
content: this.ctx.content
}
Usage:
bemhtml-syntax [OPTIONS] [ARGS]
block b-inner, default: applyCtx({ block: 'b-wrapper', content: this.ctx.content })
```
into
```js
// bemhtml-syntax -q "double" -Q -i test/basic/info6.bemhtml
// ---------------------------------------------------------
block("b-wrapper")(
tag()("wrap"),
content()(function() {
return this.ctx.content
})
);
Options:
-h, --help : Help
-o OUTPUT, --output=OUTPUT : Output to file (default: stdout)
-i INPUT, --input=INPUT : File to convert (default: stdin)
block("b-inner").def()(function() {
return applyCtx({
"block": "b-wrapper",
"content": this.ctx.content
})
})
```
Accepts a handful of options to control code-formatting. Of note:
```shell
-q QUOTES, --quotes=QUOTES : Prefer "single" or "double" quotes (default: "single")
-Q, --quote-keys : Quote object keys (default: false)
-s INDENT_SIZE, --indent-size=INDENT_SIZE : (default: 4)
-p, --dont-preserve-newlines : (default: false)
```
Most options used by [js-beautify][] should just work.
####API
```javascript
var syntax = require("bemhtml-syntax");
var syntax = require('bemhtml-syntax'),
source = 'block b1, tag: "a"',
options = { indent_size: 2 };
var source = 'block b1, tag: "a"';
// Parse BEMHTML code

@@ -41,10 +64,8 @@ var ast = syntax.parse(source);

// Serialise to JavaScript
var jsCode1 = syntax.generate(newAst);
var jsCode1 = syntax.generate(newAst, options);
/* Returns:
* block('b1').tag()('a');
*/
// Or do everything in one go
var jsCode2 = syntax.compile(source);
var jsCode2 = syntax.compile(source, options);
```
[js-beautify]: https://github.com/beautify-web/js-beautify

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc