Git Product home page Git Product logo

share-url's Introduction

share-url

NPM Version Minzipped size License Known Vulnerabilities Libraries.io dependency status for latest release Total alerts Language grade: JavaScript

Generates social sharing urls without downloading its third party scripts. Adaptable to any UI.

Supported: Facebook, Twitter, Telegram, Whatsapp, Pinterest, Reddit, Linkedin, e-mail.

Demo

https://noeldelgado.github.io/share-url/

Dependencies

None

Installation

NPM

npm i share-url --save

Or as a <script> tag from a CDN as ShareUrl:

Unkpkg CDN

<script src="https://unpkg.com/share-url"></script>

jsDelivr CDN

<script src="https://cdn.jsdelivr.net/npm/share-url"></script>

Usage Example

// jsx
<a href={ShareUrl.facebook({ u: 'https://google.com' })}>
  Share on Facebook
</a>
// js
document.querySelector('a').href = ShareUrl.facebook({ u: 'https://google.com' });

facebook

Source https://www.facebook.com/sharer.php?u={url}

ShareUrl.facebook({
  u: 'http://google.com',
});
// => 'https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fgoogle.com'

whatsapp

Source https://api.whatsapp.com/send?text={text}

ShareUrl.whatsapp({
  text: 'Check out http://google.com',
});
// => 'https://api.whatsapp.com/send?text=Check%20out%20https%3A%2F%2Fgoogle.com'

telegram

Source https://t.me/share/url?url={url}&text={text}

ShareUrl.telegram({
  url: 'https://google.com',
  text: 'Check out',
});
// => https://t.me/share/url?url=https%3A%2F%2Fgoogle.com&text=Check%20out

twitter

Source https://twitter.com/share?text={text}&url={url}

ShareUrl.twitter({
  text: 'custom share text',
  in_reply_to: '471716611724812288',
  url: 'https://dev.twitter.com/web/tweet-button',
  hashtags: 'example,demo',
  via: 'twitterdev',
  related: 'twitterapi,twitter',
});
// => 'https://twitter.com/share?text=custom%20share%20text&in_reply_to=471716611724812288&url=https%3A%2F%2Fdev.twitter.com%2Fweb%2Ftweet-button&hashtags=example%2Cdemo&via=twitterdev&related=twitterapi%2Ctwitter'

pinterest

Source https://pinterest.com/pin/create/button/?url={url}

ShareUrl.pinterest({
  url: 'http://www.flickr.com/photos/kentbrew/6851755809/',
  media: 'http://farm8.staticflickr.com/7027/6851755809_df5b2051c9_z.jpg',
  description: 'Next Stop Pinterest',
});
// => 'https://pinterest.com/pin/create/button/?url=http%3A%2F%2Fwww.flickr.com%2Fphotos%2Fkentbrew%2F6851755809%2F&media=http%3A%2F%2Ffarm8.staticflickr.com%2F7027%2F6851755809_df5b2051c9_z.jpg&description=Next%20Stop%20Pinterest'

reddit

Source http://www.reddit.com/submit?url={url}

ShareUrl.reddit({
  url: '//www.reddit.com/buttons',
  title: 'Buttons!',
});
// => 'http://www.reddit.com/submit?url=%2F%2Fwww.reddit.com%2Fbuttons&title=Buttons!'

linkedin

Source https://linkedin.com/sharing/share-offsite/?url={url}

ShareUrl.linkedin({
  url: 'http://developer.linkedin.com',
});
// => 'https://linkedin.com/sharing/share-offsite/?url=http%3A%2F%2Fdeveloper.linkedin.com'

email

Source mailto:{to}?subject={subject}&body={body}

ShareUrl.email({
  to: '[email protected]',
  cc: '[email protected]',
  subject: 'This is the subject',
  body: 'This is the body - https://developer.mozilla.org/',
});
// => 'mailto:[email protected]?cc=nobody%40mozilla.org&subject=This%20is%20the%20subject&body=This%20is%20the%20body%20-%20https%3A%2F%2Fdeveloper.mozilla.org%2F'

License

MIT © Noel Delgado

share-url's People

Contributors

noeldelgado avatar yek-plus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

share-url's Issues

Add types for TypeScript

Opening a task to track TypeScript types support.

  wagmify.app git:(main)  npm i --save-dev @types/share-url
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@types%2fshare-url - Not found
npm ERR! 404
npm ERR! 404  '@types/share-url@*' is not in this registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/zkhalapyan/.npm/_logs/2022-02-11T01_40_51_808Z-debug-0.log

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.