Giter Club home page Giter Club logo

chatdb.js's Introduction

ChatDB.js

NPM version built with typescript

A library that parses the chat.db file on Macs into a comprehensive data structure using ES6 promises.

Installation

$ npm install chatdb.js

Getting Started

// Import the package
const { Chat } = require('chatdb.js');

(async function () {
    // Create new instance of Chat 
    // and initialize it asynchronously
    const chat = await new Chat('/path/to/chat.db').init();

    // ... Do the thing
}())

Examples

Simple Message Logger

const { Chat } = require('chatdb.js');
const fs = require('fs');

(async function() {
    const chat = await new Chat().init(); // Initialize Client
    const lastId = 0;
    // Declare loop
    async function loop() {
        const msg = (await chat.getMessages(1, true))[0]; // Get the most recent message

        if(msg.id != lastId) { // Check if the most recent message id changed
            lastId = msg.id;
            console.log(`${msg.isFromMe ? "Me" : msg.handle.name}: ${msg.text}`); // Format and log the message
        }
    }

    setInterval(loop, 1000); // Start loop
}());

Common Problems

W.I.P.

Documentation

Constructors

Properties

Methods

Constructors

constructor

+ new Chat(path?: string): Chat

Defined in app.ts:12

Parameters:

Name Type
path? string

Returns: Chat

Properties

db

db: DatabaseSqlite‹Database, Statement›

Defined in app.ts:11


json

json: Conversation[]

Defined in app.ts:12


path

path: string

Defined in app.ts:10

Methods

close

close(): Promise‹void›

Defined in app.ts:224

Returns: Promise‹void›


Private dbDateToDate

dbDateToDate(nano: number): Date

Defined in app.ts:228

Parameters:

Name Type
nano number

Returns: Date


getConversationCount

getConversationCount(): Promise‹any›

Defined in app.ts:212

Returns: Promise‹any›


getConversations

getConversations(max?: number, reverse?: boolean): Promise‹Conversation[]›

Defined in app.ts:130

Parameters:

Name Type
max? number
reverse? boolean

Returns: Promise‹Conversation[]›


getHandleCount

getHandleCount(): Promise‹any›

Defined in app.ts:216

Returns: Promise‹any›


getHandles

getHandles(max?: number, reverse?: boolean): Promise‹Handle[]›

Defined in app.ts:109

Parameters:

Name Type
max? number
reverse? boolean

Returns: Promise‹Handle[]›


getMessageCount

getMessageCount(): Promise‹any›

Defined in app.ts:220

Returns: Promise‹any›


getMessages

getMessages(max?: number, reverse?: boolean): Promise‹Message[]›

Defined in app.ts:151

Parameters:

Name Type
max? number
reverse? boolean

Returns: Promise‹Message[]›


init

init(): Promise‹Chat

Defined in app.ts:19

Returns: Promise‹Chat


parse

parse(): Promise‹Conversation[]›

Defined in app.ts:28

Returns: Promise‹Conversation[]›

chatdb.js's People

Contributors

zaedus avatar

Stargazers

Michael Jett avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.