Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .github/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL Semantic Analysis"

on:
push: # all pushes
pull_request: # all PR

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: true
matrix:
language: [ 'javascript' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
# Learn more:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed

steps:
- name: Checkout repository
uses: actions/checkout@v2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
# - name: Autobuild
# uses: github/codeql-action/autobuild@v1

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
75 changes: 75 additions & 0 deletions .github/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Test suite

on:
push:
branches:
- master # allthough master is push protected we still keep it
- development
pull_request: # runs on all PR

jobs:
# ----------------------------------
# uncomment when a linter is added
# ----------------------------------

# lintjs:
# name: Javascript lint
# runs-on: ubuntu-latest
# steps:
# - name: checkout
# uses: actions/checkout@v2
#
# - name: setup node
# uses: actions/setup-node@v1
# with:
# node-version: '12.x'
#
# - name: cache dependencies
# uses: actions/cache@v1
# with:
# path: ~/.npm
# key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
# restore-keys: |
# ${{ runner.os }}-node-
# - run: npm ci
# - run: npm run lint

unittest:
name: unit tests
runs-on: ubuntu-latest
# uncomment when a linter is added
# needs: [lintjs]
strategy:
matrix:
node: [12, 14, 16]
steps:
- name: Checkout ${{ matrix.node }}
uses: actions/checkout@v2

- name: Setup node ${{ matrix.node }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}

- name: Cache dependencies ${{ matrix.node }}
uses: actions/cache@v1
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-${{ matrix.node }}
- run: npm ci
- run: npm run test:coverage

# ----------------------------------
# uncomment when a linter is added
# ----------------------------------

# - name: check coverage
# uses: devmasx/coverage-check-action@v1.2.0
# with:
# type: lcov
# result_path: coverage/lcov.info
# min_coverage: 90
# token: ${{github.token}}

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ coverage

# nyc test coverage
.nyc_output
coverage/

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
Expand Down Expand Up @@ -102,3 +103,4 @@ dist

# TernJS port file
.tern-port

4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
test/
.github
.nyc_output
coverage
71 changes: 71 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<a name="isUnicode"></a>

## isUnicode
Minimal, RFC 6749, compliant unicode validator.

**Kind**: global constant
**See**: https://datatracker.ietf.org/doc/html/rfc6749#appendix-A

* [isUnicode](#isUnicode)
* [.nchar()](#isUnicode.nchar) ⇒ <code>boolean</code>
* [.nqchar()](#isUnicode.nqchar) ⇒ <code>boolean</code>
* [.nqschar()](#isUnicode.nqschar) ⇒ <code>boolean</code>
* [.uchar()](#isUnicode.uchar) ⇒ <code>boolean</code>
* [.uri()](#isUnicode.uri) ⇒ <code>boolean</code>
* [.vschar()](#isUnicode.vschar) ⇒ <code>boolean</code>

<a name="isUnicode.nchar"></a>

### isUnicode.nchar() ⇒ <code>boolean</code>
Validate if a value matches a unicode character.

**Kind**: static method of [<code>isUnicode</code>](#isUnicode)
**Returns**: <code>boolean</code> - true, if valid, otherwise false
**Value**: <code>string</code> the value to be validated
**See**: https://tools.ietf.org/html/rfc6749#appendix-A
<a name="isUnicode.nqchar"></a>

### isUnicode.nqchar() ⇒ <code>boolean</code>
Validate if a value matches a unicode character, including exclamation marks.

**Kind**: static method of [<code>isUnicode</code>](#isUnicode)
**Returns**: <code>boolean</code> - true, if valid, otherwise false
**Value**: <code>string</code> the value to be validated
**See**: https://tools.ietf.org/html/rfc6749#appendix-A
<a name="isUnicode.nqschar"></a>

### isUnicode.nqschar() ⇒ <code>boolean</code>
Validate if a value matches a unicode character, including exclamation marks and spaces.

**Kind**: static method of [<code>isUnicode</code>](#isUnicode)
**Returns**: <code>boolean</code> - true, if valid, otherwise false
**Value**: <code>string</code> the value to be validated
**See**: https://tools.ietf.org/html/rfc6749#appendix-A
<a name="isUnicode.uchar"></a>

### isUnicode.uchar() ⇒ <code>boolean</code>
Validate if a value matches a unicode character excluding the carriage
return and linefeed characters.

**Kind**: static method of [<code>isUnicode</code>](#isUnicode)
**Returns**: <code>boolean</code> - true, if valid, otherwise false
**Value**: <code>string</code> the value to be validated
**See**: https://tools.ietf.org/html/rfc6749#appendix-A
<a name="isUnicode.uri"></a>

### isUnicode.uri() ⇒ <code>boolean</code>
Validate if a value matches generic URIs.

**Kind**: static method of [<code>isUnicode</code>](#isUnicode)
**Returns**: <code>boolean</code> - true, if valid, otherwise false
**Value**: <code>string</code> the value to be validated
**See**: http://tools.ietf.org/html/rfc3986#section-3
<a name="isUnicode.vschar"></a>

### isUnicode.vschar() ⇒ <code>boolean</code>
Validate if a value matches against the printable set of unicode characters.

**Kind**: static method of [<code>isUnicode</code>](#isUnicode)
**Returns**: <code>boolean</code> - true, if valid, otherwise false
**Value**: <code>string</code> the value to be validated
**See**: https://tools.ietf.org/html/rfc6749#appendix-A
39 changes: 36 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,43 @@
# Is Unicode
# @node-oauth/is-unicode

Validate unicode values.
Minimal, [RFC 6749](https://datatracker.ietf.org/doc/html/rfc6749#appendix-A)
compliant unicode validator.

This package is intended to be used with a OAuth2 server, like
[@node-oauth/node-oauth2-server](https://github.com/node-oauth/node-oauth2-server)
, but can also be used with any other project, that shares the same
requirements.

## Install

```bash
$ npm install @node-oauth/is-unicode
```

## Usage

```js
const isUnicode from '@node-oauth/is-unicode'

isUnicode.nchar('Hello, World!') // false
isUnicode.nqchar('Hello, World!') // true
```

For detailed usage see the [API docs](./API.md)

## Test

```sh
npm install
npm run test
npm run lint # run esline in check mode
npm run lint:fix # run esline in check mode
npm run test # run test once
npm run test:coverage # run tests with coverage report
```

## License

This project has been outsourced from
[@node-oauth/node-oauth2-server](https://github.com/node-oauth/node-oauth2-server)
, which is a fork from [oauth2-server](https://github.com/oauthjs/node-oauth2-server)
. The licence remains MIT, see [our license file](./LICENSE).
24 changes: 21 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

/**
* Validation rules.
* @private
*/

const rules = {
Expand All @@ -18,15 +19,17 @@ const rules = {
/* eslint-enable no-control-regex */

/**
* Export validation functions.
* Minimal, RFC 6749, compliant unicode validator.
* @see https://datatracker.ietf.org/doc/html/rfc6749#appendix-A
*/

module.exports = {
const isUnicode = {

/**
* Validate if a value matches a unicode character.
*
* @see https://tools.ietf.org/html/rfc6749#appendix-A
* @value {string} the value to be validated
* @return {boolean} true, if valid, otherwise false
*/

nchar: function(value) {
Expand All @@ -37,6 +40,8 @@ module.exports = {
* Validate if a value matches a unicode character, including exclamation marks.
*
* @see https://tools.ietf.org/html/rfc6749#appendix-A
* @value {string} the value to be validated
* @return {boolean} true, if valid, otherwise false
*/

nqchar: function(value) {
Expand All @@ -47,6 +52,8 @@ module.exports = {
* Validate if a value matches a unicode character, including exclamation marks and spaces.
*
* @see https://tools.ietf.org/html/rfc6749#appendix-A
* @value {string} the value to be validated
* @return {boolean} true, if valid, otherwise false
*/

nqschar: function(value) {
Expand All @@ -58,6 +65,8 @@ module.exports = {
* return and linefeed characters.
*
* @see https://tools.ietf.org/html/rfc6749#appendix-A
* @value {string} the value to be validated
* @return {boolean} true, if valid, otherwise false
*/

uchar: function(value) {
Expand All @@ -73,6 +82,8 @@ module.exports = {
* Validate if a value matches generic URIs.
*
* @see http://tools.ietf.org/html/rfc3986#section-3
* @value {string} the value to be validated
* @return {boolean} true, if valid, otherwise false
*/
uri: function(value) {
return rules.URI.test(value);
Expand All @@ -82,9 +93,16 @@ module.exports = {
* Validate if a value matches against the printable set of unicode characters.
*
* @see https://tools.ietf.org/html/rfc6749#appendix-A
* @value {string} the value to be validated
* @return {boolean} true, if valid, otherwise false
*/

vschar: function(value) {
return rules.VSCHAR.test(value);
}
};

/**
* Export validation functions.
*/
module.exports = isUnicode;
Loading