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

line-chat-parser

v2.1.0

Published

Parser module for exported LINE chats

Downloads

11

Readme

line-chat-parser

Build Status Test Coverage Maintainability

JavaScript parser module for exported LINE chats.

Note: LINE is a trademark of LINE Corporation. This project is neither affiliated with nor endorsed by LINE Corporation.

Purpose

LINE on desktop and mobile allows you to export/save chats. The formats are a bit different depending on system and locale, but it looks roughly like this:

2017.09.03 Sunday
16:23 Bob Today I found something:
Apparently there is a Node package for parsing chats now!
16:25 Alice Whaaat
16:25 Bob Yeah, it's called line-chat-parser.
16:26 Bob Here's a screenshot:
16:27 Bob Photos
16:30 Alice Looks awesome!

This package can parse these exports into message objects:

[ { date: '2017-09-03T14:23:00.000Z',
    author: 'Bob',
    text: 'Today I found something:\nApparently there is a Node package for parsing chats now!' },
  { date: '2017-09-03T14:25:00.000Z',
    author: 'Alice',
    text: 'Whaaat' },
  { date: '2017-09-03T14:25:00.000Z',
    author: 'Bob',
    text: 'Yeah, it\'s called line-chat-parser.' },
  { date: '2017-09-03T14:26:00.000Z',
    author: 'Bob',
    text: 'Here\'s a screenshot:' },
  { date: '2017-09-03T14:27:00.000Z', author: 'Bob', text: 'Photos' },
  { date: '2017-09-03T14:30:00.000Z',
    author: 'Alice',
    text: 'Looks awesome!' } ]

Note: The date properties above are native Date objects. They are just represented here as strings because there are no date literals in JavaScript.

Installation

This package is available on NPM:

npm i line-chat-parser

Usage

Note: user name array

Exports from the Windows .exe (not the Store app) are formatted with single spaces. This makes it impossible to correctly detect user names without a list of participating users.

Exports from the mobile app separate the names from the message bodies with tab characters. There, you can do without the user list.

What you need ultimately comes down to what kind of export you want to process.

There are two ways to use the parser. Note that both require an array of participating users so that the message authors can be deduced correctly.

Asynchronous parsing ('message' event)

The asynchronous method should be used with huge amounts of messages or when not all lines are known yet -- it emits a message event every time a message is complete.

const LineChatParser = require('line-chat-parser')

// as stated above, you can leave out the user name array when processing
// mobile app exports
let parser = new LineChatParser(['Alice', 'Bob'])
parser.on('message', function (msg) {
  console.log(msg)
})

parser.process('2017.09.03 Sunday')
parser.process('16:23 Bob Today I found something:')
parser.process('Apparently there is a Node package for parsing chats now!')
// now the message is done and the event is emitted
parser.process('16:25 Alice Whaaat')
// ...
// IMPORTANT - always call flush - it emits the final message
parser.flush()

Synchronous parsing (static 'parse' function)

Use this method when you have the full file in memory already and/or need the complete message array immediately without listening for events.

You can supply an array of lines or a single string with line terminators.

const LineChatParser = require('line-chat-parser')

const messages = LineChatParser.parse([
  '2017.09.03 Sunday',
  '16:23 Bob Today I found something:',
  'Apparently there is a Node package for parsing chats now!',
  '16:25 Alice Whaaat',
  // ...
], ['Alice', 'Bob'])
// as stated above, you can leave out the user name array when processing
// mobile app exports

// or, alternatively:

const messages = LineChatParser.parse('2017.09.03 Sunday\n' +
  '16:23 Bob Today I found something:\n' +
  'Apparently there is a Node package for parsing chats now!\n' +
  '16:25 Alice Whaaat', ['Alice', 'Bob'])

console.log(messages)