{"name":"bem-naming","version":"0.2.0","description":"Manage naming of BEM entities","keywords":["bem","naming"],"author":{"name":"Andrew Abramov","email":"andrewblond@yandex.com"},"repository":{"type":"git","url":"git://github.com/bem/bem-naming"},"homepage":"https://github.com/bem/bem-naming","bugs":{"url":"https://github.com/bem/bem-naming/issues"},"contributors":[{"name":"Andrew Abramov","email":"andrewblond@yandex.com"}],"engines":{"node":">= 0.10.0"},"main":"lib/bem-naming","files":["lib"],"devDependencies":{"mocha":"1.21.4","should":"4.0.4","zuul":"1.10.1","jshint":"2.5.3","jscs":"1.5.9","istanbul":"0.3.0","uglify-js":"2.4.15"},"scripts":{"test":"npm run lint && npm run node-test && npm run browser-test && npm run cover","lint":"jshint . && jscs -c .jscs.js .","node-test":"mocha ./test/**/*.test.js","browser-test":"zuul -- ./test/**/*.test.js","cover":"istanbul cover _mocha -- ./test/**/*.test.js","min":"uglifyjs lib/bem-naming.js > bem-naming.min.js"},"gitHead":"5f0fe146d779f2f646d108a5ef83446f11a46e83","_id":"bem-naming@0.2.0","_shasum":"a0d5ed2a80295d8d210f1fc34558e3e5ae08c74f","_from":".","_npmVersion":"2.0.0-alpha-5","_npmUser":{"name":"andrewblond","email":"andrewblond@yandex.com"},"maintainers":[{"name":"andrewblond","email":"andrewblond@yandex.com"}],"dist":{"shasum":"a0d5ed2a80295d8d210f1fc34558e3e5ae08c74f","tarball":"http://registry-npm.ywwl.com/bem-naming/download/bem-naming-0.2.0.tgz","integrity":"sha512-F8NM3jJBeNkM8ah1b0ItLuTJyV1z7nP8IoQTtIMvqz7yUi86zvnBsp/3t2KR+/GqYhTIjefl2dOsmqMjMoknqg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCkgTrTWZfmZ4A83u6XhSAoEXt1koiDCD9YTCmzaE465gIgOIU0U6GXkJ0OjPU0VCAF36nx2KJG0wVonQMKl4FKf3k="}],"size":2971,"noattachment":false,"key":"/bem-naming/-/bem-naming-0.2.0.tgz"},"directories":{},"readme":"bem-naming\n==========\n\n[![NPM Status][npm-img]][npm]\n[![Travis Status][test-img]][travis]\n[![Coverage Status][coverage-img]][coveralls]\n\n[npm]:          https://www.npmjs.org/package/bem-naming\n[npm-img]:      https://img.shields.io/npm/v/bem-naming.svg\n\n[travis]:       https://travis-ci.org/bem/bem-naming\n[test-img]:     https://img.shields.io/travis/bem/bem-naming.svg\n\n[coveralls]:    https://coveralls.io/r/bem/bem-naming\n[coverage-img]: https://img.shields.io/coveralls/bem/bem-naming.svg\n\nAbout\n-----\n\nThis tool allows getting information about BEM entity using [string](#string-representation) as well as forming string representation based on [naming object](#object-representation-of-bem-entity).\n\nInstall\n-------\n\n```\n$ npm install --save bem-naming\n```\n\nUsage\n-----\n\n```js\nvar bemNaming = require('bem-naming');\n\nbemNaming.parse('button__text'); // { block: 'button', elem: 'text' }\n\nbemNaming.stringify({ block: 'button', modName: 'checked' }); // button_checked\n```\n\nTable of Contents\n-----------------\n\n* [String representation](#string-representation)\n* [Object representation of BEM entity](#object-representation-of-bem-entity)\n* [API](#api)\n* [Common misconceptions](#common-misconceptions)\n* [Custom naming convention](#custom-naming-convention)\n* [Convention by Harry Roberts](#convention-by-harry-roberts)\n\nString representation\n---------------------\nTo define BEM entities we often use a special string format that allows us 100% define what entity exactly is represented.\n\nAccording to original BEM-naming convention it looks like the following:\n\n```js\n'block[_block-mod-name[_block-mod-val]][__elem-name[_elem-mod-name[_elem-mod-val]]]'\n```\n\n*(Parameters within square brackets are optional)*\n\n* Block — `block-name`.\n* Block's modifier in key-value format — `block-name_mod-name_mod-val`.\n* Block's boolean modifier — `block-name_mod`.\n* Block's element — `block-name__elem-name`.\n* Element's modifier in key-value format — `block-name__elem-name_mod-name_mod-val`.\n* Element's boolean modifier — `block-name__elem_mod`.\n\nObject representation of BEM entity\n-----------------------------------\n\nBEM entities can be defined with a help of JS object with the following fields:\n\n* `block` — a block name. The field is required because only a block exists as an independent BEM entity\n* `elem` — an element name.\n* `modName` — a modifier name.\n* `modVal` — a modifier value.\n\nThe modifier consists of a pair of fields `modName` and `modVal`. This means that the field `modVal` without `modName` has no meaning.\n\nExample:\n\n```js\n// The block modifier\n{\n    block: 'block',\n    modName: 'mod',\n    modVal: 'val'\n}\n\n// Not valid BEM-notation\n{\n    block: 'block',\n    modVal: 'val'\n}\n```\n\nTo describe the boolean modifier field `modVal` must be specified as `true`.\n\nExample:\n\n```js\n// Boolean modifier of a block\n{\n    block: 'block',\n    modName: 'mod',\n    modVal: true\n}\n\n// Shorthand for the boolean modifier of a block\n{\n    block: 'block',\n    modName: 'mod'\n}\n\n// Not valid BEM-notation\n{\n    block: 'block',\n    modName: 'mod',\n    modVal: false\n}\n```\n\nAPI\n---\n\n* [validate(str)](#validatestr)\n* [parse(str)](#parsestr)\n* [stringify(obj)](#stringifyobj)\n* [typeOf(str)](#typeofstr)\n* [typeOf(obj)](#typeofobj)\n* [isBlock(str)](#isblockstr)\n* [isBlock(obj)](#isblockobj)\n* [isBlockMod(str)](#isblockmodstr)\n* [isBlockMod(obj)](#isblockmodobj)\n* [isElem(str)](#iselemstr)\n* [isElem(obj)](#iselemobj)\n* [isElemMod(str)](#iselemmodstr)\n* [isElemMod(obj)](#iselemmodobj)\n* [elemDelim](#elemdelim)\n* [modDelim](#moddelim)\n* [modValDelim](#modvaldelim)\n\n### validate(str)\n\nChecks a string to be valid BEM notation.\n\nExample:\n\n```js\nbemNaming.validate('block-name');  // true\nbemNaming.validate('^*^');         // false\n```\n\n### parse(str)\n\nIt parses string into naming object.\n\nExample:\n\n```js\nbemNaming.parse('block__elem_mod_val');  // { block: 'block', elem: 'elem',\n                                         //   modName: 'mod', modVal: 'val' }\n```\n\n### stringify(obj)\n\nIt forms a string according to naming object.\n\nExample:\n\n```js\nbemNaming.stringify({\n    block: 'block', elem: 'elem',\n    modName: 'mod', modVal: 'val'\n}); // 'block__elem_mod_val'\n```\n\n### `typeOf(str)`\n\nReturns a string indicating the type of the BEM entity.\n\nExample:\n\n```js\nbemNaming.typeOf('block');             // block\nbemNaming.typeOf('block_mod');         // blockMod\nbemNaming.typeOf('block__elem');       // elem\nbemNaming.typeOf('block__elem_mod');   // elemMod\n```\n\n### typeOf(obj)\n\nReturns a string indicating the type of the BEM entity.\n\nExample:\n\n```js\nbemNaming.typeOf({ block: 'block' });                               // block\nbemNaming.typeOf({ block: 'block', modName: 'mod' });               // blockMod\nbemNaming.typeOf({ block: 'block', elem: 'elem' });                 // elem\nbemNaming.typeOf({ block: 'block', elem: 'elem', modName: 'mod' }); // elemMod\n```\n\n### isBlock(str)\n\nChecks whether string is a block.\n\nExample:\n\n```js\nbemNaming.isBlock('block-name');   // true\nbemNaming.isBlock('block__elem');  // false\n```\n\n### isBlock(obj)\n\nChecks whether naming object is a block.\n\nExample:\n\n```js\nbemNaming.isBlock({ block: 'block-name' });           // true\nbemNaming.isBlock({ block: 'block', elem: 'elem' });  // false\n```\n\n### isBlockMod(str)\n\nChecks whether string is modifier of a block.\n\nExample:\n\n```js\nbemNaming.isBlockMod('block_mod');        // true\nbemNaming.isBlockMod('block__elem_mod');  // false\n```\n\n### isBlockMod(obj)\n\nChecks whether naming object is modifier of a block.\n\nExample:\n\n```js\nbemNaming.isBlockMod({ block: 'block',\n    modName: 'mod', modVal: true });  // true\n\nbemNaming.isBlockMod({ block: 'block', elem: 'elem',\n    modName: 'mod', modVal: true });  // false\n```\n\n### isElem(str)\n\nChecks whether string is element of a block.\n\nExample:\n\n```js\nbemNaming.isElem('block__elem');  // true\nbemNaming.isElem('block-name');   // false\n```\n\n### isElem(obj)\n\nChecks whether naming object is element of a block.\n\nExample:\n\n```js\nbemNaming.isElem({ block: 'block', elem: 'elem' });  // true\nbemNaming.isElem({ block: 'block-name' });           // false\n```\n\n### isElemMod(str)\n\nChecks whether string is modifier of an element.\n\nExample:\n\n```js\nbemNaming.isElemMod('block__elem_mod');  // true\nbemNaming.isElemMod('block__elem');      // false\n```\n\n### isElemMod(obj)\n\nChecks whether naming object is modifier of an element.\n\nExample:\n\n```js\nbemNaming.isElemMod({ block: 'block', elem: 'elem',\n    modName: 'mod', modVal: true });  // true\n\nbemNaming.isElemMod({ block: 'block',\n    modName: 'mod', modVal: true});   // false\n```\n\n### elemDelim\n\nString to separate elem from block.\n\n### modDelim\n\nString to separate modifiers from blocks and elements.\n\n### modValDelim\n\nString to separate value of modifier from name of modifier.\n\nCommon misconceptions\n---------------------\n\nBEM methodology involves the use of flat structure inside a block. It means that BEM entity can not be represented as an element of the other element and the following string representation will be invalid:\n\n```js\n'block__some-elem__sub-elem'\n```\n\nAlso there is no such BEM entity as a modifier and an element modifier simultaneously so the following string representation will be invalid:\n\n```js\n'block_block-mod-name_block-mod-val__elem-name_elem-mod-name_elem-mod-val'\n```\n\nCustom naming convention\n------------------------\n\nUse `bemNaming` function to create instance to manage naming of your own naming convention.\n\nExample:\n\n```js\nvar myNaming = bemNaming({\n    elem: '-',\n    mod: { name: '--', val: '_' }\n    wordPattern: '[a-zA-Z0-9]+'   // because element and modifier's separators include\n});                               // hyphen in it, we need to exclude it from block,\n                                  // element and modifier's name\n\nmyNaming.parse('block--mod_val'); // { block: 'block',\n                                  //   modName: 'mod', modVal: 'val' }\n\nmyNaming.stringify({              // 'blockName-elemName--boolElemMod'\n    block: 'blockName',\n    elem: 'elemName',\n    modName: 'boolElemMod'\n});\n```\n\n### bemNaming({ elem, mod, wordPattern })\n\n#### elem\n\nType: `String`\n\nDefault: `__`\n\nSeparates element's name from block\n\n#### mod\n\nType: `String`, `{ name: String, val: String }`\n\nDefault: `_`\n\nSeparates modifiers from blocks and elements.\n\nThis option can take object with following fields:\n\n* `name` — separates name of modifier from blocks and elements.\n\n  Default as `_`.\n\n* `val` — separates value of modifier from name of modifier.\n\n  Default as the value of the `name`.\n\n#### wordPattern\n\nType: `String`\n\nDefault: `[a-z0-9]+(?:-[a-z0-9]+)*`\n\nDefines which symbols can be used for block, element and modifier's names.\n\nConvention by Harry Roberts\n---------------------------\n\nAccording to this convention elements are delimited with two underscores (`__`), modifiers are delimited by two hyphens (`--`), and values of modifiers are delimited by one underscore (`_`).\n\nRead more in the [Guidelines](http://cssguidelin.es/#bem-like-naming).\n\nExample:\n\n```js\nvar twoDashes = bemNaming('two-dashes');\n\ntwoDashes.parse('block__elem');    // { block: 'block', elem: 'elem' }\ntwoDashes.parse('block--mod_val'); // { block: 'block',\n                                   //   modName: 'mod', modVal: 'val' }\n\ntwoDashes.stringify({              // 'block__elem--mod'\n    block: 'block',\n    elem: 'elem',\n    modName: 'mod'\n});\n```\n\nLicense\n-------\n\nCode and documentation copyright 2014 YANDEX LLC. Code released under the [Mozilla Public License 2.0](LICENSE.txt).\n","publish_time":1407705223205,"_cnpm_publish_time":1407705223205,"dist-tags":{"latest":"1.0.1"}}