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

@bem/sdk.file

v0.3.5

Published

Representation of identifier of a part of BEM entity.

Downloads

65

Readme

BemFile

NPM Status

Representation of BEM Entity realisation on FS.

Install

$ npm install --save @bem/sdk.file

Usage

const BemFile = require('@bem/sdk.file');
const BemCell = require('@bem/sdk.cell');

const file = new BemFile({
    cell: BemCell.create({
        block: 'button',
        elem: 'text',
        mod: { name: 'theme', val: 'simple' },
        tech: 'css',
        layer: 'desktop'
    }),
    level: 'node_modules/bem-components',
    path: 'node_modules/bem-components/desktop.blocks/button/__text/_theme/button__text_theme_simple.css'
});

file.cell;   // ➜ BemCell { entity: BemEntityName { … }, layer: 'desktop', tech: 'css' }
file.level;  // node_modules/bem-components
file.path;   // node_modules/bem-components/desktop.blocks/button/__text/_theme/button__text_theme_simple.css

file.entity; // ➜ BemEntityName { block: 'button', elem: 'text', mod: { name: 'theme', val: 'simple' } }
file.layer;  // desktop
file.tech;   // css

API

constructor(obj)

Parameter | Type | Description --------------|-----------------|------------------------------ obj.cell | BemCell | Representation of cell obj.level | string | Level (base directory) obj.path | string | Path to a file in level's scheme

cell

Returns the cell of the file.

const BemFile = require('@bem/sdk.file');
const BemCell = require('@bem/sdk.cell');

const file = new BemFile({
    cell: BemCell.create({ block: 'button', elem: 'text', tech: 'css' })
});

file.cell; // ➜ BemCell { entity: BemEntityName { block: 'button', elem: 'text' }, tech: 'css' }

level

Returns the path to level of the file.

const BemFile = require('@bem/sdk.file');
const BemCell = require('@bem/sdk.cell');

const file = new BemFile({
    cell: BemCell.create({
        block: 'button',
        elem: 'text',
        layer: 'desktop'
    }),
    level: 'node_modules/bem-components'
});

cell.level; // ➜ 'node_modules/bem-components'

path

Returns the path to the file.

const BemFile = require('@bem/sdk.file');
const BemCell = require('@bem/sdk.cell');

const file = new BemFile({
    cell: BemCell.create({
        block: 'button',
        elem: 'text',
        tech: 'css'
    }),
    level: 'node_modules/bem-components',
    path: 'node_modules/bem-components/desktop.blocks/button/__text/button__text.css'
});

cell.path; // ➜ 'node_modules/bem-components/desktop.blocks/button/__text/button__text.css'

tech

Returns the tech of the file.

const BemFile = require('@bem/sdk.file');
const BemCell = require('@bem/sdk.cell');

const file = new BemFile({
    cell: BemCell.create({
        block: 'button',
        tech: 'css'
    })
});

file.tech; // ➜ 'css'

layer

Returns the layer of the file.

const BemFile = require('@bem/sdk.file');
const BemCell = require('@bem/sdk.cell');

const file = new BemFile({
    cell: BemCell.create({
        block: 'button',
        layer: 'desktop'
    })
});

file.layer; // ➜ desktop

id

Returns the identifier of the file.

Important: should only be used to determine uniqueness of file.

const BemFile = require('@bem/sdk.file');
const BemCell = require('@bem/sdk.cell');

const file = new BemFile({
    cell: BemCell.create({
        block: 'button',
        elem: 'text',
        tech: 'css',
        layer: 'desktop'
    }),
    level: 'node_modules/bem-components',
    path: 'desktop.blocks/button_focused.css'
});

file.id; // ➜ "desktop.blocks/[email protected]"

toString()

Returns a string representing the file.

const BemFile = require('@bem/sdk.file');
const BemCell = require('@bem/sdk.cell');
const file = new BemFile({
    cell: BemCell.create({
        block: 'button',
        mod: 'focused',
        tech: 'css',
        layer: 'desktop'
    }),
    level: 'node_modules/bem-components',
    path: 'desktop.blocks/button_focused.css'
});

file.toString(); // desktop.blocks/[email protected]

valueOf()

Returns an object representing this cell.

const BemFile = require('@bem/sdk.file');
const BemCell = require('@bem/sdk.cell');
const file = new BemFile({
    cell: BemCell.create({
        block: 'button',
        mod: 'focused',
        tech: 'css',
        layer: 'desktop'
    }),
    level: 'node_modules/bem-components',
    path: 'desktop.blocks/button_focused.css'
});

file.valueOf();

// ➜ { cell: {
//        entity: { block: 'button', mod: { name: 'focused', value: true } },
//        tech: 'css',
//        layer: 'desktop'
//      },
//      level: 'node_modules/bem-components',
//      path: 'desktop.blocks/button_focused.css' }

toJSON()

Returns an object for JSON.stringify() purpose.

isEqual(file)

Determines whether specified file is deep equal to file or not.

Parameter | Type | Description ----------|-----------------|----------------------- file | BemFile | The file to compare.

const BemFile = require('@bem/sdk.file');
const buttonFile1 = BemFile.create({ block: 'button', tech: 'css', layer: 'desktop', path: 'desktop/button.css' });
const buttonFile2 = BemFile.create({ block: 'button', tech: 'css', layer: 'desktop', path: 'desktop/button.css' });
const inputFile = BemFile.create({ block: 'input', tech: 'css', layer: 'common', path: 'common/input.css' });

buttonFile1.isEqual(buttonFile2); // true
buttonFile1.isEqual(inputFile); // false

#isBemFile(file)

Determines whether specified cell is instance of BemFile.

Parameter | Type | Description ----------|-----------------|----------------------- file | BemFile | The file to check.

const BemFile = require('@bem/sdk.file');

const file = BemFile.create({
    entity: { block: 'button', elem: 'text' },
    tech: 'css',
    path: 'button__text.css'
});

BemFile.isBemFile(file); // true
BemFile.isBemFile({}); // false

#create(object)

Creates BemFile instance by any object representation.

Helper for sugar-free simplicity.

Parameter | Type | Description -------------|----------|-------------------------- object | object | Representation of entity name.

Passed Object could have fields for BemEntityName and cell itself:

Object field | Type | Description -------------|----------|------------------------------ block | string | The block name of entity. elem | string | The element name of entity. mod | string, object | The modifier of entity. If specified value is string then it will be equivalent to { name: string, val: true }. val | string | The modifier value of entity. Used if mod is a string. mod.name | string | The modifier name of entity. mod.val | * | The modifier value of entity. modName | string | The modifier name of entity. Used if mod.name wasn't specified. modVal | * | The modifier value of entity. Used if neither mod.val nor val were not specified. tech | string | Technology of cell. layer | string | Layer of cell. level | string | Base path to level. path | string | Path to the file on fs.

const BemFile = require('@bem/sdk.file');

BemFile.create({ block: 'my-button', tech: 'css', path: 'my-button.css' });
BemFile.create({ cell: { entity: { block: 'my-button' }, tech: 'css' }, path: 'my-button.css' }); // valueOf() format
// → BemFile { cell: { entity: { block: 'my-button' }, tech: 'css' }, path: 'my-button.css' }

Debuggability

In Node.js, console.log() calls util.inspect() on each argument without a formatting placeholder.

BemCell has inspect() method to get custom string representation of the object.

const BemFile = require('@bem/sdk.file');
const BemCell = require('@bem/sdk.cell');

const file = new BemFile({
    cell: BemCell.create({ block: 'input', mod: 'available', tech: 'css' }),
    level: 'blocks',
    path: 'blocks/input_mod.css'
});

console.log(file);

// ➜ BemFile {
//     cell: { entity: { block: 'input', mod: { name: 'available' } }, tech: 'css' },
//     path: 'my-button.css'
//   }

You can also convert BemFile object to a string.

const BemFile = require('@bem/sdk.file');
const BemCell = require('@bem/sdk.cell');

const file = new BemFile({
    cell: BemCell.create({ block: 'input', mod: 'available', layer: 'common', tech: 'css' }),
    level: 'common.blocks'
});

console.log(`file: ${file}`);

// ➜ file: common.blocks/[email protected]

Also BemFile has toJSON method to support JSON.stringify() behaviour.

const BemFile = require('@bem/sdk.file');
const BemCell = require('@bem/sdk.cell');

const file = new BemFile({
    cell: BemCell.create({ block: 'input', mod: 'available', layer: 'desktop', tech: 'css' }),
    level: 'node_modules/bem-components'
});

console.log(JSON.stringify(file, null, 2));

// ➜ {
//     "cell": {
//       "entity": {
//         "block": "input",
//         "mod": {
//           "name": "available",
//           "val": true
//         }
//       },
//       "tech": "css",
//       "layer": "desktop"
//     },
//     "level": "desktop.blocks"
//   }

Deprecation

Deprecation is performed with depd To silencing deprecation warnings from being output simply use this. Details

NO_DEPRECATION=@bem/sdk.file node app.js

License

Code and documentation © 2016 YANDEX LLC. Code released under the Mozilla Public License 2.0.