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

jp-wrap

v0.2.2

Published

Japanese word wrap

Downloads

203

Readme

jp-wrap

日本語の禁則処理に対応したword-wrap

example

made out of meat in Japanese

var wrap = require('jp-wrap')(20);
console.log(wrap('「僕らはみんな、肉だ」とかって、substackが言ってたよ。'));

output:

「僕らはみんな、肉
だ」とかって、
substackが言ってた
よ。

centered

var wrap = require('jp-wrap')(20, 60);

console.log(wrap(
    'CureAppは、アプリを薬のように医師が処方する時代を創っていく会社です。' +
    '20世紀の医学は感染症をcontrollableなものとしました。' +
    '平均寿命が延伸するにつれて見えてきた、21世紀の医療の大きな課題は生活習慣病です。' +
    'しかし生活習慣は、当たり前のことですが、病院の中にはありません。' +
    '医療が介入しにくい場所にあった生活習慣。そこに24時間介入できるのが、' +
    'アプリでしょう。最新のevidenceやガイドラインに沿った指導を毎日行います。' +
    '「アプリの治療が当たり前になる」そんな未来を創っていきたいのです。'
));

output:

                    CureAppは、アプリを薬のように医師が処方                     
                    する時代を創っていく会社です。20世紀の医                    
                    学は感染症をcontrollableなものとしまし                      
                    た。平均寿命が延伸するにつれて見えてき                      
                    た、21世紀の医療の大きな課題は生活習慣病                    
                    です。しかし生活習慣は、当たり前のことで                    
                    すが、病院の中にはありません。医療が介入                    
                    しにくい場所にあった生活習慣。そこに24時                    
                    間介入できるのが、アプリでしょう。最新の                    
                    evidenceやガイドラインに沿った指導を毎日                    
                    行います。「アプリの治療が当たり前にな                      
                    る」そんな未来を創っていきたいのです。                      

install

npm install jp-wrap

methods

substack/node-wordwrapと似たAPIにしました。

var jpWrap = require('jp-wrap');

jpWrap(stop, options)

文字列を受け取って、新しい文字列を返す関数 を返す. stopは文字の幅。

jpWrap(start, stop, options)

2つの数字が与えられたときは 文字列を与えるとstop - startの幅でwrapし、左右にstartだけのpaddingをつける関数 を返す.

options

| name | type | 意味 | デフォルト | |:---------------|:--------|:--------------------------------------------|:-----------| | trim | boolean | 入力文字列の改行を利用しないときtrue | false | | half | boolean | 半角文字の行頭禁則処理を行うかどうか | false | | breakAll | boolean | trueだとcssのword-break:break-allと同じ挙動 | false | | fullWidthSpace | boolean | 全角スペースが行頭にあった場合削除するか | true | | sameWidth | boolean | 全角と半角文字の両方を幅2として計算するか | false | | regexs | array | 幅の計算方法を正規表現で指定する | [] |

optionsの例

小文字のアルファベットを幅3として計算する

new JpWrap(100, {regExs: [{pattern:/[a-z]/, width: 3}]});

小文字のアルファベットを幅3、大文字のアルファベットを幅5として計算する

new JpWrap(100, {regExs: [{pattern:/[a-z]/, width: 3}, {pattern:/[A-Z]/, width: 5}]});

もっと内部をさわりたい方

var JpWrap = require('jp-wrap').JpWrap;

クラスが取れます。 こちらの仕様は API docs にあります。

LICENSE

MIT

thanks to

下記を参考にし、改変しました。