• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nilfalse / ctf / 5752977660

pending completion
5752977660

Pull #298

github

web-flow
Merge b6f7f6972 into da4e6f9f9
Pull Request #298: Update all of jest 27.5.1 → 29.6.2 (major)

0 of 266 branches covered (0.0%)

Branch coverage included in aggregate %.

0 of 613 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/packages/cli/twemoji.js
1
import assert from 'assert';
2
import * as fs from 'fs';
3
import * as https from 'https';
4
import * as path from 'path';
5

6
import flags from 'country-flag-emoji-json/dist/by-code.json';
7
import fetch from 'node-fetch';
8

9
export function main(binPath, twemojiRoot) {
10
  const twemoji = new Twemoji(twemojiRoot);
×
11

12
  return twemoji.download().catch((err) => {
×
13
    console.error(err);
×
14

15
    process.exit(1);
×
16
  });
17
}
18

19
class Twemoji {
20
  constructor(twemojiRoot) {
21
    this.twemojiRoot = twemojiRoot;
×
22

23
    this.agent = new https.Agent({ keepAlive: true });
×
24
  }
25

26
  get flags() {
27
    return Object.entries(flags).map(
×
28
      ([code, flag]) => new TwemojiFlag(code, flag)
×
29
    );
30
  }
31

32
  download() {
33
    return Promise.all(
×
34
      this.flags.map((flag) =>
35
        flag.download(this.agent).then((res) => this._persist(flag, res))
×
36
      )
37
    );
38
  }
39

40
  _persist(flag, response) {
41
    console.log(`${flag.countryCode} -- ${flag.remoteUrl}`);
×
42

43
    if (response.ok) {
×
44
      return response.body.pipe(
×
45
        fs.createWriteStream(`${this.twemojiRoot}${flag.localPath}`)
46
      );
47
    } else {
48
      response.headers.forEach((value, name) =>
×
49
        console.log(`  ${name}: ${value}`)
×
50
      );
51

52
      return Promise.reject(
×
53
        new Error(`${response.status} ${response.statusText}`)
54
      );
55
    }
56
  }
57
}
58

59
class TwemojiFlag {
60
  constructor(code, { unicode }) {
61
    this.unicode = unicode;
×
62

63
    this.countryCode = code.toLowerCase();
×
64
    this.localPath = `${path.sep}${this.countryCode}.svg`;
×
65
    this.remoteUrl = `https://twemoji.maxcdn.com/v/latest/svg/${this.codepoints}.svg`;
×
66
  }
67

68
  download(agent) {
69
    return fetch(this.remoteUrl, {
×
70
      agent,
71
    });
72
  }
73

74
  get codepoints() {
75
    const codepoints = this.unicode
×
76
      .toLowerCase()
77
      .split(' ')
78
      .map((codePoint) => {
79
        assert(
×
80
          codePoint.startsWith('u+'),
81
          `Code point "${codePoint}" does not start with "u+"`
82
        );
83

84
        return codePoint.substring(2);
×
85
      });
86

87
    return codepoints.join('-');
×
88
  }
89
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc