Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Upgrade to typescript #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// For a detailed explanation regarding each configuration property, visit:
// https://jestjs.io/docs/en/configuration.html
module.exports = {
clearMocks: true,
resetMocks: true,
restoreMocks: true,
testEnvironment: "node",
transform: {
".(js|ts)": "ts-jest"
},
transformIgnorePatterns: [
"[/\\\\]node_modules[/\\\\].+\\.(js|jsx|ts|tsx|json)$",
"package.json"
],
};

File renamed without changes.
17 changes: 9 additions & 8 deletions lib/generator.js → lib/generator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = (function () {
var jsomeRef
, browserColors = []
, browserColors: string[] = []
, browserStyle = require('./browser-style')

function getType (value) {
Expand Down Expand Up @@ -54,6 +54,7 @@ module.exports = (function () {
for (var key in obj) {
if (isArray(obj[key]) || isObject(obj[key])) return true;
}
return false;
}

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

function colorify (value, level) {
function colorify (value, level = 0) {
var color = jsomeRef.colors[getType(value)];
return generateLevel(level)
+ (getType(value) === 'str' ? colorifySpec('"', 'quot') : '')
+ useColorProvider('' + value, color)
+ (getType(value) === 'str' ? colorifySpec('"', 'quot') : '');
}

function colorifySpec (char, type, level) {
function colorifySpec (char, type, level = 0): string {
var quote = (
jsomeRef.params.lintable && type === 'attr'
? colorifySpec('"', 'quot', 0)
Expand Down Expand Up @@ -109,7 +110,7 @@ module.exports = (function () {

return {
gen : function (json, level, isChild) {
var colored = [];
var colored: string[] = [];
level = level || 0;

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

if (hasChild(json)) {

var result = json.map(function(item) {
var arr = json.map(function(item) {
return this.gen(item, level+1);
}.bind(this));

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

} else {

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

Expand Down
Loading