1.0.6 • Published 4 years ago
nc-deeplink v1.0.6
deeplink
Key Features
- Convert links into deep links
- Pass a user agent to correctly determine which link to provide
- Automatically fallback to default URL if a type can't be determined
- Support for many platforms
- TikTok
- SnapChat
- YouTube
- ...and more coming soon!
- 100% free and open-source
Installation
npm
npm i nc-deeplink
yarn
yarn add nc-deeplink
Compiling
# install dependencies
npm install
# (optional) install typescript globally
npm install typescript -g
# build the library (automatically copies important files and compiles typescript)
npm run build
Documentation
Prerequisites
DeepLink uses user agents to determine a valid destination for a link.
You can grab this user agent any way you need to.
Import
import {DeepLinker} from "nc-deeplink";
// or
const Index = require("nc-deeplink");
Creating Deep Links
Parse a Deep Link
import {DeepLinker} from "nc-deeplink";
let userAgent = navigator.userAgent;
let deepLink = DeepLinker.parseDeepLink(url, userAgent);
console.log(deepLink);
Create an OS specific Deep Link (no user agent needed)
import {DeepLinker} from "nc-deeplink";
let deepLink = DeepLinker.convertToDeepLink(url, "Android");
console.log(deepLink);
deepLink = DeepLinker.convertToDeepLink(url, "iOS");
console.log(deepLink);
Check if a user agent is mobile
import {DeepLinker} from "nc-deeplink";
let userAgent = navigator.userAgent;
let isMobile = DeepLinker.isMobile(url, userAgent);
console.log(isMobile)
Deep Link Mapping with Link Apps
Link Apps are how DeepLink figures out how to convert a link into a deep link.
DeepLink provides a number of mappings by default, but if you wish to add more, you may do so.
Add a mapping
import {DeepLinkGenerator} from "nc-deeplink";
import {LinkApp} from "nc-deeplink";
class RedditLinkApp extends LinkApp {
constructor(url?: string) {
super(url, "reddit.com", undefined, "com.reddit.frontpage");
}
getAndroidLink(): string {
return `intent://${this.appUrl}/${this.pathname}#Intent;package=${this.appPackage};scheme=https;end`;
}
getiOSLink(): string {
return this.originalUrl;
}
}
DeepLinkGenerator.mappings.push(new RedditLinkApp());
Check These Out
Our contribution guidelines 🚀 to see how you can contribute to this project!
Our Discord 💬 if you just want to chat with us! 😃