From d5a123abf45c54bd2e8b02cbd312322c4602181d Mon Sep 17 00:00:00 2001 From: brantje Date: Sat, 15 Oct 2016 17:05:25 +0200 Subject: [PATCH] Use global namespace for importers --- js/importers/import-main.js | 187 ++++++++++++++------------- js/importers/importer-clipperz.js | 112 ++++++++-------- js/importers/importer-dashlanecsv.js | 93 ++++++------- js/importers/importer-keepasscsv.js | 97 +++++++------- js/importers/importer-lastpasscsv.js | 75 +++++------ js/importers/importer-passmanjson.js | 136 +++++++++---------- js/importers/importer-passpackcsv.js | 101 ++++++++------- js/importers/importer-randomdata.js | 167 ++++++++++++------------ js/importers/importer-zohocsv.js | 75 +++++------ 9 files changed, 527 insertions(+), 516 deletions(-) diff --git a/js/importers/import-main.js b/js/importers/import-main.js index 5f5944bb..6443be49 100644 --- a/js/importers/import-main.js +++ b/js/importers/import-main.js @@ -1,98 +1,99 @@ -// Importers should always start with this -if(!window['PassmanImporter']){ - var PassmanImporter = {} -} +var PassmanImporter = PassmanImporter || {}; +(function(window, $, PassmanImporter) { + 'use strict'; -PassmanImporter.parseRow_ = function(row) { - // Strip leading quote. - row = row.trim(); - var isQuoted = false; - if (row.charAt(0) == '"') { - row = row.substring(1); - isQuoted = true; - } - if (row.charAt(row.length - 2) == '"') { - row = row.substring(0, row.length - 2); - isQuoted = true; - } - // Strip trailing quote. There seems to be a character between the last quote - // and the line ending, hence 2 instead of 1. - if(isQuoted == true) { - row = row.split('","'); - } else { - row = row.split(','); - } - return row; -}; -PassmanImporter.htmlDecode = function(input){ - var e = document.createElement('div'); - e.innerHTML = input; - return e.childNodes[0].nodeValue; -}; -PassmanImporter.toObject_ = function(headings, row) { - var result = {}; - for (var i = 0, ii = row.length; i < ii; i++) { - headings[i] = headings[i].replace(',','_') - .toLowerCase().replace(' ','_') - .replace('(','').replace(')','') - .replace('"',''); - result[headings[i]] = row[i]; - } - return result; -}; -PassmanImporter.join_ = function(arr, sep) { - var parts = []; - for (var i = 0, ii = arr.length; i < ii; i++) { - arr[i] && parts.push(arr[i]); - } - return parts.join(sep); -}; - -PassmanImporter.newCredential = function () { - var credential = { - 'credential_id': null, - 'guid': null, - 'vault_id': null, - 'label': null, - 'description': null, - 'created': null, - 'changed': null, - 'tags': [], - 'email': null, - 'username': null, - 'password': null, - 'url': null, - 'favicon': null, - 'renew_interval': null, - 'expire_time': 0, - 'delete_time': 0, - 'files': [], - 'custom_fields': [], - 'otp': {}, - 'hidden': false + PassmanImporter.parseRow_ = function(row) { + // Strip leading quote. + row = row.trim(); + var isQuoted = false; + if (row.charAt(0) == '"') { + row = row.substring(1); + isQuoted = true; + } + if (row.charAt(row.length - 2) == '"') { + row = row.substring(0, row.length - 2); + isQuoted = true; + } + // Strip trailing quote. There seems to be a character between the last quote + // and the line ending, hence 2 instead of 1. + if(isQuoted == true) { + row = row.split('","'); + } else { + row = row.split(','); + } + return row; }; - return credential; -}; - -PassmanImporter.readCsv = function( csv, hasHeadings ){ - hasHeadings = (hasHeadings === undefined) ? true : hasHeadings; - var lines = []; - var rows = csv.split('\n'); - if(hasHeadings) { - var headings = this.parseRow_(rows[0]); - for (var i = 1, row; row = rows[i]; i++) { - row = this.toObject_(headings, this.parseRow_(row)); - lines.push(row); + PassmanImporter.htmlDecode = function(input){ + var e = document.createElement('div'); + e.innerHTML = input; + return e.childNodes[0].nodeValue; + }; + PassmanImporter.toObject_ = function(headings, row) { + var result = {}; + for (var i = 0, ii = row.length; i < ii; i++) { + headings[i] = headings[i].replace(',','_') + .toLowerCase().replace(' ','_') + .replace('(','').replace(')','') + .replace('"',''); + result[headings[i]] = row[i]; } - } else { - for (var i = 1, row; row = rows[i]; i++) { - lines.push(this.parseRow_(row)); - } - } - return lines; -}; + return result; + }; -PassmanImporter.readJson = function (string){ - return JSON.parse(string); -}; \ No newline at end of file + PassmanImporter.join_ = function(arr, sep) { + var parts = []; + for (var i = 0, ii = arr.length; i < ii; i++) { + arr[i] && parts.push(arr[i]); + } + return parts.join(sep); + }; + + PassmanImporter.newCredential = function () { + var credential = { + 'credential_id': null, + 'guid': null, + 'vault_id': null, + 'label': null, + 'description': null, + 'created': null, + 'changed': null, + 'tags': [], + 'email': null, + 'username': null, + 'password': null, + 'url': null, + 'favicon': null, + 'renew_interval': null, + 'expire_time': 0, + 'delete_time': 0, + 'files': [], + 'custom_fields': [], + 'otp': {}, + 'hidden': false + }; + return credential; + }; + + PassmanImporter.readCsv = function( csv, hasHeadings ){ + hasHeadings = (hasHeadings === undefined) ? true : hasHeadings; + var lines = []; + var rows = csv.split('\n'); + if(hasHeadings) { + var headings = this.parseRow_(rows[0]); + for (var i = 1, row; row = rows[i]; i++) { + row = this.toObject_(headings, this.parseRow_(row)); + lines.push(row); + } + } else { + for (var i = 1, row; row = rows[i]; i++) { + lines.push(this.parseRow_(row)); + } + } + return lines; + }; + + PassmanImporter.readJson = function (string){ + return JSON.parse(string); + }; +})(window, $, PassmanImporter); diff --git a/js/importers/importer-clipperz.js b/js/importers/importer-clipperz.js index e9194bcc..213f969c 100644 --- a/js/importers/importer-clipperz.js +++ b/js/importers/importer-clipperz.js @@ -1,58 +1,58 @@ // Importers should always start with this -if (!window['PassmanImporter']) { - var PassmanImporter = {} -} -// Define the importer -PassmanImporter.clippers = { - info: { - name: 'Clipperz.is', - id: 'clippers', - description: 'Go to menu -> Export -> Download HTML + JSON. Fields will be imported as custom fields.' - } -}; - -PassmanImporter.clippers.readFile = function (file_data) { - return new C_Promise(function() { - var credential_list = []; - var re = /