ta-js-toolbox v1.1.0
JS Toolbox
Simple functions for everyday use.
Installation
npm install ta-js-toolbox --save
yarn add ta-js-toolbox
Available Functions
parseHostname()
Parses the hostname (window.location.hostname
or your own supplied string)
and returns an object with the hostname (kinda redundant), the simple domain
and the media name.
import {parseHostname} from 'ta-js-toolbox';
let parsedHost = parseHostname();
/* Returns on http://interaktiv.tagesanzeiger.ch/2016/example-project
{
projectDomain: interaktiv.tagesanzeiger.ch,
publicationDomain: tagesanzeiger.ch,
publicationName: tagesanzeiger
}
*/
Used to find the correct API endpoint or to find the correct logo for the masthead.
shareActionFactory[provider]()
Generate action URLs for Twitter and Facebook that allow the sharing of content.
import {shareActionFactory} from 'ta-js-toolbox';
let twitterUrl = shareActionFactory['twitter'](
{
url: 'http://interaktiv.tagesanzeiger.ch/2017/grossartiges-werk',
via: 'tagesanzeiger',
title: 'Schaut euch diese grossartige Grafik an!',
hashtags: ['TAGrafik', 'awesome']
});
let facebookUrl = shareActionFactory['facebook'](
{
url: 'http://interaktiv.tagesanzeiger.ch/2017/grossartiges-werk',
facebook_id: 123, // Facebook App ID, doesn't work without it.
hashtags: ['TAGrafik'] // Also as an array, but will only use the first item.
});
Contributing
This project hosts small functions that are repeatedly used, but don't warrant their own project. See the first function – parsing the host name, which is repeatedly used in order to be able to provide tracking, logos, etc. to different publications.
Each new script should go into a new file within src
, and export it's main
function. The index.js
then re-exports all these functions for easy
reference. See D3 modules that work in a similar way.