bem.wxs 805B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* eslint-disable */
  2. var array = require('./array.wxs');
  3. var object = require('./object.wxs');
  4. var PREFIX = 'van-';
  5. function join(name, mods) {
  6. name = PREFIX + name;
  7. mods = mods.map(function(mod) {
  8. return name + '--' + mod;
  9. });
  10. mods.unshift(name);
  11. return mods.join(' ');
  12. }
  13. function traversing(mods, conf) {
  14. if (!conf) {
  15. return;
  16. }
  17. if (typeof conf === 'string' || typeof conf === 'number') {
  18. mods.push(conf);
  19. } else if (array.isArray(conf)) {
  20. conf.forEach(function(item) {
  21. traversing(mods, item);
  22. });
  23. } else if (typeof conf === 'object') {
  24. object.keys(conf).forEach(function(key) {
  25. conf[key] && mods.push(key);
  26. });
  27. }
  28. }
  29. function bem(name, conf) {
  30. var mods = [];
  31. traversing(mods, conf);
  32. return join(name, mods);
  33. }
  34. module.exports = bem;