Code Monkey home page Code Monkey logo

deps-normalize's Introduction

deps-normalize

NPM version Build Status Dependency Status

This module used to normalize require and expect properties in BEM object.

Usage

var normalize = require('deps-normalize');

normalize(undefined);               // []
normalize({ block: 'block' });      // [ { block: 'block' } ]
normalize({ elem: 'elem' });        // [ { elem: 'elem' } ]

// See more examples in tests

API

normalize(dependencies, [options])

Runs normalization of dependencies. Returns array of normalized dependencies.

dependencies

Type: Object / String

options

Type: Object

  • parseString - contains Function, that will parse dependencies if they passed as string.

Normalization

Dependencies should contain deps objects (or String). We do not support full specification. Those objects are equivalents of BEM objects, but with additional properties, that reduces boilerplate code. After they are normalized, they can be converted to BEM objects.

  • elems - contains Array of String (if it contains String it will be wrapped in array).
  • mods - contains Object with keys as modificators names and values as modificators values. Values can be Number, Boolean, String or Array of String.

If deps object contain elems or mods it will be splitted in multiple BEM objects. It will not take multiplication of elems and mods, if both are present in deps object. Instead it will be interpretated as two deps objects: one with elems and other with mods.

normalize({ elems: ['e1', 'e2'], mods: {m1: 1, m2: [2, 3]} });

// [
//     { block: 'b', elem: 'e1' },
//     { block: 'b', elem: 'e2' },
//     { block: 'b', modName: 'm1', modVal: 1 },
//     { block: 'b', modName: 'm2', modVal: 2 },
//     { block: 'b', modName: 'm2', modVal: 3 }
// ]

level, block, elem, mod and value properties will be taken from current processing object.

Note: you can not have elem with elems in one deps object (same applies to mod and mods).

License

MIT (c) 2014 Vsevolod Strukchinsky

deps-normalize's People

Contributors

egavr avatar f0rmat1k avatar floatdrop avatar pavelpower avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

deps-normalize's Issues

Exception on an empty object

Are you sure that throwing an exception on an empty object in the input is a good solution?

I mean

normalize(undefined) // []

BUT

normalize({}) // throw ERROR

WHY?

Maybe it should be

normalize({}) // []

Incorrect working when

...array one the first level, e.g.:

//noinspection BadExpressionStatementJS
([
    {
        tech: 'js',
        shouldDeps: [
            { block: 'foo.deps', tech: 'bemhtml' }
        ]
    },
    {
        mustDeps: [],
        shouldDeps: [
            { elems: ['foo', 'baz'] }
        ]
    }
]);

enb process it correctly.

Bug in normalization

normalize({block: 'i-bem', elem: ['dom', 'html']}) // [ { elem: 'dom', block: 'i-bem' }, { elem: 'html', block: 'i-bem' } ]
// It is OK!

BUT

// elemS, not elem
normalize({block: 'i-bem', elems: ['dom', 'html']}) // [ { elem: 'dom', block: 'i-bem' }, { elem: 'html', block: 'i-bem' } ]

// It is NOT OK! it should be [ {block: 'i-bem'}, { elem: 'dom', block: 'i-bem' }, { elem: 'html', block: 'i-bem' } ]
// Field `elems` says that an entity should depend from a block and its elems, not just from its elems

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.