Skip to content

Commit 4f95c3b

Browse files
author
Patrick Michaelsen
committed
feat: Upgrade to typescript
1 parent c2e8fb4 commit 4f95c3b

File tree

7 files changed

+5825
-15
lines changed

7 files changed

+5825
-15
lines changed

jest.config.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// For a detailed explanation regarding each configuration property, visit:
2+
// https://jestjs.io/docs/en/configuration.html
3+
module.exports = {
4+
clearMocks: true,
5+
resetMocks: true,
6+
restoreMocks: true,
7+
testEnvironment: "node",
8+
// testMatch: [
9+
// "**/**.test.ts"
10+
// ],
11+
transform: {
12+
".(js|ts)": "ts-jest"
13+
},
14+
transformIgnorePatterns: [
15+
"[/\\\\]node_modules[/\\\\].+\\.(js|jsx|ts|tsx|json)$",
16+
"package.json"
17+
],
18+
};
19+
File renamed without changes.

lib/generator.js renamed to lib/generator.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = (function () {
22
var jsomeRef
3-
, browserColors = []
3+
, browserColors: string[] = []
44
, browserStyle = require('./browser-style')
55

66
function getType (value) {
@@ -54,6 +54,7 @@ module.exports = (function () {
5454
for (var key in obj) {
5555
if (isArray(obj[key]) || isObject(obj[key])) return true;
5656
}
57+
return false;
5758
}
5859

5960
function isArray (arr) {
@@ -64,15 +65,15 @@ module.exports = (function () {
6465
return toString.call(obj).match(/^\[object Object\]$/);
6566
}
6667

67-
function colorify (value, level) {
68+
function colorify (value, level = 0) {
6869
var color = jsomeRef.colors[getType(value)];
6970
return generateLevel(level)
7071
+ (getType(value) === 'str' ? colorifySpec('"', 'quot') : '')
7172
+ useColorProvider('' + value, color)
7273
+ (getType(value) === 'str' ? colorifySpec('"', 'quot') : '');
7374
}
7475

75-
function colorifySpec (char, type, level) {
76+
function colorifySpec (char, type, level = 0): string {
7677
var quote = (
7778
jsomeRef.params.lintable && type === 'attr'
7879
? colorifySpec('"', 'quot', 0)
@@ -109,7 +110,7 @@ module.exports = (function () {
109110

110111
return {
111112
gen : function (json, level, isChild) {
112-
var colored = [];
113+
var colored: string[] = [];
113114
level = level || 0;
114115

115116
if (isObject(json)) {
@@ -133,19 +134,19 @@ module.exports = (function () {
133134

134135
if (hasChild(json)) {
135136

136-
var result = json.map(function(item) {
137+
var arr = json.map(function(item) {
137138
return this.gen(item, level+1);
138139
}.bind(this));
139140

140141
colored.push(colorifySpec('[', 'brack', isChild ? 0 : level));;
141-
colored.push(result.join(colorifySpec(', ', 'punc') + '\n' ));
142+
colored.push(arr.join(colorifySpec(', ', 'punc') + '\n' ));
142143
colored.push(colorifySpec(']', 'brack', level));
143144

144145
} else {
145146

146147
var coloredArray = colorifySpec('[', 'brack', isChild ? 0 : level);
147-
for (var key in json) {
148-
coloredArray += colorify(json[key]) + (json.length-1>key ? colorifySpec(', ', 'punc') : '');
148+
for (var i = 0; i < json.length; i++) {
149+
coloredArray += colorify(json[i]) + (json.length - 1 > i ? colorifySpec(', ', 'punc') : '');
149150
}
150151
colored.push(coloredArray + colorifySpec(']', 'brack'));
151152

0 commit comments

Comments
 (0)