Skip to content

Commit e29afab

Browse files
committed
Add standard style.
1 parent def64af commit e29afab

File tree

18 files changed

+2649
-849
lines changed

18 files changed

+2649
-849
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#! /usr/bin/env node
2-
const {makeProgram} = require('./src/cli');
2+
const { makeProgram } = require('./src/cli')
33

4-
makeProgram().parse();
4+
makeProgram().parse()

jest.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module.exports = {
3131
// ],
3232

3333
// Indicates which provider should be used to instrument code for coverage
34-
coverageProvider: "v8",
34+
coverageProvider: 'v8'
3535

3636
// A list of reporter names that Jest uses when writing coverage reports
3737
// coverageReporters: [
@@ -191,4 +191,4 @@ module.exports = {
191191

192192
// Whether to use watchman for file crawling
193193
// watchman: true,
194-
};
194+
}

package-lock.json

Lines changed: 1935 additions & 129 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "A CLI for Torchlight - the syntax highlighting API",
55
"main": "index.js",
66
"scripts": {
7-
"test": "jest"
7+
"test": "standard && jest"
88
},
99
"bin": {
1010
"torchlight": "index.js"
@@ -24,9 +24,12 @@
2424
"commander": "^8.1.0",
2525
"fs-extra": "^10.0.0",
2626
"inquirer": "^8.1.2",
27-
"jest": "^27.0.6",
2827
"lodash.chunk": "^4.2.0",
2928
"lodash.get": "^4.4.2",
3029
"md5": "^2.3.0"
30+
},
31+
"devDependencies": {
32+
"jest": "^27.0.6",
33+
"standard": "^16.0.3"
3134
}
3235
}

src/block.js

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,78 @@
1-
const md5 = require('md5');
2-
const guid = require('./support/guid');
3-
const torchlight = require('./torchlight');
4-
5-
let Block = function (opts = {}) {
6-
opts = {
7-
id: guid(),
8-
theme: torchlight.config('theme', 'nord'),
9-
...opts,
10-
}
11-
12-
this.id = opts.id;
13-
this.code = opts.code;
14-
this.language = opts.language;
15-
this.theme = opts.theme;
16-
17-
this.highlighted = null;
18-
this.classes = null;
19-
this.styles = null;
1+
const md5 = require('md5')
2+
const guid = require('./support/guid')
3+
const torchlight = require('./torchlight')
4+
5+
const Block = function (opts = {}) {
6+
opts = {
7+
id: guid(),
8+
theme: torchlight.config('theme', 'nord'),
9+
...opts
10+
}
11+
12+
this.id = opts.id
13+
this.code = opts.code
14+
this.language = opts.language
15+
this.theme = opts.theme
16+
17+
this.highlighted = null
18+
this.classes = null
19+
this.styles = null
2020
}
2121

2222
Block.prototype.hash = function () {
23-
return md5(''
24-
+ this.language
25-
+ this.theme
26-
+ this.code
27-
+ torchlight.config('bust', 0)
28-
+ JSON.stringify(torchlight.config('options'))
29-
)
23+
return md5('' +
24+
this.language +
25+
this.theme +
26+
this.code +
27+
torchlight.config('bust', 0) +
28+
JSON.stringify(torchlight.config('options'))
29+
)
3030
}
3131

3232
Block.prototype.code = function (code) {
33-
this.code = code;
33+
this.code = code
3434

35-
return this;
35+
return this
3636
}
3737

3838
Block.prototype.language = function (language) {
39-
this.language = language;
39+
this.language = language
4040

41-
return this;
41+
return this
4242
}
4343

4444
Block.prototype.theme = function (theme) {
45-
this.theme = theme;
45+
this.theme = theme
4646

47-
return this;
47+
return this
4848
}
4949

5050
Block.prototype.placeholder = function (extra = '') {
51-
if (extra) {
52-
extra = `-${extra}`;
53-
}
51+
if (extra) {
52+
extra = `-${extra}`
53+
}
5454

55-
return `__torchlight-block-[${this.id}]${extra}__`;
55+
return `__torchlight-block-[${this.id}]${extra}__`
5656
}
5757

5858
Block.prototype.setResponseData = function (data) {
59-
if (data) {
60-
this.highlighted = data.highlighted;
61-
this.classes = data.classes;
62-
this.styles = data.styles;
63-
}
59+
if (data) {
60+
this.highlighted = data.highlighted
61+
this.classes = data.classes
62+
this.styles = data.styles
63+
}
6464

65-
return this;
65+
return this
6666
}
6767

6868
Block.prototype.toRequestParams = function () {
69-
return {
70-
id: this.id,
71-
hash: this.hash,
72-
language: this.language,
73-
theme: this.theme,
74-
code: this.code,
75-
}
69+
return {
70+
id: this.id,
71+
hash: this.hash,
72+
language: this.language,
73+
theme: this.theme,
74+
code: this.code
75+
}
7676
}
7777

78-
module.exports = Block;
78+
module.exports = Block

src/cache/file.js

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
const md5 = require('md5');
2-
const path = require('path');
1+
const md5 = require('md5')
2+
const path = require('path')
33
const {
4-
readJsonSync,
5-
writeJsonSync,
6-
ensureDirSync,
7-
pathExistsSync,
8-
removeSync
4+
readJsonSync,
5+
writeJsonSync,
6+
ensureDirSync,
7+
pathExistsSync,
8+
removeSync
99
} = require('fs-extra')
1010

1111
/**
1212
* @param options
1313
* @constructor
1414
*/
15-
let File = function (options = {}) {
16-
if (!options.directory) {
17-
throw new Error('No cache directory specified.');
18-
}
15+
const File = function (options = {}) {
16+
if (!options.directory) {
17+
throw new Error('No cache directory specified.')
18+
}
1919

20-
this.directory = path.resolve(options.directory)
20+
this.directory = path.resolve(options.directory)
2121

22-
ensureDirSync(this.directory);
22+
ensureDirSync(this.directory)
2323
}
2424

2525
/**
@@ -30,19 +30,19 @@ let File = function (options = {}) {
3030
* @return {*}
3131
*/
3232
File.prototype.get = function (key, def) {
33-
if (!pathExistsSync(this.filename(key))) {
34-
return def;
35-
}
33+
if (!pathExistsSync(this.filename(key))) {
34+
return def
35+
}
3636

37-
let entry = readJsonSync(this.filename(key));
37+
const entry = readJsonSync(this.filename(key))
3838

39-
if (Date.now() / 1000 > entry.expires) {
40-
this.delete(key);
39+
if (Date.now() / 1000 > entry.expires) {
40+
this.delete(key)
4141

42-
return def;
43-
}
42+
return def
43+
}
4444

45-
return entry.value;
45+
return entry.value
4646
}
4747

4848
/**
@@ -53,10 +53,10 @@ File.prototype.get = function (key, def) {
5353
* @param {number} ttlSeconds
5454
*/
5555
File.prototype.set = function (key, value, ttlSeconds = 60 * 24 * 7) {
56-
writeJsonSync(this.filename(key), {
57-
expires: (Date.now() / 1000) + ttlSeconds,
58-
value: value
59-
});
56+
writeJsonSync(this.filename(key), {
57+
expires: (Date.now() / 1000) + ttlSeconds,
58+
value: value
59+
})
6060
}
6161

6262
/**
@@ -65,22 +65,22 @@ File.prototype.set = function (key, value, ttlSeconds = 60 * 24 * 7) {
6565
* @param key
6666
*/
6767
File.prototype.delete = function (key) {
68-
removeSync(this.filename(key));
68+
removeSync(this.filename(key))
6969
}
7070

7171
/**
7272
* Clear the cache.
7373
*/
7474
File.prototype.clear = function () {
75-
removeSync(this.directory);
75+
removeSync(this.directory)
7676
}
7777

7878
/**
7979
* @param {string} key
8080
* @return {string}
8181
*/
8282
File.prototype.filename = function (key) {
83-
return path.join(this.directory, md5(key) + '.json');
83+
return path.join(this.directory, md5(key) + '.json')
8484
}
8585

86-
module.exports = File;
86+
module.exports = File

src/cache/memory.js

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
let store = {};
1+
let store = {}
22

3-
let Memory = function () {
4-
//
3+
const Memory = function () {
4+
//
55
}
66

77
/**
@@ -12,19 +12,19 @@ let Memory = function () {
1212
* @return {*}
1313
*/
1414
Memory.prototype.get = function (key, def) {
15-
if (!store.hasOwnProperty(key)) {
16-
return def;
17-
}
15+
if (!Object.prototype.hasOwnProperty.call(store, key)) {
16+
return def
17+
}
1818

19-
let entry = store[key];
19+
const entry = store[key]
2020

21-
if (Date.now() / 1000 > entry.expires) {
22-
this.delete(key);
21+
if (Date.now() / 1000 > entry.expires) {
22+
this.delete(key)
2323

24-
return def;
25-
}
24+
return def
25+
}
2626

27-
return entry.value;
27+
return entry.value
2828
}
2929

3030
/**
@@ -35,10 +35,10 @@ Memory.prototype.get = function (key, def) {
3535
* @param {number} ttlSeconds
3636
*/
3737
Memory.prototype.set = function (key, value, ttlSeconds = 60 * 24 * 7) {
38-
store[key] = {
39-
expires: (Date.now() / 1000) + ttlSeconds,
40-
value: value
41-
}
38+
store[key] = {
39+
expires: (Date.now() / 1000) + ttlSeconds,
40+
value: value
41+
}
4242
}
4343

4444
/**
@@ -47,16 +47,14 @@ Memory.prototype.set = function (key, value, ttlSeconds = 60 * 24 * 7) {
4747
* @param key
4848
*/
4949
Memory.prototype.delete = function (key) {
50-
delete store[key];
50+
delete store[key]
5151
}
5252

5353
/**
5454
* Clear the cache.
5555
*/
5656
Memory.prototype.clear = function () {
57-
store = {};
57+
store = {}
5858
}
5959

60-
61-
module.exports = Memory;
62-
60+
module.exports = Memory

0 commit comments

Comments
 (0)