Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. const acceptable_type = function(variable) :boolean {
  2. const type = typeof variable;
  3. return (type === "string" || type === "symbol" || type === "number");
  4. };
  5.  
  6. export default class Noty {
  7.  
  8. private _note = {};
  9.  
  10. note (name : string|symbol|number, content : any = true, ...more_contents) : Noty {
  11.  
  12. if(more_contents.length !== 0) {
  13. content = [content, ...more_contents];
  14. }
  15. name in this._note ? this._note[name].push(content) : this._note[name] = [content];
  16.  
  17. return this
  18.  
  19. };
  20.  
  21. // INDISTINGUISHABLE RETURN VALUE returns the thing being noted and take it off memory. if nothing noted, return null. cannot distinguish between a null note and not noted.
  22. noted (name : string|symbol|number) : any {
  23.  
  24. if(name in this._note) {
  25.  
  26. const content = this._note[name].pop();
  27. if(this._note[name].length === 0)
  28. delete this._note[name];
  29. return content;
  30. }
  31. else
  32. return null;
  33. // noted returns data or null, but data itself could be null, in which case,
  34. // noted cannot distinguish between whether something is not noted or something is noted as null.
  35. // to determine that, call 'noting'.
  36. };
  37.  
  38. // always returns true or false indicating if the entry is being noted.
  39. noting (name : string|symbol|number) : boolean {
  40.  
  41. return name in this._note;
  42. };
  43.  
  44. // returns array if the dismissed note exists_json, otherwise returns []
  45. dismiss (name : string|symbol|number) : Array<any> {
  46.  
  47. let note_array = name in this._note ? this._note[name] : [];
  48. delete this._note[name];
  49. return note_array;
  50. };
  51.  
  52. // always returns array, even when nothing is noted, then it returns empty array.
  53. notes () : Array<string> {
  54.  
  55. return Object.keys(this._note);
  56. };
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement