Skip to content

Commit 1c3302c

Browse files
committed
Move grapheme cluster break tooling to own package
1 parent c5521c0 commit 1c3302c

13 files changed

Lines changed: 2968 additions & 0 deletions

File tree

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2021 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# grapheme
22+
23+
> Grapheme cluster break tooling.
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26+
27+
<section class="intro">
28+
29+
</section>
30+
31+
<!-- /.intro -->
32+
33+
<!-- Package usage documentation. -->
34+
35+
<section class="usage">
36+
37+
## Usage
38+
39+
```javascript
40+
var grapheme = require( '@stdlib/string/tools/grapheme-cluster-break' );
41+
```
42+
43+
#### grapheme
44+
45+
A collection of functions for performing grapheme cluster break operations.
46+
47+
* * *
48+
49+
### Methods
50+
51+
#### grapheme.breakProperty( code )
52+
53+
Returns the grapheme break property from the [Unicode Standard][unicode-grapheme-break-property].
54+
55+
```javascript
56+
var out = grapheme.breakProperty( 0x008f );
57+
// returns 2
58+
59+
out = grapheme.breakProperty( 0x111C2 );
60+
// returns 12
61+
62+
out = grapheme.breakProperty( 0x1F3FC );
63+
// returns 3
64+
```
65+
66+
#### grapheme.emojiProperty( code )
67+
68+
Returns the emoji property from the [Unicode Standard][unicode-emoji-property].
69+
70+
```javascript
71+
var out = grapheme.emojiProperty( 0x23EC );
72+
// returns 101
73+
74+
out = grapheme.emojiProperty( 0x1FFFE );
75+
// returns 11
76+
```
77+
78+
#### grapheme.breakType( breaks, emoji )
79+
80+
Returns the break type between grapheme breaking classes according to _UAX #29 3.1.1 Grapheme Cluster Boundary Rules_ on extended grapheme clusters.
81+
82+
```javascript
83+
var out = grapheme.breakType( [ 11, 3, 11 ], [ 11, 11, 11 ] );
84+
// returns 1
85+
```
86+
87+
* * *
88+
89+
### Properties
90+
91+
#### grapheme.constants
92+
93+
An object mapping break type names to integer values.
94+
95+
```javascript
96+
var out = grapheme.constants;
97+
// returns {...}
98+
```
99+
100+
</section>
101+
102+
<!-- /.usage -->
103+
104+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
105+
106+
<section class="notes">
107+
108+
</section>
109+
110+
<!-- /.notes -->
111+
112+
<!-- Package usage examples. -->
113+
114+
<section class="examples">
115+
116+
## Examples
117+
118+
<!-- eslint no-undef: "error" -->
119+
120+
```javascript
121+
var grapheme = require( '@stdlib/string/tools/grapheme-cluster-break' );
122+
123+
var out = grapheme.breakProperty( 0x008f );
124+
// returns 2
125+
126+
out = grapheme.emojiProperty( 0x23EC );
127+
// returns 101
128+
129+
out = grapheme.breakType( [ 11, 3, 11 ], [ 11, 11, 11 ] );
130+
// returns 1
131+
132+
out = grapheme.constants;
133+
// returns {...}
134+
```
135+
136+
</section>
137+
138+
<!-- /.examples -->
139+
140+
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
141+
142+
<section class="references">
143+
144+
</section>
145+
146+
<!-- /.references -->
147+
148+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
149+
150+
<section class="related">
151+
152+
</section>
153+
154+
<!-- /.related -->
155+
156+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
157+
158+
<section class="links">
159+
160+
[unicode-grapheme-break-property]: https://www.unicode.org/Public/13.0.0/ucd/auxiliary/GraphemeBreakProperty.txt
161+
162+
[unicode-emoji-property]: https://www.unicode.org/Public/13.0.0/ucd/emoji/emoji-data.txt
163+
164+
<!-- <related-links> -->
165+
166+
<!-- </related-links> -->
167+
168+
</section>
169+
170+
<!-- /.links -->
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2021 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
// TypeScript Version: 2.0
20+
21+
/**
22+
* Interface describing grapheme cluster break tooling.
23+
*/
24+
interface Grapheme {
25+
/**
26+
* Returns the grapheme break property from the [Unicode Standard][1].
27+
*
28+
* [1]: https://www.unicode.org/Public/13.0.0/ucd/auxiliary/GraphemeBreakProperty.txt
29+
*
30+
* @param code - Unicode code point
31+
* @returns grapheme break property
32+
*
33+
* @example
34+
* var out = grapheme.breakProperty( 0x008f );
35+
* // returns 2
36+
*
37+
* @example
38+
* var out = grapheme.breakProperty( 0x111C2 );
39+
* // returns 12
40+
*
41+
* @example
42+
* var out = grapheme.breakProperty( 0x1F3FC );
43+
* // returns 3
44+
*/
45+
breakProperty( code: number ): number;
46+
47+
/**
48+
* Returns the break type between grapheme breaking classes according to _UAX #29 3.1.1 Grapheme Cluster Boundary Rules_ on extended grapheme clusters.
49+
*
50+
* @param breaks - list of grapheme break properties
51+
* @param emoji - list of emoji properties
52+
* @returns break type
53+
*
54+
* @example
55+
* var out = grapheme.breakType( [ 11, 3, 11 ], [ 11, 11, 11 ] );
56+
* // returns 1
57+
*/
58+
breakType( breaks: Array<number>, emoji: Array<number> ): number;
59+
60+
/**
61+
* Returns the emoji property from the [Unicode Standard][1].
62+
*
63+
* [1]: https://www.unicode.org/Public/13.0.0/ucd/emoji/emoji-data.txt
64+
*
65+
* @param code - Unicode code point
66+
* @returns emoji property
67+
*
68+
* @example
69+
* var out = emojiProperty( 0x23EC );
70+
* // returns 101
71+
*
72+
* @example
73+
* var out = emojiProperty( 0x1FFFE );
74+
* // returns 11
75+
*/
76+
emojiProperty( code: number ): number;
77+
78+
/**
79+
* An object mapping break type names to integer values.
80+
*/
81+
constants: any;
82+
}
83+
84+
/**
85+
* Grapheme cluster break tooling.
86+
*/
87+
declare var grapheme: Grapheme;
88+
89+
90+
// EXPORTS //
91+
92+
export = grapheme;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2021 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/* tslint:disable:no-unused-expression */
20+
21+
import grapheme = require( './index' );
22+
23+
24+
// TESTS //
25+
26+
// The exported value is the expected interface...
27+
{
28+
grapheme; // $ExpectType Grapheme
29+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2021 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
var grapheme = require( './../lib' );
22+
23+
var out = grapheme.breakProperty( 0x008f );
24+
console.log( out );
25+
// => 2
26+
27+
out = grapheme.emojiProperty( 0x23EC );
28+
console.log( out );
29+
// => 101
30+
31+
out = grapheme.breakType( [ 11, 3, 11 ], [ 11, 11, 11 ] );
32+
console.log( out );
33+
// => 1
34+
35+
out = grapheme.constants;
36+
console.log( out );
37+
// => {...}

0 commit comments

Comments
 (0)