« get me outta code hell

withWebArchiveDate.js « content « things « composite « data « src - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/composite/things/content/withWebArchiveDate.js
blob: 08cebd7fe83c9278905feebc35d06ded72041622 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import {input, templateCompositeFrom} from '#composite';

import {raiseOutputWithoutDependency} from '#composite/control-flow';

export default templateCompositeFrom({
  annotation: `withWebArchiveDate`,

  outputs: ['#webArchiveDate'],

  steps: () => [
    {
      dependencies: ['sourceURLs'],

      compute: (continuation, {sourceURLs}) =>
        continuation({
          ['#dateText']:
            sourceURLs
              .find(url => url.match(/https?:\/\/web\.archive\.org/))
              ?.match(/\/web\/([0-9]{8,8})[0-9]*\//)
              ?.[1] ??
            null,
        }),
    },

    raiseOutputWithoutDependency({
      dependency: '#dateText',
      output: input.value({['#webArchiveDate']: null}),
    }),

    {
      dependencies: ['#dateText'],
      compute: (continuation, {['#dateText']: dateText}) =>
        continuation({
          ['#webArchiveDate']:
            new Date(
              dateText.slice(0, 4) + '/' +
              dateText.slice(4, 6) + '/' +
              dateText.slice(6, 8)),
        }),
    },
  ],
});