{"name":"@bem/sdk.naming.entity.stringify","version":"0.1.0-alpha.21b40d0b","description":"Stringifier for BEM entities","publishConfig":{"access":"public"},"license":"MPL-2.0","author":{"name":"Andrew Abramov","email":"mail@blond.im"},"keywords":["bem","naming","entity","name","representation","stringify"],"repository":{"type":"git","url":"git+https://github.com/bem/bem-sdk.git"},"engines":{"node":">= 4.0"},"main":"index.js","files":["lib/**","index.js"],"devDependencies":{"@bem/sdk.naming.presets":"^0.1.0-alpha.21b40d0b"},"scripts":{"bench":"matcha benchmark/*.js"},"bugs":{"url":"https://github.com/bem/bem-sdk/issues"},"homepage":"https://github.com/bem/bem-sdk#readme","_id":"@bem/sdk.naming.entity.stringify@0.1.0-alpha.21b40d0b","_npmVersion":"5.4.1","_nodeVersion":"8.4.0","_npmUser":{"name":"qfox","email":"zxqfox@gmail.com"},"dist":{"integrity":"sha512-mR87JT2+jdugsw0qJh2+STODkB6qBmTtmW5Xs2OtK9WGWHZKUb7qgovwFsD/MvNNZnU4PQ/ORFkbJC2TNAyr/g==","shasum":"cde8ac049d14c7cd45c9e352529975a60ea5403e","tarball":"http://registry-npm.ywwl.com/@bem/sdk.naming.entity.stringify/download/@bem/sdk.naming.entity.stringify-0.1.0-alpha.21b40d0b.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIH9IhGItxzMBaYwvWmm7moTSjYH9xSuHGOVXsTDxmbm+AiAbqV63R0EuKnPUmXE2yvZ+9ZZITXMNszc8utq8hCAiDg=="}],"size":1273,"noattachment":false,"key":"/@bem/sdk.naming.entity.stringify/-/@bem/sdk.naming.entity.stringify-0.1.0-alpha.21b40d0b.tgz"},"maintainers":[{"email":"yeti.or@gmail.com","name":"yeti-or"},{"email":"zxqfox@gmail.com","name":"qfox"},{"email":"veged@ya.ru","name":"veged"},{"email":"vitaly@harisov.name","name":"vithar"},{"email":"mail@blond.im","name":"blond"},{"email":"i@tadatuta.com","name":"tadatuta"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/sdk.naming.entity.stringify-0.1.0-alpha.21b40d0b.tgz_1506774867652_0.14057236211374402"},"directories":{},"readme":"# stringify\n\nStringifier for a [BEM entity](https://bem.info/methodology/key-concepts/#bem-entity) representation.\n\n[![NPM Status][npm-img]][npm]\n\n[npm]:          https://www.npmjs.org/package/@bem/sdk.naming.entity.stringify\n[npm-img]:      https://img.shields.io/npm/v/@bem/sdk.naming.entity.stringify.svg\n\n* [Introduction](#introduction)\n* [Try stringify](#try-stringify)\n* [Quick start](#quick-start)\n* [API reference](#api-reference)\n* [Parameter tuning](#parameter-tuning)\n\n## Introduction\n\nStringify returns a string with the name of the specified BEM entity representation. This name can be used in class attributes.\n\nYou can choose which [naming convention](https://en.bem.info/methodology/naming-convention/) to use for creating a `stingify()` function.\n\n> **Note.** If you don't have any BEM projects available to try out the `@bem/sdk.naming.entity.stringify` package, the quickest way to create one is to use [bem-express](https://github.com/bem/bem-express).\n\n## Try stringify\n\nAn example is available in the [RunKit editor](https://runkit.com/migs911/how-bem-sdk-naming-entity-stringify-works).\n\n## Quick start\n\n> **Attention.** To use `@bem/sdk.naming.entity.stringify`, you must install [Node.js 8.0+](https://nodejs.org/en/download/).\n\nTo run the `@bem/sdk.naming.entity.stringify` package:\n\n1. [Install required packages](#installing-required-packages).\n3. [Create a stringify() function](#creating-a-stringify-function).\n4. [Make a string from a BEM entity](#creating-a-string-from-a-bem-entity-name).\n\n### Installing required packages\n\nInstall the following packages:\n\n* [@bem/sdk.naming.entity.stringify](https://www.npmjs.org/package/@bem/sdk.naming.entity.stringify), which contains the `stringify()` function.\n* [@bem/sdk.naming.presets](https://www.npmjs.com/package/@bem/sdk.naming.presets), which contains presets with well-known naming conventions.\n\nTo install the packages, run the following command:\n\n```\n$ npm install --save @bem/sdk.naming.entity.stringify @bem/sdk.naming.presets\n```\n\n### Creating a `stringify()` function\n\nCreate a JavaScript file with any name (for example, **app.js**) and do the following:\n\n1. Choose the [naming convention](https://bem.info/methodology/naming-convention/) and import the preset with this convention (for example, origin naming convention).\n1. Import the `@bem/sdk.naming.entity.stringify` package and create the `stringify()` function using the imported preset:\n\n```js\nconst originNaming = require('@bem/sdk.naming.presets/origin');\nconst stringify = require('@bem/sdk.naming.entity.stringify')(originNaming);\n```\n\n### Creating a string from a BEM entity name\n\nStringify an object representation of a BEM entity:\n\n```js\nstringify({ block: 'my-block', mod: 'my-modifier' });\n```\n\nThis function will return the string `my-block_my-modifier`.\n\n**Example**:\n\n```js\nconst originNaming = require('@bem/sdk.naming.presets/origin');\nconst stringify = require('@bem/sdk.naming.entity.stringify')(originNaming);\n\nconsole.log(stringify({ block: 'my-block', mod: 'my-modifier' }));\n// => my-block_my-modifier\n\nconsole.log(stringify({ block: 'my-block', mod: { name: 'my-modifier'}}));\n// => my-block_my-modifier\n\nconsole.log(stringify({ block: 'my-block',\n                        mod: { name: 'my-modifier', val: 'some-value'}}));\n// => my-block__my-modifier_some-value\n\nconsole.log(stringify({ block: 'my-block', elem: 'my-element' }));\n// => my-block__my-element\n\nconsole.log(stringify({ block: 'my-block',\n                        elem: 'my-element',\n                        mod: 'my-modifier'}));\n// => my-block__my-element_my-modifier\n\nconsole.log(stringify({ block: 'my-block',\n                        elem: 'my-element',\n                        mod: { name: 'my-modifier', val: 'some-value'}}));\n// => my-block__my-element_my-modifier_some-value\n```\n\n[RunKit live example](https://runkit.com/migs911/stringify-using-origin-convention).\n\n## API reference\n\n### stringify()\n\nForms a string based on the object representation of a BEM entity.\n\n```js\n/**\n * @typedef BemEntityName\n * @property {string} block — Block name.\n * @property {string} [elem] — Element name.\n * @property {string|Object} [mod] — Modifier name or object with name and value.\n * @property {string} mod.name — Modifier name.\n * @property {string|boolean} [mod.val] — Modifier value.\n */\n\n/**\n * @param {object|BemEntityName} entity — Object representation of the BEM entity.\n * @returns {string} — Name of the BEM entity. This name can be used in class attributes.\n */\nstringify(entity);\n```\n\n## Parameter tuning\n\n### Using a custom naming convention\n\nSpecify an [INamingConvention](https://github.com/bem/bem-sdk/blob/master/packages/naming.presets/index.d.ts#L10) object with the `delims` field, which defines the delimiters that are used to separate names in the naming convention.\n\nUse this object to make your `stringify()` function.\n\n**Example:**\n\n```js\nconst convention = {\n    delims: {\n        elem: '_EL-',\n        mod: {\n            name: '_MOD-',\n            val: '-'\n    }}};\nconst stringify = require('@bem/sdk.naming.entity.stringify')(convention);\n\nconsole.log(stringify({ block: 'myBlock',\n                        elem: 'myElement',\n                        mod: 'myModifier'}));\n// => myBlock_EL-myElement_MOD-myModifier\n```\n\n[RunKit live example](https://runkit.com/migs911/stringify-usage-examples-custom-naming-convention).\n","publish_time":1506774868552,"_cnpm_publish_time":1506774868552,"dist-tags":{"canary":"0.1.0-alpha.21b40d0b","latest":"1.1.2"}}