Socket
Socket
Sign inDemoInstall

@taptrack/ndef

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @taptrack/ndef

Ndef message parser and composer


Version published
Weekly downloads
7
decreased by-53.33%
Maintainers
1
Install size
91.1 kB
Created
Weekly downloads
 

Readme

Source

Library for creating and parsing NDEF messages

Installing

Bower

    bower install ndef

NPM

    npm install @taptrack/ndef

Creating Records

Text records

    var ndef = require('@taptrack/ndef');
    // language code is optional, defaults to 'en'
    var textRecord = ndef.Utils.createTextRecord("sirop","fr"); 
    var message = new ndef.Message([textRecord]);

    // Uint8Array for storing, writing to a tag, etc.
    var bytes = message.toByteArray(); 

Uri records

    // NDEF uri prefixes will be automatically applied
    var textRecord = ndef.Utils.createUriRecord("http://www.google.com"); 
    var message = new ndef.Message([textRecord]);

    // Uint8Array for storing, writing to a tag, etc.
    var bytes = message.toByteArray(); 

Custom records

    // creating message to be carried inside smartposter record
    var uri = ndef.Utils.createUriRecord("http://www.google.com");
    var payloadMsg = new ndef.Message([uri]);

    var chunked = false; // non-chunked record
    var tnf = new Uint8Array([0x01]); // TNF well known
    var type = new Uint8Array([0x53,0x70]);
    var payload = payloadMessage.toByteArray();

    var spRecord = new ndef.Record(chunked,tnf,type,id,payload);
    var spMessage = new ndef.Message([record]);

    // Uint8Array for storing, writing to a tag, etc.
    var bytes = spMessage.toByteArray();

Parsing messages

Text records

    var message = ndef.Message.fromBytes(byteArray);
    var records = message.getRecords();

    var recordContents = ndef.Utils.resolveTextRecord(parsedRecords[0]);
    console.log("Language: "+recordContents.language);
    console.log("Content: "+recordContents.content);

URI records

    var message = ndef.Message.fromBytes(byteArray);
    var records = message.getRecords();

    var uri = ndef.Utils.resolveUriRecordToString(parsedRecords[0]);
    console.log("URI: "+uri);

Other records

    // takes a Uint8Array containing a valid, complete message
    var message = ndef.Message.fromBytes(byteArray);

    // array of all the records
    var records = message.getRecords();
    
    for(var i = 0; i < records.length; i++) {
        var record = records[i];
        console.log("Chunked: "+(record.isChunked?"Yes":"No");
        console.log("TNF: "+record.getTnf().toString());
        console.log("Type: "+record.getTnf().toString());
        console.log("ID: "+record.getId().toString());
        console.log("Payload: "+record.getTnf().toString());
    }

FAQs

Last updated on 09 Feb 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc