bem.sjs 922 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. var antmove_export = {};
  2. import antmove_1_module from './array.sjs';
  3. import antmove_2_module from './object.sjs';
  4. var array = antmove_1_module;
  5. var object = antmove_2_module;
  6. var PREFIX = 'van-';
  7. function join(name, mods) {
  8. name = PREFIX + name;
  9. mods = mods.map(function (mod) {
  10. return name + '--' + mod;
  11. });
  12. mods.unshift(name);
  13. return mods.join(' ');
  14. }
  15. function traversing(mods, conf) {
  16. if (!conf) {
  17. return;
  18. }
  19. if (typeof conf === 'string' || typeof conf === 'number') {
  20. mods.push(conf);
  21. } else if (array.isArray(conf)) {
  22. conf.forEach(function (item) {
  23. traversing(mods, item);
  24. });
  25. } else if (typeof conf === 'object') {
  26. object.keys(conf).forEach(function (key) {
  27. conf[key] && mods.push(key);
  28. });
  29. }
  30. }
  31. function bem(name, conf) {
  32. var mods = [];
  33. traversing(mods, conf);
  34. return join(name, mods);
  35. }
  36. antmove_export.bem = bem;
  37. export default antmove_export;