priv-js

1.1.0 • Public • Published

priv-js NPM version Build Status Coverage Status

Helper library, that contains functions and methods which will help you form final BEMJSON object in *.priv.js files.

Install

npm install priv-js

Usage

var Blocks = require('priv-js');
var blocks = new Blocks;

All *.priv.js files exports function:

// button.priv.js
module.exports = function(blocks) {
    // ...
};

This function expects to get instance of priv-js object in first argument:

var privFile = require('button.priv.js');
privFile(blocks);

API

Blocks()

Constructor. Returns Blocks instance, that have next methods:

blocks.declare(name, object)

Declares object by name.

blocks.declare('header', function(data) {
    return {
        block: 'header',
        content: data.name
    }
});
 
blocks.declare('utils', {
    format: fucntion(number) { ... },
    inverse: function(obj) { ... }
});

blocks.has(name)

Checks whether block is declared or not.

blocks.declare('layout-vertical', function () {
    return {
        block: 'layout-vertical'
    };
});
blocks.declare('layout', function () {
    if (blocks.has('layout-vertical')) {
        return blocks.exec('layout-vertical');
    }
 
    return {
        block: 'layout'
    };
});

blocks.get(name)

Get declared object by name.

blocks.declare('price', function(data) {
    var utils = blocks.get('utils');
    return {
        block: 'price',
        content: utils.format(data.price) + 'руб.'
    }
});

blocks.exec(name, args...)

Executes stored function with args. If type of stored object is not a function, exception will be thrown. Returns result of execution.

blocks.declare('item', function(data) {
    return [
        { block: 'image' },
        blocks.exec('price');
        blocks.exec('debug', data.debug);
    ]
});

Changelog

Changelog can be viewed on a separate page.

Contribution

Please, read contribution guide before creating issues or submitting pull request.

Tests

$ npm test

Readme

Keywords

none

Package Sidebar

Install

npm i priv-js

Weekly Downloads

4

Version

1.1.0

License

none

Last publish

Collaborators

  • maxvipon