Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Regtech Regex Support to Node Environments #22

Merged
merged 8 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
missing resources?
  • Loading branch information
tanner-ricks committed Dec 12, 2024
commit 1d32f03ab5b23d8ac8b873410c003518950503f4
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,5 @@ node_modules/
bower_components/
.grunt/
src/vendor/
dist/
dist/
!node/dist/
15 changes: 15 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
compressionLevel: mixed

enableGlobalCache: false

enableHardenedMode: true

enableMirror: true

enableOfflineMode: true

enableTelemetry: false

nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.2.1.cjs
40 changes: 40 additions & 0 deletions src/node/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# regtech_regex

Node project to provide a reusable node module to other node projects dependent on these regex's for validation of data.

## Installation

Until we start publishing to npm, install this github repo:

```
yarn add cfpb/design-system-react
```

If you're using yarn v2 or greater, [`yarn pack`](https://yarnpkg.com/advanced/lifecycle-scripts) will automatically build the package for you after it's installed.

## Usage

```ts
import type { RegtechRegexConfigs } from 'regtech-regex';
import validations from 'regtech-regex';

console.log(validations as RegtechRegexConfigs);

```

## Development

To persist changes made to validations.yaml:

1. Install Node v22+.
1. Enable [corepack](https://yarnpkg.com/getting-started/install): `corepack enable`.
1. `yarn`
1. `yarn build`

Note: This project uses yarn v3.5 in "plug n play" mode. There is no `node_modules/` directory. Packages are stored in `.yarn/cache/`.

## Open source licensing info

1. [TERMS](TERMS.md)
2. [LICENSE](LICENSE)
3. [CFPB Source Code Policy](https://github.com/cfpb/source-code-policy/)
8 changes: 8 additions & 0 deletions src/node/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { parse as yamlParse } from "yaml";
import * as fs from 'fs';
import * as path from "path";

const __dirname = path.dirname(path.resolve('./package.json'));
const content = fs.readFileSync(path.resolve('src/validations.yaml'), {encoding: "utf8"});
const configs = yamlParse(content);
fs.writeFileSync(path.join(__dirname, '/src/validations.json'), JSON.stringify(configs, null, "\t"));
12 changes: 12 additions & 0 deletions src/node/dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export type RegtechRegexNames = "email" | "lei" | "rssd_id" | "simple_us_phone_number" | "tin";
export type RegtechRegexConfigs = Record<RegtechRegexNames, RegtechRegexConfig>;
export type RegtechRegexConfig = {
description: string;
error_text: string;
regex: string;
examples?: string[];
link?: string;
references?: string[];
};
export declare const RegtechRegex: RegtechRegexConfigs;
export default RegtechRegex;
1 change: 1 addition & 0 deletions src/node/dist/regtech-regex.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 62 additions & 0 deletions src/node/dist/regtech-regex.es.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const e = {
description: "must conform to common email conventions using the W3C method of email validation which is only a subset of full RFC 5322 compliance",
error_text: "Must be a valid email address.",
examples: [
"a-test-email-account@cfpb.gov",
"ASuperCoolEmailAccount@cfpb.gov"
],
link: "https://regex101.com/r/bUsmeo/2",
references: [
"https://html.spec.whatwg.org/multipage/input.html#email-state-(type=email)"
],
regex: "^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"
}, t = {
description: "must be 18 characters that only contain A-Z and 0-9 followed by 2 digits",
error_text: "Must be a valid LEI of 20 characters that only contain A-Z and 0-9 (no special characters).",
examples: [
"123400TESTBANK000192",
"123400TESTBANK000289",
"123400TESTSUBBANK147",
"123400TESTSUBBANK244",
"TESTBANK123456789012"
],
link: "https://regex101.com/r/ItOdOj/3",
regex: "^[A-Z0-9]{18}\\d{2}$"
}, o = {
description: "must be an integer",
error_text: "Must be a number.",
examples: [
"9999",
"1"
],
link: "https://regex101.com/r/l3SyQi/3",
regex: "^\\d+$"
}, i = {
description: "must be a simple United States phone number pattern of 3 digits, followed by a hyphen, followed by 3 digits, followed by a hyphen, followed by 4 digits",
error_text: "Must be a valid phone number in the format of 555-555-5555.",
examples: [
"555-555-5555",
"555-123-4567"
],
link: "https://regex101.com/r/jt6ujJ/5",
regex: "^\\d{3}-\\d{3}-\\d{4}$"
}, s = {
description: "must be 2 digits, followed by a hyphen, followed by 7 digits",
error_text: "Must be a valid TIN in the format of 12-3456789.",
examples: [
"12-3456789",
"98-7654321"
],
link: "https://regex101.com/r/7op0LA/3",
regex: "^\\d{2}-\\d{7}$"
}, a = {
email: e,
lei: t,
rssd_id: o,
simple_us_phone_number: i,
tin: s
}, n = a;
export {
n as RegtechRegex,
n as default
};
Loading
Loading