Skip to content

Commit

Permalink
Code analysis and optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonsturges committed Apr 6, 2019
1 parent 0410d5e commit 49a7641
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 24 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ Example:

```js
const fs = require("fs");
const anf = require("apple-news-compiler")
const anf = require("apple-news-compiler");

const run = async () => {
var article = JSON.parse(fs.readFileSync("article.json"), 'utf8');
const article = JSON.parse(fs.readFileSync("article.json"), 'utf8');

anf.article.inline(article);

console.log(JSON.stringify(article, null, 2));
}
};

run();
```
Expand Down Expand Up @@ -68,15 +68,15 @@ Example:

```js
const fs = require("fs");
const anf = require("apple-news-compiler")
const anf = require("apple-news-compiler");

const run = async () => {
var article = JSON.parse(fs.readFileSync("article.json"), 'utf8');
const article = JSON.parse(fs.readFileSync("article.json"), 'utf8');

anf.article.removeUnusedReferences(article);

console.log(JSON.stringify(article, null, 2));
}
};

run();
```
Expand All @@ -92,15 +92,15 @@ Example:

```js
const fs = require("fs");
const anf = require("apple-news-compiler")
const anf = require("apple-news-compiler");

const run = async () => {
var article = JSON.parse(fs.readFileSync("article.json"), 'utf8');
const article = JSON.parse(fs.readFileSync("article.json"), 'utf8');

anf.article.removeEmptyDefinitions(article);

console.log(JSON.stringify(article, null, 2));
}
};

run();
```
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

'use strict';

const article = require("./lib/article")
const article = require("./lib/article");

module.exports = {
article
Expand Down
20 changes: 10 additions & 10 deletions lib/article.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const removeComments = (article) => {
traverser(article, child);
});
}
}
};

article.components.forEach(component => {
traverser(article, component)
Expand All @@ -112,7 +112,7 @@ const removeComments = (article) => {
Object.keys(textStyles).forEach(textStyle => {
removeComment(textStyles[textStyle]);
});
}
};


/**
Expand All @@ -131,21 +131,21 @@ const removeEmptyDefinitions = (article) => {
if (util.isString(component["layout"]))
if (componentLayouts.hasOwnProperty(component["layout"]))
if (Object.keys(componentLayouts[component["layout"]]).length === 0)
delete component["layout"]
delete component["layout"];

// Component styles
if (component.hasOwnProperty("style"))
if (util.isString(component["style"]))
if (componentStyles.hasOwnProperty(component["style"]))
if (Object.keys(componentStyles[component["style"]]).length === 0)
delete component["style"]
delete component["style"];

// Component text styles
if (component.hasOwnProperty("textStyle"))
if (util.isString(component["textStyle"]))
if (componentTextStyles.hasOwnProperty(component["textStyle"]))
if (Object.keys(componentTextStyles[component["textStyle"]]).length === 0)
delete component["textStyle"]
delete component["textStyle"];

// Conditionals
if (component.hasOwnProperty("conditional"))
Expand All @@ -155,14 +155,14 @@ const removeEmptyDefinitions = (article) => {
if (util.isString(condition["layout"]))
if (componentLayouts.hasOwnProperty(condition["layout"]))
if (Object.keys(componentLayouts[condition["layout"]]).length === 0)
delete condition["layout"]
delete condition["layout"];

// Component styles - conditional
if (condition.hasOwnProperty("style"))
if (util.isString(condition["style"]))
if (componentStyles.hasOwnProperty(condition["style"]))
if (Object.keys(componentStyles[condition["style"]]).length === 0)
delete condition["style"]
delete condition["style"];

// Component text styles - conditional
if (condition.hasOwnProperty("textStyle"))
Expand Down Expand Up @@ -197,7 +197,7 @@ const removeEmptyDefinitions = (article) => {
if (Object.keys(componentTextStyles[textStyle]).length === 0)
delete componentTextStyles[textStyle];
});
}
};


/**
Expand Down Expand Up @@ -283,7 +283,7 @@ const removeUnusedReferences = (article) => {
if (!textStyles.includes(textStyle))
delete componentTextStyles[textStyle];
});
}
};


/**
Expand All @@ -297,7 +297,7 @@ const removeComment = (object) => {

if (object.hasOwnProperty("comment"))
delete object["comment"];
}
};


module.exports = {
Expand Down
5 changes: 1 addition & 4 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
'use strict';

const isString = (property) => {
if (typeof property === 'string' || property instanceof String)
return true;

return false;
return typeof property === 'string' || property instanceof String;
};

module.exports = {
Expand Down

0 comments on commit 49a7641

Please sign in to comment.