Skip to content

A minimal client-side library to convert your vanilla URLs to deep links.

License

Notifications You must be signed in to change notification settings

amoraroma/Deeplink

 
 

Repository files navigation






A simple library to convert your links to deep links.

Version License

Twitter Follow

Key featuresInstallationPre-requisitesCreating deep linksRelated


Deeplink promotional graphic


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
    • Twitter
    • Instagram
    • Facebook
    • Reddit
    • 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

Pre-requisites

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");

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:https://${this.appUrl}/${this.pathname}#Intent;package=${this.appPackage};scheme=https;end`;
    }

    getiOSLink(): string {
        return this.originalUrl;
    }
}

DeepLinkGenerator.mappings.push(new RedditLinkApp());

Singlelink is Neutron Creative product, created and hosted free of charge in the mission of open-source. To learn more about our mission, visit neutroncreative.com

Be sure to check out our other products as well!

About

A minimal client-side library to convert your vanilla URLs to deep links.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

 
 
 

Languages

  • TypeScript 100.0%