Skip to content

Commit

Permalink
Add es6 import/export for utils
Browse files Browse the repository at this point in the history
  • Loading branch information
eKoopmans committed Nov 19, 2017
1 parent 5c8ef3a commit 761150e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
* SOFTWARE.
*/

import { objType, createElement, cloneNode, unitConvert } from './utils.js';

/**
* Generate a PDF from an HTML element or string using html2canvas and jsPDF.
*
Expand Down
8 changes: 4 additions & 4 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Determine the type of a variable/object.
var objType = function(obj) {
export const objType = function(obj) {
if (typeof obj === 'undefined') return 'undefined';
else if (typeof obj === 'string' || obj instanceof String) return 'string';
else if (typeof obj === 'number' || obj instanceof Number) return 'number';
Expand All @@ -10,7 +10,7 @@ var objType = function(obj) {
};

// Create an HTML element with optional className, innerHTML, and style.
var createElement = function(tagName, opt) {
export const createElement = function(tagName, opt) {
var el = document.createElement(tagName);
if (opt.className) el.className = opt.className;
if (opt.innerHTML) {
Expand All @@ -27,7 +27,7 @@ var createElement = function(tagName, opt) {
};

// Deep-clone a node and preserve contents/properties.
var cloneNode = function(node, javascriptEnabled) {
export const cloneNode = function(node, javascriptEnabled) {
// Recursively clone the node.
var clone = node.nodeType === 3 ? document.createTextNode(node.nodeValue) : node.cloneNode(false);
for (var child = node.firstChild; child; child = child.nextSibling) {
Expand Down Expand Up @@ -58,7 +58,7 @@ var cloneNode = function(node, javascriptEnabled) {
}

// Convert units using the conversion value 'k' from jsPDF.
var unitConvert = function(obj, k) {
export const unitConvert = function(obj, k) {
var newObj = {};
for (var key in obj) {
newObj[key] = obj[key] * 72 / 96 / k;
Expand Down

0 comments on commit 761150e

Please sign in to comment.