Socket
Socket
Sign inDemoInstall

apple-news-compiler

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    apple-news-compiler

Apple News format compiler for optimized JSON article


Version published
Weekly downloads
3
decreased by-66.67%
Maintainers
1
Install size
14.9 kB
Created
Weekly downloads
 

Readme

Source

Apple News Compiler

Apple News format compiler for optimized JSON article

Inline

Replace all named component layouts, styles, and text styles by inlining object definitions within the article's components array.

Example:

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

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

  anf.article.inline(article);

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

run();

Original article.json:

{
  "role": "title",
  "text": "Title on Scrim",
  "layout": "titleLayout",
  "textStyle": "titleStyle"
}

Inline will replace named references of titleLayout and titleStyle with object definitions:

{
  "role": "title",
  "text": "Title on Scrim",
  "layout": {
    "columnStart": 0,
    "columnSpan": 7,
    "margin": {
      "top": 50,
      "bottom": 5
    }
  },
  "textStyle": {
    "textAlignment": "center",
    "fontName": "HelveticaNeue-Bold",
    "fontSize": 42,
    "lineHeight": 50,
    "textColor": "#EFEFEF"
  }
}

Remove Unused References

Purge any unused references to layouts, styles, or text styles not referenced by name within the components array.

This optimization removes lengthy templated style definitions that may be stubbed into an article boilerplate, leaving only definitions that are actually used. Note this does not purge empty object definitions - use removeEmptyDefinitions().

Example:

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

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

  anf.article.removeUnusedReferences(article);

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

run();

Remove Empty Definitions

Purge any empty definitions within layouts, styles, or text styles as well as their named reference within the components array.

This optimization removes lengthy templated style definitions that may be stubbed into an article boilerplate.

Example:

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

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

  anf.article.removeEmptyDefinitions(article);

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

run();

Original article.json

"components": [
  {
    "role": "title",
    "text": "Title on Scrim",
    "layout": "titleLayout",
    "textStyle": "titleStyle"
  }
],
"componentTextStyles": {
  "titleStyle": {
  }
}

In the example above, titleStyle is empty - no style was defined in the object. Therefore, the resulting optimization would remove the component's "textStyle": "titleStyle" as well as the empty titleStyle from componentTextStyles:

"components": [
  {
    "role": "title",
    "text": "Title on Scrim",
    "layout": "titleLayout"
  }
],
"componentTextStyles": {}

Remove Comments

Purge any comments from components, layouts, styles, or text styles that use either the following conventions:

{
  "//": "Comment example"
}

Or:

{
  "comment": "Comment example"
}

FAQs

Last updated on 06 Apr 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc