NodeLib.js 872 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. const NodeLib = {
  2. nodes: {},
  3. keywords: {},
  4. add: function ( node ) {
  5. this.nodes[ node.name ] = node;
  6. },
  7. addKeyword: function ( name, callback, cache ) {
  8. cache = cache !== undefined ? cache : true;
  9. this.keywords[ name ] = { callback: callback, cache: cache };
  10. },
  11. remove: function ( node ) {
  12. delete this.nodes[ node.name ];
  13. },
  14. removeKeyword: function ( name ) {
  15. delete this.keywords[ name ];
  16. },
  17. get: function ( name ) {
  18. return this.nodes[ name ];
  19. },
  20. getKeyword: function ( name, builder ) {
  21. return this.keywords[ name ].callback.call( this, builder );
  22. },
  23. getKeywordData: function ( name ) {
  24. return this.keywords[ name ];
  25. },
  26. contains: function ( name ) {
  27. return this.nodes[ name ] !== undefined;
  28. },
  29. containsKeyword: function ( name ) {
  30. return this.keywords[ name ] !== undefined;
  31. }
  32. };
  33. export { NodeLib };