⌈⌋ ⎇ branch:  Bitrhythm


Hex Artifact Content

Artifact c02db925c056e00016052a7f2bd6c87628e667a747decdf12e515da0d098193f:


0000: 69 6d 70 6f 72 74 20 7b 20 52 45 5f 48 54 4d 4c  import { RE_HTML
0010: 5f 41 54 54 52 53 20 7d 20 66 72 6f 6d 20 27 2e  _ATTRS } from '.
0020: 2f 2e 2e 2f 2e 2e 2f 67 6c 6f 62 61 6c 2d 76 61  /../../global-va
0030: 72 69 61 62 6c 65 73 27 0a 2f 2a 2a 0a 20 2a 20  riables'./**. * 
0040: 4d 69 6e 69 6d 69 7a 65 20 72 69 73 6b 3a 20 6f  Minimize risk: o
0050: 6e 6c 79 20 7a 65 72 6f 20 6f 72 20 6f 6e 65 20  nly zero or one 
0060: 5f 73 70 61 63 65 5f 20 62 65 74 77 65 65 6e 20  _space_ between 
0070: 61 74 74 72 20 26 20 76 61 6c 75 65 0a 20 2a 20  attr & value. * 
0080: 40 70 61 72 61 6d 20 20 20 7b 20 53 74 72 69 6e  @param   { Strin
0090: 67 20 7d 20 20 20 68 74 6d 6c 20 2d 20 68 74 6d  g }   html - htm
00a0: 6c 20 73 74 72 69 6e 67 20 77 65 20 77 61 6e 74  l string we want
00b0: 20 74 6f 20 70 61 72 73 65 0a 20 2a 20 40 70 61   to parse. * @pa
00c0: 72 61 6d 20 20 20 7b 20 46 75 6e 63 74 69 6f 6e  ram   { Function
00d0: 20 7d 20 66 6e 20 2d 20 63 61 6c 6c 62 61 63 6b   } fn - callback
00e0: 20 66 75 6e 63 74 69 6f 6e 20 74 6f 20 61 70 70   function to app
00f0: 6c 79 20 6f 6e 20 61 6e 79 20 61 74 74 72 69 62  ly on any attrib
0100: 75 74 65 20 66 6f 75 6e 64 0a 20 2a 2f 0a 65 78  ute found. */.ex
0110: 70 6f 72 74 20 64 65 66 61 75 6c 74 20 66 75 6e  port default fun
0120: 63 74 69 6f 6e 20 77 61 6c 6b 41 74 74 72 69 62  ction walkAttrib
0130: 75 74 65 73 28 68 74 6d 6c 2c 20 66 6e 29 20 7b  utes(html, fn) {
0140: 0a 20 20 69 66 20 28 21 68 74 6d 6c 29 20 72 65  .  if (!html) re
0150: 74 75 72 6e 0a 20 20 6c 65 74 20 6d 0a 20 20 77  turn.  let m.  w
0160: 68 69 6c 65 20 28 6d 20 3d 20 52 45 5f 48 54 4d  hile (m = RE_HTM
0170: 4c 5f 41 54 54 52 53 2e 65 78 65 63 28 68 74 6d  L_ATTRS.exec(htm
0180: 6c 29 29 0a 20 20 20 20 66 6e 28 6d 5b 31 5d 2e  l)).    fn(m[1].
0190: 74 6f 4c 6f 77 65 72 43 61 73 65 28 29 2c 20 6d  toLowerCase(), m
01a0: 5b 32 5d 20 7c 7c 20 6d 5b 33 5d 20 7c 7c 20 6d  [2] || m[3] || m
01b0: 5b 34 5d 29 0a 7d 0a                             [4]).}.