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

tc-comment

v1.0.1

Published

A comment component that supports markdowm and emoji, without any configuration, no need to apply for any account, it can be used immediately

Downloads

50

Readme

tc-comment

中文 | Use Case

A comment component that supports markdowm and emoji, without any configuration, no need to apply for any account, it can be used immediately

Features

  1. One line of code introduction without any configuration
  2. No need to apply for any account, just use it
  3. Support markdowm and emoji comment components
  4. Support real-time preview
  5. Support insert link of code message
  6. Support dark mode, adapt to the original dark mode of the website
  7. Support custom services and url
  8. Support for inserting pictures

1. Quick use

import {initComment} from 'tc-comment';
initComment({
    appName: 'xxx', // create your own app name
});

cdn use

<script src="https://cdn.jsdelivr.net/npm/tc-comment/tc-comment.min.js"></script>
<script>
    TComment.initComment({
        appName: 'xxx', // create your own app name
    });
</script>

2. Vue component introduction

// ...
import {Comment} from 'tc-comment';

Comment.init({appName: 'xxx'}); // Create your own app name

export default {
    components: {Comment},
    // ...
}

3. Configuration parameters

initComment({
    appName: string;
    el?: HTMLElement | string; // Comment.init passed this parameter is invalid
    theme?: 'dark' | 'light';
    darkSelector?: string;
    services?: {
        insertComment: InsertComment;
        getComment: GetComment;
        insertReply: InsertReply;
    };
    urlConfig?: {
        host: string;
        get?: string;
        insert?: string;
        reply?: string;
    };
    dataHandler?: {
        get?: (data: IGetOption) => any;
        insert?: (data: IComment) => any;
        reply?: (data: IReply) => any;
    };
})
// Comment.init parameters are consistent with the above parameters
  1. appName: An application name is required, a combination of numbers and letters is recommended, and it supports the use of / to divide directories such as appName = blog/2022/hello
  2. The container rendered by el will append an element to the body by default
  3. theme color
  4. darkSelector Fill in a dark theme color selector, generally used to adapt to the dark theme of the main website
  5. Services, urlConfig, dataHandler will be introduced in detail later

4. Custom services

tc-comment supports custom methods to implement your own request methods

import {initComment} from 'tc-comment';
initComment({
    el: '#app',
    services: { // Please inject three requests by yourself, insert comment, insert reply and get comment
        insertComment(){

        },
        getComment(){

        },
        getComment(){

        }
    }
});

insertComment and getComment ts statement

interface InsertComment {
    (data: {
        name: string;
        contact: string;
        content: string;
    }): Promise<boolean>;
}

interface InsertReply {
    (data: {
        name: string;
        contact: string;
        content: string;
        commentId: number;
    }): Promise<boolean>;
}

interface GetComment {
    (query: {
        index?: number;
        size?: number;
        all?: boolean;
        condition?: object;
    }): Promise<Array<{
        createTime: number;
        name: string;
        content: string;
    }>>;
}

5. Custom interface urlConfig

tc-comment supports custom interface by configuring urlConfig

The urlConfig parameter has lower precedence than the services parameter

import {initComment} from 'tc-comment';
initComment({
    el: '#app',
    urlConfig: {
        host:'www.example.com',
        get:'/api/comment/get',
        insert:'/api/comment/insert',
        reply: '/api/reply/insert'
    },
});

If you use the urlConfig parameter, tc-comment will call the three interfaces under the domain name, please deploy it yourself

  1. get request for pulling comments
  • path: urlConfig.get
  • method: get
  • Parameters: index, size, all, condition, app
  • Return: {data: {code: 0, data: [CommentObject]}} 0 means success
  • responseType: json

CommentObject

{
    id: number;
    name: string;
    contact: string;
    content: string;
    createTime: number; // timestamp
    reply: Array<{
        name: string;
        contact: string;
        content: string;
        createTime: number; // timestamp
    }>;
}
  1. insert request for uploading comments
  • path: urlConfig.insert
  • method: post
  • Parameters: name, contact, content, app
  • Return: {data: {code: 0}} 0 means success
  • responseType: json
  1. The reply request is used to upload the reply
  • path: urlConfig.insert
  • method: post
  • Parameters: name, contact, content, commentId, app
  • Return: {data: {code: 0}} 0 means success
  • responseType: json

6. dataHandler

When using a custom urlConfig, you can modify the request data with dataHandle

Use as follows

import {initComment} from 'tc-comment';
initComment({
    el: '#app',
    urlConfig: {
        host:'www.example.com',
        get:'/api/comment/get',
        insert:'/api/comment/insert',
        reply: '/api/reply/insert'
    },
    
    dataHandler: {
        get: (data) => {return data},
        insert: (data) => {return data},
        reply: (data) => {return data},
    }
});