Giter Site home page Giter Site logo

masskoder / deeplink Goto Github PK

View Code? Open in Web Editor NEW

This project forked from neutron-creative/deeplink

0.0 0.0 0.0 1.03 MB

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

Home Page: https://npmjs.org/package/nc-deeplink

License: GNU Lesser General Public License v2.1

TypeScript 100.00%

deeplink's Introduction






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://${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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.