Version 1.41.3 of nativescript-toolbox released with Markdown and vibration support

The plugin now supports Markdown and device vibration.

Sub modules

Functions

fromMarkdown()

import Toolbox = require('nativescript-toolbox');
import { MarkdownDialect, TargetFormat } from 'nativescript-toolbox';
 
// s. markdownToJson()
var json1 = Toolbox.fromMarkdown("Hello.\n\n* This is markdown.\n* It is fun");
var json2 = Toolbox.fromMarkdown("Vessel     | Captain\n-----------|-------------\nNCC-1701   | James T Kirk\nNCC-1701 A | James T Kirk\nNCC-1701 D | Picard",
                                 null, MarkdownDialect.Maruku);
 
// s. markdownToHtml()
var html1 = Toolbox.fromMarkdown("Hello.\n\n* This is markdown.\n* It is fun");
var html2 = Toolbox.fromMarkdown("Vessel     | Captain\n-----------|-------------\nNCC-1701   | James T Kirk\nNCC-1701 A | James T Kirk\nNCC-1701 D | Picard",
                                 TargetFormat.Html, MarkdownDialect.Maruku);

invokeForConnectivity()

Invokes logic for a specific connectivity type.

import Toolbox = require('nativescript-toolbox');
 
Toolbox.invokeForConnectivity({
    mobile: () => {
        console.log('Now is connected via mobile');
    },
    none: () => {
        console.log('Currently NOT connected.');
    },
    wifi: () => {
        console.log('Now is connected via WiFi');
    },
    unknown: (result) => {
        console.log('UNKNOWN connection type: ' + result.type);
        console.log('Code: ' + result.code);
        console.log('Error: ' + result.error);
    }
});

markdownToJson()

Short hand for ‘fromMarkdown()’ with JSON as target format.

import Toolbox = require('nativescript-toolbox');
import { MarkdownDialect } from 'nativescript-toolbox';
 
// Gruber syntax
// 
// [
//     "markdown",
//     [
//         "para",
//         "Hello."
//     ],
//     [
//         "bulletlist",
//         [
//             "listitem",
//             "This is markdown."
//         ],
//         [
//             "listitem",
//             "It is fun"
//         ]
//     ]
// ]
var json1 = Toolbox.markdownToJson("Hello.\n\n* This is markdown.\n* It is fun");
 
// Maruku syntax
// 
// [
//     "markdown",
//     [
//         "table",
//         [
//             "thead",
//             [
//                 "tr",
//                 [
//                     "th",
//                     {},
//                     "Vessel"
//                 ],
//                 [
//                     "th",
//                     {},
//                     "Captain"
//                 ]
//             ]
//         ],
//         [
//             "tbody",
//             [
//                 "tr",
//                 [
//                     "td",
//                     {},
//                     "NCC-1701"
//                 ],
//                 [
//                     "td",
//                     {},
//                     "James T Kirk"
//                 ]
//             ],
//             [
//                 "tr",
//                 [
//                     "td",
//                     {},
//                     "NCC-1701 A"
//                 ],
//                 [
//                     "td",
//                     {},
//                     "James T Kirk"
//                 ]
//             ],
//             [
//                 "tr",
//                 [
//                     "td",
//                     {},
//                     "NCC-1701 D"
//                 ],
//                 [
//                     "td",
//                     {},
//                     "Picard"
//                 ]
//             ]
//         ]
//     ]
// ]
var json2 = Toolbox.markdownToJson("Vessel     | Captain\n-----------|-------------\nNCC-1701   | James T Kirk\nNCC-1701 A | James T Kirk\nNCC-1701 D | Picard",
                                   MarkdownDialect.Maruku);

markdownToHtml()

Short hand for ‘fromMarkdown()’ with HTML as target format.

import Toolbox = require('nativescript-toolbox');
import { MarkdownDialect } from 'nativescript-toolbox';
 
// Gruber syntax
// 
// "<p>Hello.</p>
//
// <ul><li>This is markdown.</li><li>It is fun</li></ul>"
var html1 = Toolbox.markdownToHtml("Hello.\n\n* This is markdown.\n* It is fun");
 
// Maruku syntax
// 
// "<table><thead><tr><th>Vessel</th><th>Captain</th></tr></thead><tbody><tr><td>NCC-1701</td><td>James T Kirk</td></tr><tr><td>NCC-1701 A</td><td>James T Kirk</td></tr><tr><td>NCC-1701 D</td><td>Picard</td></tr></tbody></table>"
var html2 = Toolbox.markdownToHtml("Vessel     | Captain\n-----------|-------------\nNCC-1701   | James T Kirk\nNCC-1701 A | James T Kirk\nNCC-1701 D | Picard",
                                   MarkdownDialect.Maruku);

openWifiSettings()

Opens the WiFi settings on the device.

import Toolbox = require('nativescript-toolbox');
 
if (Toolbox.openWifiSettings()) {
    console.log('WiFi settings opened.');
}
else {
    console.log('WiFi settings NOT opened.');
}

startMonitoringForConnectivity()

Starts monitoring for connectivity (changes). Requires permission on Android, e.g. (s. android.permission.ACCESS_NETWORK_STATE)

import Toolbox = require('nativescript-toolbox');
 
Toolbox.startMonitoringForConnectivity({
    mobile: () => {
        console.log('Now is connected via mobile');
    },
    none: () => {
        console.log('Currently NOT connected.');
    },
    wifi: () => {
        console.log('Now is connected via WiFi');
    },
    unknown: (result) => {
        console.log('UNKNOWN connection type: ' + result.type);
        console.log('Code: ' + result.code);
        console.log('Error: ' + result.error);
    }
});

stopMonitoringForConnectivity()

Stops monitoring for connectivity. Requires permission on Android, e.g. (s. android.permission.ACCESS_NETWORK_STATE)

vibrate()

Vibrates the device.

Requires permissions on Android (android.permission.VIBRATE), e.g.

The code is based on nativescript-vibrate by Anarchic Knight.

import Toolbox = require('nativescript-toolbox');
 
// vibrate for 500 milliseconds
Toolbox.vibrate();
 
// vibrate for 1 second
Toolbox.vibrate(1000);

NOTE: The argument that defines the milliseconds to vibrate has NO effect on iOS.

Leave a Reply

Your email address will not be published. Required fields are marked *