-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[WIP] Improved barcode options #171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
abf817e
300a46c
c939f38
94adfcd
8fd488d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ class ErrorHandler{ | |
| handleCatch(e){ | ||
| // If babel supported extending of Error in a correct way instanceof would be used here | ||
| if(e.name === "InvalidInputException"){ | ||
| if(this.api._options.valid !== this.api._defaults.valid){ | ||
| if(typeof this.api._options.valid !== 'undefined'){ | ||
| this.api._options.valid(false); | ||
| } | ||
| else{ | ||
|
|
@@ -25,7 +25,9 @@ class ErrorHandler{ | |
| wrapBarcodeCall(func){ | ||
| try{ | ||
| var result = func(...arguments); | ||
| this.api._options.valid(true); | ||
| if (typeof this.api._options.valid !== 'undefined') { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, you can do it in old specs as I see (http://www.ecma-international.org/ecma-262/5.1/#sec-15.1.1.3). But for a public library your way is better :) |
||
| this.api._options.valid(true); | ||
| } | ||
| return result; | ||
| } | ||
| catch(e){ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| export default applyOptions; | ||
|
|
||
| function applyOptions(optionsBlueprint, options) { | ||
| var returnOptions = {}; | ||
| for (var name in optionsBlueprint) { | ||
| if (optionsBlueprint.hasOwnProperty(name)) { | ||
| if (typeof options[name] !== 'undefined') { | ||
| returnOptions[name] = convertOption(options[name], optionsBlueprint[name].type); | ||
| } | ||
| else { | ||
| returnOptions[name] = optionsBlueprint[name].default; | ||
| } | ||
| } | ||
| } | ||
| return returnOptions; | ||
| } | ||
|
|
||
| // Convert an option to a specified type | ||
| function convertOption(data, type) { | ||
| if (type === 'string') { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe check type before: if (typeof data !== type) {
// do conversions
}
return data;
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For example |
||
| return '' + data; | ||
| } | ||
| else if (type === 'number') { | ||
| return parseInt(data, 10); | ||
| } | ||
| else if (type === 'boolean') { | ||
| return (typeof data === 'boolean' && data) || data === 'true' || data === 'True'; | ||
| } | ||
| else { | ||
| return data; | ||
| } | ||
| } | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,84 @@ | ||
| var defaults = { | ||
| width: 2, | ||
| height: 100, | ||
| format: "auto", | ||
| displayValue: true, | ||
| fontOptions: "", | ||
| font: "monospace", | ||
| text: undefined, | ||
| textAlign: "center", | ||
| textPosition: "bottom", | ||
| textMargin: 2, | ||
| fontSize: 20, | ||
| background: "#ffffff", | ||
| lineColor: "#000000", | ||
| margin: 10, | ||
| marginTop: undefined, | ||
| marginBottom: undefined, | ||
| marginLeft: undefined, | ||
| marginRight: undefined, | ||
| valid: function(){} | ||
| width: { | ||
| type: "number", | ||
| default: 2, | ||
| }, | ||
| height: { | ||
| type: "number", | ||
| default: 100, | ||
| }, | ||
| format: { | ||
| type: "string", | ||
| default: "auto", | ||
| }, | ||
| displayValue: { | ||
| type: "boolean", | ||
| default: true, | ||
| }, | ||
| fontOptions: { | ||
| type: "string", | ||
| default: "", | ||
| }, | ||
| font: { | ||
| type: "string", | ||
| default: "monospace", | ||
| }, | ||
| text: { | ||
| type: "string", | ||
| default: undefined, | ||
| }, | ||
| textAlign: { | ||
| type: "string", | ||
| default: "center", | ||
| }, | ||
| textPosition: { | ||
| type: "string", | ||
| default: "bottom", | ||
| }, | ||
| textMargin: { | ||
| type: "number", | ||
| default: 2, | ||
| }, | ||
| fontSize: { | ||
| type: "number", | ||
| default: 20, | ||
| }, | ||
| background: { | ||
| type: "string", | ||
| default: "#ffffff", | ||
| }, | ||
| lineColor: { | ||
| type: "string", | ||
| default: "#000000", | ||
| }, | ||
| margin: { | ||
| type: "number", | ||
| default: 10, | ||
| }, | ||
| marginTop: { | ||
| type: "number", | ||
| default: undefined, | ||
| }, | ||
| marginBottom: { | ||
| type: "number", | ||
| default: undefined, | ||
| }, | ||
| marginLeft: { | ||
| type: "number", | ||
| default: undefined, | ||
| }, | ||
| marginRight: { | ||
| type: "number", | ||
| default: undefined, | ||
| }, | ||
| valid: { | ||
| type: "function", | ||
| default: undefined, | ||
| }, | ||
| xmlDocument: { | ||
| type: "function", | ||
| default: undefined, | ||
| } | ||
| }; | ||
|
|
||
| export default defaults; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you think to make it as a property, but not as a function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about it. The main reason why I wanted to make this a function is that it will make inheritance of options easier. If for all CODE128 codes have one option but we want to add additional options to that sub-symbology it can easily be done like follow.