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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@sygnas/jp-social-share

v2.2.0

Published

日本向けのソーシャルシェアボタンのリンクを作成

Readme

syg-jp-social-share

日本向けのソーシャルシェアボタンのリンクを作成。

Description

日本の主要なソーシャルサービスのシェアボタンを作成。画像など装飾は一切ないので、自分のオリジナルボタンを作りたい方向け。

※主要かどうかは作者の主観です。

Release

  • 2021.11.27
    • ブラウザ版削除
  • 2021.11.23
    • TypeScriptで作り直し
    • class形式にしたので呼び出し方法が変更になった
    • 任意のサービスの追加機能は無くした
    • Google+を除外
  • 2019.10.17
    • API、openShareWindow()を追加

対応サービス

  • Twitter
  • Facebook
  • LINE
  • Feedly
  • Pocket
  • はてなブックマーク

Usage

DEMO

Install

npm install --save @sygnas/jp-social-share

html

<a href="#" class="js-social-share"
    data-share-service="twitter"
    data-share-account="sygnas"
    data-share-follow="sygnas"
    data-share-url="http://google.com/"
    data-share-msg="Hello world."
>
  Twitter
</a>

<!-- data-share-url、data-share-msg が設定されていない場合
そのページのURL、タイトルが使われる -->
<a href="#" class="js-social-share"
    data-share-service="facebook">
  Facebook
</a>

<button class="js-test">スクリプトから開く</button>

Script:静的なボタンから

import socialShare from '@sygnas/jp-social-share';

// HTML上に設置しているリンクから開くパターン
socialShare.setShareButton('.js-social-share');

Script:動的に開く1

Vueなどで動的に生成されるボタンから使いたいときは下記のようにする。

<template>
...
<a href="#" @click.prevent="share"
            data-share-service="twitter"
            data-share-account="sygnas"
            data-share-follow="anime_shingeki"
            data-share-url="http://google.com/"
            data-share-msg="Hello world."
            >Twitter</a>
...
</template>

<script>
import socialShare from '@sygnas/jp-social-share';

export default {
  methods: {
    share(e) {
      socialShare.openShareWindowWithElement(e.target);
    }
  },
}

Script:動的に開く2

ボタンなど用意せずに動的に開きたいパターン。

<button class="js-test">シェアする</button>
import socialShare from '@sygnas/jp-social-share';

const btn = document.querySelector('.js-test');

btn.addEventListener('click', (ev) => {
  socialShare.openShareWindow(socialShare.SERVICES.TWITTER, 'https://google.com', 'メッセージ');
});

Data attributes

| data属性 | 初期値 | 説明 | | --- | --- | --- | | data-share-service | | ソーシャルサービス名(twitter / facebook / line / feedly / pocket / hatebu | | data-share-url | location.href | シェアしたいURL | | data-share-msg | document.title | メッセージ | | data-share-account | | Twitter専用 / Replyに入れるアカウント | | data-share-follow | | Twitter専用 / ツイート後にフォローを促すアカウント |

Methods

setShareButton

ボタンクリックでシェアウィンドウを開くよう設定。

static setShareButton(target: string, option: TOption = {}): void

| 引数 | 説明 | | ---- | ---- | | target | 対象ボタンのclassなど | | option | ウィンドウサイズ、シェア実行URLの設定 |

const options = {
    window: {
        width: 500,
        height: 450
    },
    service: {
      facebook: 'http://www.facebook.com/share.php?u={{URL}}',
    },
}
socialShare.setShareButton('.js-social-share', options);

Option

| 項目 | 説明 | | ---- | ---- | | window | window.open() で使用するパラメータのオブジェクト | | services | 各サービスのシェア用テンプレート / twitter / facebook / line / feedly / pocket / hatebu |

Default

const defaults = {
  window: {
    width: 550,
    height: 450,
    personalbar: 0,
    toolbar: 0,
    scrollbars: 1,
    resizable: 1,
  },
  // シェア用URLのテンプレート
  services: {
    twitter:
      'http://twitter.com/share?url={{URL}}&text={{MESSAGE}}&via={{ACCOUNT}}&related={{FOLLOW}}',
    facebook: 'http://www.facebook.com/share.php?u={{URL}}',
    line: 'line://msg/text/{{MESSAGE}} {{URL}}',
    feedly: 'http://feedly.com/i/subscription/feed/{{URL}}',
    pocket: 'http://getpocket.com/edit?url={{URL}}',
    hatebu: '//b.hatena.ne.jp/add?mode=confirm&url={{URL}}&title={{MESSAGE}}',
  },
};

openShareWindowWithElement

エレメントから情報を取得してシェアウィンドウを開く。

static openShareWindowWithElement(elm: HTMLElement): void

openShareWindow

パラメータを指定してシェアウィンドウを開く。

static openShareWindow(
  service: TService,
  url: string = '',
  message: string = '',
  account: string = '',
  follow: string = ''
): void

| 引数 | 説明 | | ---- | ---- | | service | ソーシャルサービス識別子 | | url | シェアURL | | message | メッセージ本文 | | account | ツイートに付けるRepleyアカウント | | follow | ツイート後に表示するフォロー候補アカウント |

License

MIT