phonegap-nfc
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -0,1 +1,4 @@ | ||
= 1.0.3 = | ||
Remove ES6 code from phonegap-nfc.js #325 | ||
= 1.0.2 = | ||
@@ -2,0 +5,0 @@ Add reader mode for Android #326 #198 |
{ | ||
"name": "phonegap-nfc", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Near Field Communication (NFC) Plugin. Read and write NDEF messages to NFC tags and share NDEF messages with peers.", | ||
@@ -5,0 +5,0 @@ "cordova": { |
@@ -1111,3 +1111,3 @@ PhoneGap NFC Plugin | ||
cordova plugin add ../phonegap-nfc/tests | ||
cordova plugin add http://git-wip-us.apache.org/repos/asf/cordova-plugin-test-framework.git | ||
cordova plugin add https://github.com/apache/cordova-plugin-test-framework.git | ||
@@ -1114,0 +1114,0 @@ Change the start page in `config.xml` |
@@ -12,2 +12,12 @@ exports.defineAutoTests = function () { | ||
}); | ||
it("should contain a readerMode function", function () { | ||
expect(typeof nfc.readerMode).toBeDefined(); | ||
expect(typeof nfc.readerMode).toBe("function"); | ||
}); | ||
it("should contain a transceive function", function () { | ||
expect(typeof nfc.transceive).toBeDefined(); | ||
expect(typeof nfc.transceive).toBe("function"); | ||
}); | ||
}); | ||
@@ -69,4 +79,55 @@ | ||
}); | ||
}); | ||
describe('Translate ArrayBuffer and HEX Strings', function() { | ||
it('should convert array buffer to hex string', function() { | ||
var source = new Uint8Array([0x00, 0x01, 0x02, 0xFD, 0xFE, 0xFF]).buffer; | ||
var hexString = util.arrayBufferToHexString(source); | ||
expect(hexString).toEqual('000102fdfeff'); | ||
}); | ||
it('should convert hex string to array buffer', function() { | ||
var hexString = '000102FDFEFF' | ||
var buffer = util.hexStringToArrayBuffer(hexString); | ||
expect(new Uint8Array(buffer)).toEqual(new Uint8Array([0x00, 0x01, 0x02, 0xFD, 0xFE, 0xFF])); | ||
// leading 0 | ||
var buffer = util.hexStringToArrayBuffer('0x68656c6c6f2c20776f726c64'); | ||
expect(new Uint8Array(buffer)).toEqual(new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64])); | ||
// space delimiter | ||
var buffer = util.hexStringToArrayBuffer('68 65 6c 6c 6f 2c 20 77 6f 72 6c 64'); | ||
expect(new Uint8Array(buffer)).toEqual(new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64])); | ||
// : delimiter | ||
var buffer = util.hexStringToArrayBuffer('68:65:6c:6c:6f:2c:20:77:6f:72:6c:64'); | ||
expect(new Uint8Array(buffer)).toEqual(new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64])); | ||
// - delimiter | ||
var buffer = util.hexStringToArrayBuffer('68-65-6c-6c-6f-2c-20-77-6f-72-6c-64'); | ||
expect(new Uint8Array(buffer)).toEqual(new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64])); | ||
}); | ||
}); | ||
describe('nfc.transceive', function() { | ||
it('should reject invalid input', function(done) { | ||
var promise = nfc.transceive(42); | ||
promise.then( | ||
function resolve() { | ||
throw new Error('Promise should not be resolved'); | ||
}, | ||
function reject(reason) { | ||
expect(reason).toBe("Expecting an ArrayBuffer or String"); | ||
done(); | ||
} | ||
) | ||
}); | ||
}); | ||
}; | ||
@@ -73,0 +134,0 @@ |
@@ -516,3 +516,3 @@ /*jshint bitwise: false, camelcase: false, quotmark: false, unused: vars, esversion: 6, browser: true*/ | ||
let buffer; | ||
var buffer; | ||
if (typeof data === 'string') { | ||
@@ -707,5 +707,6 @@ buffer = util.hexStringToArrayBuffer(data); | ||
} | ||
const typedArray = new Uint8Array(buffer); | ||
var typedArray = new Uint8Array(buffer); | ||
var array = Array.from(typedArray); // need to convert to [] so our map result is not typed | ||
const parts = array.map(i => toHexString(i)); | ||
var parts = array.map(function(i) { return toHexString(i) }); | ||
return parts.join(''); | ||
@@ -734,3 +735,3 @@ }, | ||
// check for some non-hex characters | ||
const bad = hexString.match(/[G-Z\s]/i); | ||
var bad = hexString.match(/[G-Z\s]/i); | ||
if (bad) { | ||
@@ -741,6 +742,6 @@ console.log('WARNING: found non-hex characters', bad); | ||
// split the string into pairs of octets | ||
const pairs = hexString.match(/[\dA-F]{2}/gi); | ||
var pairs = hexString.match(/[\dA-F]{2}/gi); | ||
// convert the octets to integers | ||
const ints = pairs.map(s => parseInt(s, 16)); | ||
var ints = pairs.map(function(s) { return parseInt(s, 16) }); | ||
@@ -747,0 +748,0 @@ var array = new Uint8Array(ints); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
414739
28
1250