cldr-smart-quotes 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +7 -0
- package/README.md +60 -2
- package/index.d.mts +48 -0
- package/index.mjs +2 -0
- package/package.json +37 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2025-Present Aviv Keller
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,61 @@
|
|
|
1
|
-
#
|
|
1
|
+
# cldr-smart-quotes
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Locale-correct quotation marks, from the [Unicode CLDR](https://cldr.unicode.org/):
|
|
4
|
+
look up a locale's quotation marks, quote text with them, or turn straight
|
|
5
|
+
quotes into them ("smart quotes").
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install cldr-smart-quotes
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import { getQuotes, quote, smartQuotes } from "cldr-smart-quotes";
|
|
17
|
+
|
|
18
|
+
getQuotes("de");
|
|
19
|
+
// { start: "„", end: "“", alternateStart: "‚", alternateEnd: "‘" }
|
|
20
|
+
|
|
21
|
+
quote("Bonjour", "fr"); // "«Bonjour»"
|
|
22
|
+
quote("やあ", "ja"); // "「やあ」"
|
|
23
|
+
|
|
24
|
+
smartQuotes(`"She said 'don't'," he wrote.`, "en");
|
|
25
|
+
// "“She said ‘don’t’,” he wrote."
|
|
26
|
+
smartQuotes(`"She said 'hi'"`, "de");
|
|
27
|
+
// "„She said ‚hi‘“"
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## API
|
|
31
|
+
|
|
32
|
+
### `getQuotes(locale)`
|
|
33
|
+
|
|
34
|
+
Returns `{ start, end, alternateStart, alternateEnd }`: the quotation marks
|
|
35
|
+
of a locale, and the alternate marks used for quotes inside quotes.
|
|
36
|
+
|
|
37
|
+
### `quote(text, locale, options?)`
|
|
38
|
+
|
|
39
|
+
Wraps text in the locale's quotation marks, or its alternate marks with
|
|
40
|
+
`{ alternate: true }`.
|
|
41
|
+
|
|
42
|
+
### `smartQuotes(text, locale)`
|
|
43
|
+
|
|
44
|
+
Replaces straight double quotes with the locale's quotation marks, straight
|
|
45
|
+
single quotes with its alternate marks, and apostrophes (as in "don't",
|
|
46
|
+
"students'" and "'90s") with ’.
|
|
47
|
+
|
|
48
|
+
### `VERSION`
|
|
49
|
+
|
|
50
|
+
The CLDR version of the data, such as `"49.0.0"`.
|
|
51
|
+
|
|
52
|
+
## Locales
|
|
53
|
+
|
|
54
|
+
`locale` is a BCP 47 language tag or an `Intl.Locale`. Locales fall back to
|
|
55
|
+
their parents ("de-AT" uses "de") and finally to the CLDR root locale, and
|
|
56
|
+
use the likely script of their region ("zh-TW" uses Traditional Chinese
|
|
57
|
+
marks). Lookup does not depend on the JavaScript engine's locale data.
|
|
58
|
+
|
|
59
|
+
## License
|
|
60
|
+
|
|
61
|
+
MIT. Includes data from the Unicode CLDR, © Unicode, Inc., under the [Unicode License v3](https://www.unicode.org/license.txt).
|
package/index.d.mts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export declare const VERSION: string;
|
|
2
|
+
/**
|
|
3
|
+
* Returns the quotation marks of a locale
|
|
4
|
+
* @param {string | Intl.Locale} locale
|
|
5
|
+
* @returns {Quotes}
|
|
6
|
+
*/
|
|
7
|
+
export declare function getQuotes(locale: string | Intl.Locale): Quotes;
|
|
8
|
+
/**
|
|
9
|
+
* Wraps text in the quotation marks of a locale
|
|
10
|
+
* @param {string} text
|
|
11
|
+
* @param {string | Intl.Locale} locale
|
|
12
|
+
* @param {object} [options]
|
|
13
|
+
* @param {boolean} [options.alternate] - Use the marks for nested quotes
|
|
14
|
+
* @returns {string}
|
|
15
|
+
*/
|
|
16
|
+
export declare function quote(text: string, locale: string | Intl.Locale, { alternate }?: {
|
|
17
|
+
alternate?: boolean;
|
|
18
|
+
}): string;
|
|
19
|
+
/**
|
|
20
|
+
* Replaces straight quotes and apostrophes with a locale's typographic ones
|
|
21
|
+
* @param {string} text
|
|
22
|
+
* @param {string | Intl.Locale} locale
|
|
23
|
+
* @returns {string}
|
|
24
|
+
*/
|
|
25
|
+
export declare function smartQuotes(text: string, locale: string | Intl.Locale): string;
|
|
26
|
+
declare const _default: {
|
|
27
|
+
getQuotes: typeof getQuotes;
|
|
28
|
+
quote: typeof quote;
|
|
29
|
+
smartQuotes: typeof smartQuotes;
|
|
30
|
+
VERSION: string;
|
|
31
|
+
};
|
|
32
|
+
export type Quotes = {
|
|
33
|
+
start: string;
|
|
34
|
+
end: string;
|
|
35
|
+
/**
|
|
36
|
+
* For nested quotes
|
|
37
|
+
*/
|
|
38
|
+
alternateStart: string;
|
|
39
|
+
alternateEnd: string;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* @typedef {object} Quotes
|
|
43
|
+
* @property {string} start
|
|
44
|
+
* @property {string} end
|
|
45
|
+
* @property {string} alternateStart For nested quotes
|
|
46
|
+
* @property {string} alternateEnd
|
|
47
|
+
*/
|
|
48
|
+
export { _default as default };
|
package/index.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! cldr-smart-quotes | MIT License | Includes data © Unicode, Inc., Unicode License v3 (https://www.unicode.org/license.txt) */
|
|
2
|
+
function e(e){if(typeof e!=`string`)throw TypeError(`Input must be a string`)}const t=/* @__PURE__ */ new Map;function n(e){if(typeof e!=`string`)return new Intl.Locale(e).baseName;let n=t.get(e);return n===void 0&&(t.size>=1e3&&t.clear(),n=new Intl.Locale(e).baseName,t.set(e,n)),n}function r(e,t){let r=n(t);for(;!e.locales.has(r);){let t=r.lastIndexOf(`-`);r=e.aliases.get(r)??(t===-1?`und`:r.slice(0,t))}return r}function i(e,t){return e.values[e.locales.get(r(e,t))]}const a={values:[[`«`,`»`,`‘`,`’`],[`“`,`”`,`‘`,`’`],[`„`,`”`,`‚`,`’`],[`«`,`»`,`‹`,`›`],[`”`,`“`,`’`,`‘`],[`«`,`»`,`“`,`”`],[`«`,`»`,`„`,`“`],[`„`,`“`,`„`,`“`],[`„`,`“`,`‚`,`‘`],[`„`,`”`,`‘`,`’`],[`“`,`”`,`«`,`»`],[`”`,`”`,`’`,`’`],[`«`,`»`,`«`,`»`],[`«`,`»`,`”`,`“`],[`‘`,`’`,`“`,`”`],[`„`,`”`,`»`,`«`],[`「`,`」`,`『`,`』`],[`„`,`“`,`«`,`»`],[`»`,`«`,`›`,`‹`],[`‘`,`’`,`‘`,`’`],[`„`,`”`,`«`,`»`],[`«`,`»`,`„`,`”`],[`„`,`”`,`’`,`’`],[`“`,`’`,`“`,`”`],[`“`,`”`,`“`,`”`],[`“`,`”`,`’`,`‘`]],locales:/* @__PURE__ */ new Map([[`und`,1],[`ady`,0],[`agq`,2],[`am`,3],[`ar`,4],[`ast`,5],[`bas`,6],[`be`,6],[`bg`,7],[`blo`,5],[`bm`,5],[`br`,5],[`bs`,9],[`bua`,6],[`ca`,5],[`cs`,8],[`cv`,5],[`de`,8],[`dsb`,8],[`dua`,0],[`dyo`,5],[`el`,5],[`eo`,10],[`et`,8],[`eu`,5],[`ewo`,5],[`fa`,3],[`ff`,2],[`fi`,11],[`fr`,12],[`fur`,14],[`gsw`,3],[`he`,11],[`hr`,8],[`hsb`,8],[`hu`,15],[`hy`,12],[`ia`,14],[`ie`,5],[`is`,8],[`it`,5],[`ja`,16],[`jgo`,3],[`ka`,17],[`kab`,5],[`kbd`,0],[`kk`,5],[`kkj`,3],[`ksf`,0],[`ksh`,8],[`ky`,6],[`lag`,11],[`lb`,8],[`lij`,5],[`lld`,4],[`lt`,7],[`luy`,8],[`mg`,5],[`mk`,8],[`mua`,5],[`mzn`,3],[`nb`,0],[`nds`,8],[`nl`,19],[`nmg`,20],[`nn`,0],[`nnh`,5],[`no`,0],[`oc`,12],[`os`,6],[`pl`,20],[`pms`,5],[`prg`,7],[`rm`,3],[`rn`,11],[`ro`,20],[`ru`,6],[`rw`,0],[`sah`,6],[`sc`,5],[`se`,11],[`sg`,5],[`shi`,21],[`sk`,8],[`sl`,8],[`sn`,11],[`sr`,22],[`st`,23],[`sv`,11],[`syr`,4],[`szl`,15],[`ti`,5],[`tk`,24],[`tn`,24],[`tyv`,6],[`ug`,18],[`uk`,6],[`ur`,4],[`uz`,25],[`wae`,3],[`yav`,12],[`yi`,11],[`yue`,16],[`zgh`,21],[`az-Cyrl`,3],[`bs-Cyrl`,8],[`el-polyton`,0],[`es-US`,5],[`ff-Adlm`,1],[`fr-CA`,13],[`fr-CH`,3],[`kk-Arab`,18],[`pt-AO`,5],[`pt-CH`,5],[`pt-CV`,5],[`pt-GQ`,5],[`pt-GW`,5],[`pt-LU`,5],[`pt-MO`,5],[`pt-MZ`,5],[`pt-PT`,5],[`pt-ST`,5],[`pt-TL`,5],[`ti-ER`,14],[`uz-Arab`,1],[`uz-Cyrl`,1],[`zh-Hant`,16]]),aliases:/* @__PURE__ */ new Map([[`az-RU`,`az-Cyrl-RU`],[`kk-AF`,`kk-Arab-AF`],[`kk-CN`,`kk-Arab-CN`],[`kk-IR`,`kk-Arab-IR`],[`kk-MN`,`kk-Arab-MN`],[`uz-AF`,`uz-Arab-AF`],[`uz-CN`,`uz-Cyrl-CN`],[`zh-AU`,`zh-Hant-AU`],[`zh-BN`,`zh-Hant-BN`],[`zh-GB`,`zh-Hant-GB`],[`zh-GF`,`zh-Hant-GF`],[`zh-HK`,`zh-Hant-HK`],[`zh-ID`,`zh-Hant-ID`],[`zh-MO`,`zh-Hant-MO`],[`zh-PA`,`zh-Hant-PA`],[`zh-PF`,`zh-Hant-PF`],[`zh-PH`,`zh-Hant-PH`],[`zh-SR`,`zh-Hant-SR`],[`zh-TH`,`zh-Hant-TH`],[`zh-TW`,`zh-Hant-TW`],[`zh-US`,`zh-Hant-US`],[`zh-VN`,`zh-Hant-VN`]])},o=`49.0.0`,s=/[\p{L}\p{N}\p{M}]/u,c=/[\s\p{Ps}\p{Pi}\p{Pd}]/u,l=/\s/u,u=/\p{Nd}/u;function d(e){let[t,n,r,o]=i(a,e);return{start:t,end:n,alternateStart:r,alternateEnd:o}}function f(t,n,{alternate:r=!1}={}){e(t);let[o,s,c,l]=i(a,n);return r?c+t+l:o+t+s}function p(t,n){e(t);let[r,o,u,d]=i(a,n),f=Array.from(t),p=``,h=0,g=!1;for(let e=0;e<f.length;e++){let t=f[e];if(t!==`"`&&t!==`'`){p+=t,g=!1;continue}let n=f[e-1],i=f[e+1],a=(n===void 0||g||c.test(n))&&i!==void 0&&!l.test(i),_,v=!1;t===`"`?(_=a?r:o,v=a):a&&m(f,e)?_=`’`:a?(_=u,v=!0,h++):s.test(n)&&i!==void 0&&s.test(i)?_=`’`:h>0?(_=d,h--):_=`’`,p+=_,g=v}return p}function m(e,t){return u.test(e[t+1]??``)&&u.test(e[t+2]??``)&&!u.test(e[t+3]??``)}var h={getQuotes:d,quote:f,smartQuotes:p,VERSION:o};export{o as VERSION,h as default,d as getQuotes,f as quote,p as smartQuotes};
|
package/package.json
CHANGED
|
@@ -1,6 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cldr-smart-quotes",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Locale-correct quotation marks and smart quotes, based on the Unicode CLDR",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"unicode",
|
|
7
|
+
"cldr",
|
|
8
|
+
"quotes",
|
|
9
|
+
"smart-quotes",
|
|
10
|
+
"typography",
|
|
11
|
+
"i18n",
|
|
12
|
+
"locale"
|
|
13
|
+
],
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"author": "Aviv Keller <me@aviv.sh>",
|
|
16
|
+
"type": "module",
|
|
17
|
+
"main": "./index.mjs",
|
|
18
|
+
"types": "./index.d.mts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./index.d.mts",
|
|
22
|
+
"default": "./index.mjs"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"index.mjs",
|
|
27
|
+
"index.d.mts"
|
|
28
|
+
],
|
|
29
|
+
"sideEffects": false,
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/avivkeller/unicode-packages.git",
|
|
33
|
+
"directory": "packages/cldr/smart-quotes"
|
|
34
|
+
},
|
|
35
|
+
"bugs": {
|
|
36
|
+
"url": "https://github.com/avivkeller/unicode-packages/issues"
|
|
37
|
+
},
|
|
38
|
+
"homepage": "https://github.com/avivkeller/unicode-packages/tree/main/packages/cldr/smart-quotes#readme"
|
|
39
|
+
}
|