Skip to content

Commit

Permalink
Add standard style.
Browse files Browse the repository at this point in the history
  • Loading branch information
aarondfrancis committed Aug 23, 2021
1 parent def64af commit e29afab
Show file tree
Hide file tree
Showing 18 changed files with 2,649 additions and 849 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/env node
const {makeProgram} = require('./src/cli');
const { makeProgram } = require('./src/cli')

makeProgram().parse();
makeProgram().parse()
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = {
// ],

// Indicates which provider should be used to instrument code for coverage
coverageProvider: "v8",
coverageProvider: 'v8'

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

// Whether to use watchman for file crawling
// watchman: true,
};
}
2,064 changes: 1,935 additions & 129 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "A CLI for Torchlight - the syntax highlighting API",
"main": "index.js",
"scripts": {
"test": "jest"
"test": "standard && jest"
},
"bin": {
"torchlight": "index.js"
Expand All @@ -24,9 +24,12 @@
"commander": "^8.1.0",
"fs-extra": "^10.0.0",
"inquirer": "^8.1.2",
"jest": "^27.0.6",
"lodash.chunk": "^4.2.0",
"lodash.get": "^4.4.2",
"md5": "^2.3.0"
},
"devDependencies": {
"jest": "^27.0.6",
"standard": "^16.0.3"
}
}
100 changes: 50 additions & 50 deletions src/block.js
Original file line number Diff line number Diff line change
@@ -1,78 +1,78 @@
const md5 = require('md5');
const guid = require('./support/guid');
const torchlight = require('./torchlight');

let Block = function (opts = {}) {
opts = {
id: guid(),
theme: torchlight.config('theme', 'nord'),
...opts,
}

this.id = opts.id;
this.code = opts.code;
this.language = opts.language;
this.theme = opts.theme;

this.highlighted = null;
this.classes = null;
this.styles = null;
const md5 = require('md5')
const guid = require('./support/guid')
const torchlight = require('./torchlight')

const Block = function (opts = {}) {
opts = {
id: guid(),
theme: torchlight.config('theme', 'nord'),
...opts
}

this.id = opts.id
this.code = opts.code
this.language = opts.language
this.theme = opts.theme

this.highlighted = null
this.classes = null
this.styles = null
}

Block.prototype.hash = function () {
return md5(''
+ this.language
+ this.theme
+ this.code
+ torchlight.config('bust', 0)
+ JSON.stringify(torchlight.config('options'))
)
return md5('' +
this.language +
this.theme +
this.code +
torchlight.config('bust', 0) +
JSON.stringify(torchlight.config('options'))
)
}

Block.prototype.code = function (code) {
this.code = code;
this.code = code

return this;
return this
}

Block.prototype.language = function (language) {
this.language = language;
this.language = language

return this;
return this
}

Block.prototype.theme = function (theme) {
this.theme = theme;
this.theme = theme

return this;
return this
}

Block.prototype.placeholder = function (extra = '') {
if (extra) {
extra = `-${extra}`;
}
if (extra) {
extra = `-${extra}`
}

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

Block.prototype.setResponseData = function (data) {
if (data) {
this.highlighted = data.highlighted;
this.classes = data.classes;
this.styles = data.styles;
}
if (data) {
this.highlighted = data.highlighted
this.classes = data.classes
this.styles = data.styles
}

return this;
return this
}

Block.prototype.toRequestParams = function () {
return {
id: this.id,
hash: this.hash,
language: this.language,
theme: this.theme,
code: this.code,
}
return {
id: this.id,
hash: this.hash,
language: this.language,
theme: this.theme,
code: this.code
}
}

module.exports = Block;
module.exports = Block
60 changes: 30 additions & 30 deletions src/cache/file.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
const md5 = require('md5');
const path = require('path');
const md5 = require('md5')
const path = require('path')
const {
readJsonSync,
writeJsonSync,
ensureDirSync,
pathExistsSync,
removeSync
readJsonSync,
writeJsonSync,
ensureDirSync,
pathExistsSync,
removeSync
} = require('fs-extra')

/**
* @param options
* @constructor
*/
let File = function (options = {}) {
if (!options.directory) {
throw new Error('No cache directory specified.');
}
const File = function (options = {}) {
if (!options.directory) {
throw new Error('No cache directory specified.')
}

this.directory = path.resolve(options.directory)
this.directory = path.resolve(options.directory)

ensureDirSync(this.directory);
ensureDirSync(this.directory)
}

/**
Expand All @@ -30,19 +30,19 @@ let File = function (options = {}) {
* @return {*}
*/
File.prototype.get = function (key, def) {
if (!pathExistsSync(this.filename(key))) {
return def;
}
if (!pathExistsSync(this.filename(key))) {
return def
}

let entry = readJsonSync(this.filename(key));
const entry = readJsonSync(this.filename(key))

if (Date.now() / 1000 > entry.expires) {
this.delete(key);
if (Date.now() / 1000 > entry.expires) {
this.delete(key)

return def;
}
return def
}

return entry.value;
return entry.value
}

/**
Expand All @@ -53,10 +53,10 @@ File.prototype.get = function (key, def) {
* @param {number} ttlSeconds
*/
File.prototype.set = function (key, value, ttlSeconds = 60 * 24 * 7) {
writeJsonSync(this.filename(key), {
expires: (Date.now() / 1000) + ttlSeconds,
value: value
});
writeJsonSync(this.filename(key), {
expires: (Date.now() / 1000) + ttlSeconds,
value: value
})
}

/**
Expand All @@ -65,22 +65,22 @@ File.prototype.set = function (key, value, ttlSeconds = 60 * 24 * 7) {
* @param key
*/
File.prototype.delete = function (key) {
removeSync(this.filename(key));
removeSync(this.filename(key))
}

/**
* Clear the cache.
*/
File.prototype.clear = function () {
removeSync(this.directory);
removeSync(this.directory)
}

/**
* @param {string} key
* @return {string}
*/
File.prototype.filename = function (key) {
return path.join(this.directory, md5(key) + '.json');
return path.join(this.directory, md5(key) + '.json')
}

module.exports = File;
module.exports = File
40 changes: 19 additions & 21 deletions src/cache/memory.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
let store = {};
let store = {}

let Memory = function () {
//
const Memory = function () {
//
}

/**
Expand All @@ -12,19 +12,19 @@ let Memory = function () {
* @return {*}
*/
Memory.prototype.get = function (key, def) {
if (!store.hasOwnProperty(key)) {
return def;
}
if (!Object.prototype.hasOwnProperty.call(store, key)) {
return def
}

let entry = store[key];
const entry = store[key]

if (Date.now() / 1000 > entry.expires) {
this.delete(key);
if (Date.now() / 1000 > entry.expires) {
this.delete(key)

return def;
}
return def
}

return entry.value;
return entry.value
}

/**
Expand All @@ -35,10 +35,10 @@ Memory.prototype.get = function (key, def) {
* @param {number} ttlSeconds
*/
Memory.prototype.set = function (key, value, ttlSeconds = 60 * 24 * 7) {
store[key] = {
expires: (Date.now() / 1000) + ttlSeconds,
value: value
}
store[key] = {
expires: (Date.now() / 1000) + ttlSeconds,
value: value
}
}

/**
Expand All @@ -47,16 +47,14 @@ Memory.prototype.set = function (key, value, ttlSeconds = 60 * 24 * 7) {
* @param key
*/
Memory.prototype.delete = function (key) {
delete store[key];
delete store[key]
}

/**
* Clear the cache.
*/
Memory.prototype.clear = function () {
store = {};
store = {}
}


module.exports = Memory;

module.exports = Memory
Loading

0 comments on commit e29afab

Please sign in to comment.