npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

web-share-wrapper

v0.2.2

Published

A web component that wraps other share elements to replace with a web share button where supported.

Downloads

1,216

Readme

<web-share-wrapper>

Published on webcomponents.org

A custom element that can be used to wrap existing share buttons and replace them with a button that invokes the Web Share API.

For example, in supporting browsers the following HTML will show a plain <button> saying "Share". In browsers that don't support the Web Share API, the default link to share on Twitter will be displayed.

<web-share-wrapper>
  <a href="https://twitter.com/intent/tweet?text=Share+Text&amp;url=SHARE_URL">Share on Twitter</a>
</web-share-wrapper>

How to use

The <web-share-wrapper> is a web component that you can use to enhance your website with the Web Share API. If the API is available, the component will replace its contents with a single share button or a template that you provide.

The component only activates if the Web Share API is available, otherwise it will just show it's contents.

Browser support

Currently the only browser that supports the Web Share API (Chrome on Android) also supports custom elements and templates. So this module works where it will work and will fallback to your original HTML where it doesn't.

Installation

Bower

You can install the component with bower.

bower install --save web-share-wrapper

npm

You can also install with npm.

npm install web-share-wrapper

Once installed, you can either use the minified version by referencing it from the dist directory.

<script src="./node_modules/web-share-wrapper/dist/web-share-wrapper.min.js"></script>

Or if you have a build step, you can require the module.

const WebShareWrapper = require('web-share-wrapper');

unpkg

If you want to use the component from the unpkg CDN then you can.

You can get the latest version using the bare URL. See more options on https://unpkg.com/.

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

Example

<web-share-wrapper>
  <a href="https://twitter.com/intent/tweet?text=Share+Text&amp;url=SHARE_URL">Share on Twitter</a>
</web-share-wrapper>

If navigator.share is available, the contents of the <web-share-wrapper> will be replaced with a single <button> element, which when clicked will invoke the Web Share API.

Check out this page with more examples.

Attributes

You can set attributes to control the text on the share button and the text and URL that is shared. The available attributes are:

  • text: Sets the text on the share button.
  • template: An id for a <template> element. The component will find the template, hydrate it and add it as the child of the component. This overrides the text attribute.
  • sharetitle: Sets the title to be shared.
  • sharetext: Sets the text to be shared. Falls back to the text contents of the <title> element.
  • shareurl: Sets the URL to be shared. Fallsback to the href of the canonical link, failing that window.location.href.
<web-share-wrapper text="Share this" sharetitle="This amazing thing was shared" sharetext="You should really click on the link to learn more" shareurl="http://example.com/amazing">
  <a href="https://twitter.com/intent/tweet?text=Share+Text&amp;url=SHARE_URL">Share on Twitter</a>
</web-share-wrapper>

Check out this page with more examples.

Events

The <web-share-wrapper> emits one of two events in response to the result of using navigator.share.

If the share is successful then a share-success event is fired. The share title, text and URL are emitted in the event's details (though the user may have edited them in the share target).

If the share is unsuccessful then a share-failure event is fired. The share title, text, URL and the error that was thrown are emitted in the event's details.

Tests

[TODO]

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/philnash/web-share-wrapper. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The code is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the <web-share-wrapper> project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.