Gimenz / wattpad.js

Un-Official Wattpad API Wrapper for NodeJS
https://www.npmjs.com/package/wattpad.js
MIT License
6 stars 1 forks source link

any plans to migrate to ts or provide types #1

Open sk337 opened 4 months ago

sk337 commented 4 months ago

if you are willing to I could add types for you

Gimenz commented 3 months ago

yeaa, it's good idea, but i'm sorry i too busy at RL, any time at holiday i'll convert it to ts. also youu can add types, it make more easier to read

sk337 commented 3 months ago

here are the types I made so you can implement them into the program

interface User {
  name: string;
  avatar: string;
  fullName: string;
}

interface Profile {
  username:string;
  avatar:string;
  isPrivate:boolean;
  backgroundUrl:string;
  followerRequest:string;
  followingRequest:string;
  isBlockedbyCurrentUser:boolean;
  name:string;
  description:string;
  genderCode:string;
  language:number;
  createDate:string;
  location:string;
  verified:boolean;
  ambassador:boolean;
  facebook:string;
  twitter:string;
  website:string;
  votesReceved:number;
  numStoriesPublished:number;
  numFollowing:number;
  numFollowers:number;
  numLists:number;
  verified_email:number;
  is_staff:boolean;
  highlight_color:string;
  programs:{ [key:string]:boolean };
  externalId:string;
  showSocialNetwork:boolean;
}

interface Language {
  id: number;
  name: string;
}

interface Part {
  id: number;
  title: string;
  modifyDate: string;
  length: number;
  videoId: string;
  photoUrl: string;
  commentCount: number;
  voteCount: number;
  readCount: number;
  dedication: { [key: string]: string };
  text_url: {
    text: string;
  }
}

interface ViewPart {
  id: number;
  title: string;
  url: string;
  rating: number;
  modifyDate: string;
  photoUrl: string;
  commentCount: number;
  voteCount: number;
  readCount: number;
}

interface Error {
  error_code: number;
  error_typr: string;
  message: string;
  fields: string[];
}

export interface Details {
  id: string;
  title: string;
  length: number;
  createDate: string;
  modifyDate: string;
  voteCount: number;
  readCount: number;
  commentCount: number;
  language: Language;
  user: User;
  description: string;
  cover: string;
  completed: boolean;
  categories: number[];
  tags: string[];
  rating: number;
  copyright: number;
  url: string;
  numParts: number;
  lastPublishedPart: {
    createDate: string;
  };
  parts: Part[];
}

interface Story {
  text: string;
  text_hash: string;
}

declare module "wattpad.js" {
  export default class Wattpad {
    constructor();
    static Stories: {
      detail(id: string | number): Promise<Details | Error>;
      read(id: string | number): Promise<Story | Error>;
    };
    static User: {
      lookup(username: string): Promise<Profile | Error>;
    };
    // Add other methods as needed
  }
}