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-sharing

v1.0.6

Published

Web Content Sharing JavaScript Package for the Web.

Downloads

54

Readme

web-sharing

npm npm npm

Documentation

About web-sharing

The web-sharing package is an easy way to share the content you want on the web.

There is an inconvenience that the Web Share API provides sharing functionality but does not support devices that need to be handled separately.

By automating those parts, this package makes it easier to implement sharing.

Requirements

  1. This package is only available on the Web. It is not dependent on JavaScript libraries such as React and Vue.

  2. App sharing is only available with the Https protocol. (For the http protocol, shared content is copied to the clipboard.)


Getting started

npm install web-sharing

Usage

Simple Code

import shareWebPage, { TypeOfSharing } from "web-sharing"

const APP_NAME = "My Web App"
const HOMEPAGE_URL = "https://google.com"
const onFail = () => alert("The share failed.")

const onSuccess = (typeofSharing: TypeOfSharing) => {
  if (typeofSharing.APP) {
    alert("Shared successfully.")
  } else {
    // The browser does not support sharing.
    alert("Web address copied successfully.")
  }
}

const ShareButton: React.FC = () => {
  return (
    <div>
      <button
        onClick={() =>
          shareWebPage(
            {
              title: APP_NAME,
              url: HOMEPAGE_URL,
              copyValue: `Welcome! ${HOMEPAGE_URL}`
            },
            onSuccess,
            onFail
          )
        }>
        Share Button
      </button>
    </div>
  )
}

export default ShareButton

shareWebPage

The main function that is the entry point of the program. Required parameters are as follows.

The main function that is the entry point of the program. Among the parameters, the options and requirements are as follows.

const shareWebPage = (
  share: Share,
  onSuccess?: (typeOfSharing: TypeOfSharing) => any,
  onFail?: (e: Error) => any
) => {
  ...
}
  • share: [isRequired] tpye of Share
  • onSuccess: [optional] Callback called after success
  • onFail: [optional] Callback called after failure

share

The interfaces of the required parameters are as follows.

interface Share {
  title: string
  url: string
  text?: string
  copyValue?: string
}
  • title: [isRequired]
  • url: [isRequired]
  • text: [optional]
  • copyValue: [optional] Text to copy to clipboard if sharing is not supported (url will be copied by default)

onSuccess

The callback that is called after the share is successful. The TypeOfSharing variable can be used to process separately depending on the type of share.

Example.

import { TypeOfSharing } from "web-sharing"

const onSuccessShare = (typeofSharing: TypeOfSharing) => {
  if (typeofSharing.APP) {
    alert("Shared successfully.")
  } else if (typeofSharing.COPY) {
    // The browser does not support sharing.
    alert("Web address copied successfully.")
  } else {
    alert("Etc...")
  }
}

onFail

The callback that is called after the share is failse. The WebSharingError class is responsible for errors that can be expected in the package. You can import this class and process it separately.

import { WebSharingError } from "web-sharing"

const onFail = (e) => {
  if(e instanceof WebSharingError) {
    ...
  }
}

Preview

preview

Contributing to web-sharing

I am working hard to develop this package with affection. I check all the requests and issues. I'm not a JavaScript developer. There are many parts of this package that are lacking.

This package needs your help.

Please write about the code and if you have a better code, please revise it and contribute.

Please upload the idea or bug for package function development on the issue.

I like all discussions related to development because I am in a learning position.

If you have any further questions or need to contact me, please email [email protected].

Thank you for using my package and for your interest.

"Buy Me A Coffee"