npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

priv-js

v1.1.0

Published

Storage of blocks functions that generats BEMJSON

Downloads

19

Readme

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