Conditions | 1 |
Paths | 1 |
Total Lines | 56 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | // Importers should always start with this |
||
3 | (function(window, $, PassmanImporter) { |
||
4 | 'use strict'; |
||
5 | PassmanImporter.clippers = { |
||
6 | info: { |
||
7 | name: 'Clipperz.is', |
||
8 | id: 'clippers', |
||
9 | description: 'Go to menu -> Export -> Download HTML + JSON. Fields will be imported as custom fields.' |
||
10 | } |
||
11 | }; |
||
12 | |||
13 | PassmanImporter.clippers.readFile = function (file_data) { |
||
14 | return new C_Promise(function() { |
||
15 | var credential_list = []; |
||
16 | var re = /<textarea>(.*?)<\/textarea>/gi; |
||
17 | var matches = re.exec(file_data); |
||
18 | if(matches){ |
||
19 | var raw_json = matches[0].substring(10); |
||
20 | raw_json = PassmanImporter.htmlDecode(raw_json.slice(0, -11)); |
||
21 | var json_objects = PassmanImporter.readJson(raw_json); |
||
22 | for(var i = 0; i < json_objects.length; i++){ |
||
23 | var card = json_objects[i]; |
||
24 | re = /(\w+)/gi; |
||
25 | var tags = card.label.match(re); |
||
26 | card.label = card.label.replace(tags.join(' '), '').trim(); |
||
27 | tags = tags.map(function(item){ return {text: item.replace('', '') }}); |
||
28 | |||
29 | |||
30 | var _credential = PassmanImporter.newCredential(); |
||
31 | _credential.label = card.label; |
||
32 | _credential.description = card.data.notes; |
||
33 | _credential.tags = tags; |
||
34 | for(var field in card.currentVersion.fields){ |
||
35 | var field_data = card.currentVersion.fields[field]; |
||
36 | _credential.custom_fields.push( |
||
37 | { |
||
38 | 'label': field_data.label, |
||
39 | 'value': field_data.value, |
||
40 | 'secret': (field_data.hidden == true) |
||
41 | } |
||
42 | ) |
||
43 | } |
||
44 | if(_credential.label){ |
||
45 | credential_list.push(_credential); |
||
46 | } |
||
47 | var progress = { |
||
48 | percent: i/json_objects.length*100, |
||
49 | loaded: i, |
||
50 | total: json_objects.length |
||
51 | }; |
||
52 | this.call_progress(progress); |
||
53 | } |
||
54 | } |
||
55 | this.call_then(credential_list); |
||
56 | }); |
||
57 | }; |
||
58 | })(window, $, PassmanImporter); |
||
59 |