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

classical-chinese

v0.0.7

Published

Classical Chinese literature in JavaScript

Downloads

15

Readme

Classical Chinese for Node.js

This is the beginning of a hopefully vast project that will make the content of Classical Chinese texts available within any Node.js app. I hope you will frequently check for updates and, if you have any ideas or want to contribute, will open issues and pull requests on the github repository.

0.0.4 Updates: Fix incomplete texts. Add "Art of War" by Sunzi. Add concordance function.
0.0.5 Add mengzi. Change language in findIn return data.
0.0.6 Add getFull() function for full text retrieval.

The examples below assume we have required the module thusly:

var classical = require('classical-chinese');

##Load the Texts

You can load all of the texts

classical.loadAll();

Or just some of them

classical.loadSome('laozi','libai','dufu');

These functions parse the texts and load them from a local JSON file. See the list at the bottom of currently available texts.

##Get Information from Texts

If you want a list of titles within a given text:

classical.getTitles('zhuangzi', function (titles) {
	console.log(titles) //returns an array of all the chapter/poem titles in the text
})

If you want an entire text:

var daodejing = classical.getFull('laozi');
//daodejing now contains an array of chapter objects

If you want a specific chapter of a text, getText takes a book name, a chapter name and a callback:

classical.getText('zhuangzi', '逍遙游', function (result) {
	console.log(result) // returns an object: {title: '逍遙游', body: '...'}
})

If you want to find specific characters in a text, use findIn with the book name and the characters you want to search for:

classical.findIn('zhuangzi', '聖知之法', function (results) {
	console.log(results) // returns matches from all chapters in a text: [ { section: '胠篋', line: '并其聖知之法而盜之' },{ section: '胠篋', line: '并與其聖知之法' } ]

})

If you want to search the entire library from a string of characters use searchAll:

classical.searchAll('饿死', function (results) {
	console.log(results) // returns matches in all texts: { laozi: [ 'No matches.' ], libai: [ { section: '笑歌行(以下二首,苏轼云是伪作)', line: '夷齐饿死终无成' } ], dufu: [ { section: '奉赠韦左丞丈二十二韵', line: '纨袴不饿死' }, { section: '醉时歌(赠广文馆博士郑虔)', line: '焉知饿死填沟壑' }, { section: '奉赠鲜于京兆二十韵(鲜于仲通,天宝末为京兆尹)', line: '有儒愁饿死' } ], zhuangzi: [ 'No matches.' ] }	
})

If you want a list of every character in a text and the lines where they occur, use the concordance function:

classical.concordance('laozi', function (results) {
		console.log(results); // returns an object with a property for each character and an array of occurances: {'败': [ '为者败之', '故无败', '常于几成而败之', '则无败事' ],'嘘': [ '或嘘或吹' ],'吹': [ '或嘘或吹' ],'羸': [ '或强或羸' ],'隳': [ '或载或隳' ],}
	})

##Currently available texts:

'laozi' - The Dao De Jing (aka Tao Te Qing). A warring states era text on philosophy and statecraft.
'zhuangzi' - The Zhuangzi is another warring states era text, very rich and colorful in its language.
'dufu' - The complete works of the Tang poet Du Fu.
'libai' - Complete works of Tang poet Li Bai.
'lunyu' - The collected sayings of Confucius compliled during the warring states period.
'sunzi' - The Art of War by the famous general Sunzi, early warring states (~500bc).
'mengzi' - Canonical confucian philosopher, late warring states.

###License MIT