« get me outta code hell

bind-utilities.js « write « src - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/write/bind-utilities.js
blob: 3d4ecc7ad6e4e3002136ac024cd6d921b1a6ae16 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Ties lots and lots of functions together in a convenient package accessible
// to page write functions. This is kept in a separate file from other write
// areas to keep imports neat and isolated.

import chroma from 'chroma-js';

import {getColors} from '#colors';
import {bindFind} from '#find';
import * as html from '#html';
import {bindOpts} from '#sugar';
import {thumb} from '#urls';

import {
  checkIfImagePathHasCachedThumbnails,
  getDimensionsOfImagePath,
  getThumbnailEqualOrSmaller,
  getThumbnailsAvailableForDimensions,
} from '#thumbs';

export function bindUtilities({
  absoluteTo,
  cachebust,
  defaultLanguage,
  getSizeOfAdditionalFile,
  getSizeOfImagePath,
  language,
  languages,
  missingImagePaths,
  pagePath,
  thumbsCache,
  to,
  urls,
  wikiData,
}) {
  const bound = {};

  Object.assign(bound, {
    absoluteTo,
    cachebust,
    defaultLanguage,
    getSizeOfAdditionalFile,
    getSizeOfImagePath,
    getThumbnailsAvailableForDimensions,
    html,
    language,
    languages,
    missingImagePaths,
    pagePath,
    thumb,
    to,
    urls,
    wikiData,
    wikiInfo: wikiData.wikiInfo,
  });

  bound.getColors = bindOpts(getColors, {chroma});

  bound.find = bindFind(wikiData, {mode: 'warn'});

  bound.checkIfImagePathHasCachedThumbnails =
    (imagePath) =>
      checkIfImagePathHasCachedThumbnails(imagePath, thumbsCache);

  bound.getDimensionsOfImagePath =
    (imagePath) =>
      getDimensionsOfImagePath(imagePath, thumbsCache);

  bound.getThumbnailEqualOrSmaller =
    (preferred, imagePath) =>
      getThumbnailEqualOrSmaller(preferred, imagePath, thumbsCache);

  return bound;
}