https://github.com/youngoat/ecmascript.chc
Character Classes
https://github.com/youngoat/ecmascript.chc
charset
Last synced: 2 months ago
JSON representation
Character Classes
- Host: GitHub
- URL: https://github.com/youngoat/ecmascript.chc
- Owner: YounGoat
- Created: 2018-02-26T13:55:14.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-02-28T16:31:20.000Z (over 7 years ago)
- Last Synced: 2025-03-04T12:43:35.858Z (3 months ago)
- Topics: charset
- Language: JavaScript
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# chc
__Character Class__## Table of contents
* [Get Started](#get-started)
* [API](#api)
* [About](#about)## Links
* [CHANGE LOG](./CHANGELOG.md)
* [Homepage](https://github.com/YounGoat/ecmascript.chc)## Get Started
```javascript
const chc = require('chc');// Create an instance of CharSet.
const cs = new chc.CharSet('a', 'z');// Get number of characters in the CharSet.
cs.length == 26;// Get the next character in the CharSet.
cs.next();
// RETURN 'a'// If all characters iterated.
cs.isEnd();
// RETURN false// Reset the iteration state.
cs.reset();
cs.next();
// RETURN 'a'
```## API
### Create *CharSet* Instances
* class | CharSet __chc.CharSet__( CHAR *start*, CHAR *end* ) throws Error
Create a charset containing characters from *start* to *end*. Here `CHAR` maybe a code point number or a string containing one but only one character. When invalid arguments passed in, an error will be thrown.
To create an CharSet instance, this function supports both contrutor mode and factory mode.
Hereafter use __\__ to represent an instance of CharSet.* class | CharSet __chc.CharSet__(String *chars*)
Create a charset containing every character in *char*.* CharSet __CharSet.concat__( CHAR | string | CharSet | Array *chars*, ... )
Create a new charset.* CharSet __\.concat__( CHAR | string | CharSet | Array *chars*, ... )
Concatenate current charset with the character(s) or charsets, and return a new charset.* boolean __\.isEnd__()
If all characters in the charset have been iterated.* number __\.length__()
Number of characters in the charset.* boolean __\.next__()
Get the next character in the charset.* boolean __\.reset__()
Reset the iteration state of the charset.* Array __\.toArray__("string" | "number" *type* = `"string"`)
Return characters in the charset. If *type* equals "number", an array of code points will be returned.## About
Following packages depend on __chc__ and offer predefined charsets:
* [chc-posix](https://www.npmjs.com/package/chc-posix)