Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

How @bem/sdk.decl works?

node v10.24.1
version: 1.0.0
endpointsharetweet
const bemDecl = require('@bem/sdk.decl'); // Create two files with declarations: const mock = require('mock-fs'); mock({ 'set1.bemdecl.js': "exports.blocks = [\n {name: 'a'},\n {name: 'b'},\n {name: 'c'}\n];", 'set2.bemdecl.js': "exports.blocks = [\n {name: 'b'},\n {name: 'e'}\n];" }); // In the RunKit you don't need to use an async function // Await loading of file and put it to `set1` variable const set1 = await bemDecl.load('set1.bemdecl.js'); // `set1` is an array of BemCell objects, // convert them to strings using `.map` and special `id` property: set1.map(c => c.id);
// Load the second set const set2 = await bemDecl.load('set2.bemdecl.js'); set2.map(c => c.id);
bemDecl.subtract(set1, set2).map(c => c.id);
bemDecl.subtract(set2, set1).map(c => c.id);
bemDecl.intersect(set1, set2).map(c => c.id);
bemDecl.merge(set1, set2).map(c => c.id);
const mergedSet = bemDecl.normalize(bemDecl.merge(set1, set2)); bemDecl.save('mergedSet.bemdecl.js', mergedSet, { format: 'v1', exportType: 'commonjs' }) const fs = require('fs'); fs.readFile('mergedSet.bemdecl.js', 'utf-8', (err, data) => { if (err) throw err; console.log(data); });
Loading…

no comments

    sign in to comment