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

@tawasal/vue

v0.0.3

Published

tawasal sdk for vue development

Downloads

13

Readme

npm npm Bundle Size Bundle Size

This library provides a set of vue hooks to integrate with the Tawasal SuperApp API, allowing you to interact with various functionalities such as fetching user data, handling clipboard operations, scanning QR codes, and more.

Tawasal Vue SDK

The Tawasal Vue SDK provides hooks for integrating Tawasal SuperApp functionalities into your Vue.js application. These hooks allow you to access various features like user information, contact selection, clipboard reading, haptic feedback, and more.

Installation

Install the SDK using npm or yarn:

npm install @tawasal/vue

or

yarn add @tawasal/vue

Usage

Below are examples of how to use the different hooks provided by the Tawasal Vue SDK.

1. useTawasal

This hook fetches the current user's information, photo, and user link.

Example:

<template>
  <div>
    <div v-if="isLoading">Loading...</div>
    <div v-if="error">Error: {{ error.message }}</div>
    <div v-if="user">
      <h2>User Info</h2>
      <p>Name: {{ user.name }}</p>
      <p>ID: {{ user.id }}</p>
    </div>
    <div v-if="avatar">
      <img :src="avatar" alt="User Photo" />
    </div>
    <div v-if="userLink">
      <p>User Link: {{ userLink }}</p>
    </div>
  </div>
</template>

<script setup>
import { useTawasal } from '@tawasal/vue';

const { user, avatar, userLink, error, isLoading } = useTawasal();
</script>

2. useContacts

This hook allows you to select contacts and fetch their details.

Example:

<template>
  <div>
    <button @click="triggerSelect('Select a contact')">Select Contacts</button>
    <div v-if="isLoading">Loading...</div>
    <div v-if="error">Error: {{ error.message }}</div>
    <ul v-if="contacts">
      <li v-for="contact in contacts" :key="contact.userId">
        {{ contact.name }} - <img v-if="contact.photoUrl" :src="contact.photoUrl" alt="Avatar" />
      </li>
    </ul>
  </div>
</template>

<script setup>
import { useContacts } from '@tawasal/vue';

const { contacts, isLoading, error, triggerSelect } = useContacts();
</script>

3. useClipboard

This hook reads the content of the clipboard.

Example:

<template>
  <div>
    <button @click="updateClipboard">Read Clipboard</button>
    <div v-if="isLoading">Loading...</div>
    <div v-if="error">Error: {{ error.message }}</div>
    <div v-if="clipboard">Clipboard Content: {{ clipboard }}</div>
  </div>
</template>

<script setup>
import { useClipboard } from '@tawasal/vue';

const { clipboard, isLoading, error, updateClipboard } = useClipboard();
</script>

4. usePhoneNumber

This hook prompts the user to share their phone number for a specified reason.

Example:

<template>
  <div>
    <button @click="triggerPhonePrompt('Please share your phone number')">Get Phone Number</button>
    <div v-if="isLoading">Loading...</div>
    <div v-if="error">Error: {{ error.message }}</div>
    <div v-if="phone">Phone Number: {{ phone }}</div>
  </div>
</template>

<script setup>
import { usePhoneNumber } from '@tawasal/vue';

const { phone, isLoading, error, triggerPhonePrompt } = usePhoneNumber();
</script>

5. useQR

This hook shows a QR code scanner and retrieves the scanned code.

Example:

<template>
  <div>
    <button @click="triggerScan">Scan QR Code</button>
    <button @click="closeScan">Close QR Scanner</button>
    <div v-if="isLoading">Loading...</div>
    <div v-if="error">Error: {{ error.message }}</div>
    <div v-if="qr">Scanned QR Code: {{ qr }}</div>
  </div>
</template>

<script setup>
import { useQR } from '@tawasal/vue';

const { qr, isLoading, error, triggerScan, closeScan } = useQR();
</script>

6. useTawasalSDK

This hook provides access to general Tawasal SuperApp functionalities like haptic feedback, opening URLs, closing the app, and sharing content.

Example:

<template>
  <div>
    <button @click="haptic">Haptic Feedback</button>
    <button @click="closeApp">Close App</button>
    <button @click="shareContent">Share Content</button>
  </div>
</template>

<script setup>
import { useTawasalSDK } from '@tawasal/vue';

const { haptic, open, closeApp, share } = useTawasalSDK();

function shareContent() {
  share({
    text: 'Check this out!',
    url: 'https://example.com',
  });
}
</script>

API Reference

useTawasal

Fetches the current user's information, photo, and user link.

  • user: The user's contact information.
  • avatar: The user's photo in base64 format.
  • userLink: A link to the user's profile.
  • error: Any error that occurred during the fetch.
  • isLoading: A boolean indicating whether the data is currently being loaded.

useContacts

Allows you to select contacts and fetch their details.

  • contacts: An array of selected contacts with extended information.
  • isLoading: A boolean indicating whether the data is currently being loaded.
  • error: Any error that occurred during the fetch.
  • triggerSelect(title: string): Triggers the contact selection with the specified title.

useClipboard

Reads the content of the clipboard.

  • clipboard: The content of the clipboard.
  • isLoading: A boolean indicating whether the data is currently being loaded.
  • error: Any error that occurred during the fetch.
  • updateClipboard(): Updates the clipboard content.

usePhoneNumber

Prompts the user to share their phone number for a specified reason.

  • phone: The user's phone number.
  • isLoading: A boolean indicating whether the data is currently being loaded.
  • error: Any error that occurred during the fetch.
  • triggerPhonePrompt(title: string): Prompts the user to share their phone number with the specified title.

useQR

Shows a QR code scanner and retrieves the scanned code.

  • qr: The scanned QR code.
  • isLoading: A boolean indicating whether the data is currently being loaded.
  • error: Any error that occurred during the fetch.
  • triggerScan(): Triggers the QR code scanner.
  • closeScan(): Closes the QR code scanner.

useTawasalSDK

Provides access to general Tawasal SuperApp functionalities.

  • haptic(): Triggers haptic feedback.
  • open(url: string): Opens the specified URL.
  • closeApp(): Closes the app.
  • share({ text: string, url: string, imgUrl?: string, isCustomIos?: boolean }): Shares the specified content.

License

Distributed under the MIT License. See LICENSE for more information.