Skip to content

Commit c5eb79c

Browse files
committedDec 4, 2023
chore: initial commit
0 parents  commit c5eb79c

34 files changed

+2345
-0
lines changed
 

‎.editorconfig

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# EditorConfig helps developers define and maintain consistent
2+
# coding styles between different editors and IDEs
3+
# editorconfig.org
4+
5+
root = true
6+
7+
[*]
8+
9+
indent_style = space
10+
indent_size = 2
11+
12+
end_of_line = lf
13+
charset = utf-8
14+
trim_trailing_whitespace = true
15+
insert_final_newline = true

‎.gitattributes

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.pbxproj -text
2+
# specific for windows script files
3+
*.bat text eol=crlf

‎.github/actions/setup/action.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Setup
2+
description: Setup Node.js and install dependencies
3+
4+
runs:
5+
using: composite
6+
steps:
7+
- name: Setup Node.js
8+
uses: actions/setup-node@v3
9+
with:
10+
node-version-file: .nvmrc
11+
12+
- name: Cache dependencies
13+
id: yarn-cache
14+
uses: actions/cache@v3
15+
with:
16+
path: |
17+
**/node_modules
18+
.yarn/install-state.gz
19+
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}-${{ hashFiles('**/package.json', '!node_modules/**') }}
20+
restore-keys: |
21+
${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
22+
${{ runner.os }}-yarn-
23+
24+
- name: Install dependencies
25+
if: steps.yarn-cache.outputs.cache-hit != 'true'
26+
run: yarn install --immutable
27+
shell: bash

‎.github/workflows/ci.yml

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: CI
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
branches:
8+
- main
9+
10+
jobs:
11+
lint:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v3
16+
17+
- name: Setup
18+
uses: ./.github/actions/setup
19+
20+
- name: Lint files
21+
run: yarn lint
22+
23+
- name: Typecheck files
24+
run: yarn typecheck
25+
26+
test:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v3
31+
32+
- name: Setup
33+
uses: ./.github/actions/setup
34+
35+
- name: Run unit tests
36+
run: yarn test --maxWorkers=2 --coverage
37+
38+
build-library:
39+
runs-on: ubuntu-latest
40+
steps:
41+
- name: Checkout
42+
uses: actions/checkout@v3
43+
44+
- name: Setup
45+
uses: ./.github/actions/setup
46+
47+
- name: Build package
48+
run: yarn prepare
49+
50+
build-web:
51+
runs-on: ubuntu-latest
52+
steps:
53+
- name: Checkout
54+
uses: actions/checkout@v3
55+
56+
- name: Setup
57+
uses: ./.github/actions/setup
58+
59+
- name: Build example for Web
60+
run: |
61+
yarn example expo export:web

‎.gitignore

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# OSX
2+
#
3+
.DS_Store
4+
5+
# XDE
6+
.expo/
7+
8+
# VSCode
9+
.vscode/
10+
jsconfig.json
11+
12+
# Xcode
13+
#
14+
build/
15+
*.pbxuser
16+
!default.pbxuser
17+
*.mode1v3
18+
!default.mode1v3
19+
*.mode2v3
20+
!default.mode2v3
21+
*.perspectivev3
22+
!default.perspectivev3
23+
xcuserdata
24+
*.xccheckout
25+
*.moved-aside
26+
DerivedData
27+
*.hmap
28+
*.ipa
29+
*.xcuserstate
30+
project.xcworkspace
31+
32+
# Android/IJ
33+
#
34+
.classpath
35+
.cxx
36+
.gradle
37+
.idea
38+
.project
39+
.settings
40+
local.properties
41+
android.iml
42+
43+
# Cocoapods
44+
#
45+
example/ios/Pods
46+
47+
# Ruby
48+
example/vendor/
49+
50+
# node.js
51+
#
52+
node_modules/
53+
npm-debug.log
54+
yarn-debug.log
55+
yarn-error.log
56+
57+
# BUCK
58+
buck-out/
59+
\.buckd/
60+
android/app/libs
61+
android/keystores/debug.keystore
62+
63+
# Yarn
64+
.yarn/*
65+
!.yarn/patches
66+
!.yarn/plugins
67+
!.yarn/releases
68+
!.yarn/sdks
69+
!.yarn/versions
70+
71+
# Expo
72+
.expo/
73+
74+
# Turborepo
75+
.turbo/
76+
77+
# generated by bob
78+
lib/

‎.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v18

‎.watchmanconfig

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

‎.yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs

+541
Large diffs are not rendered by default.

‎.yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs

+28
Large diffs are not rendered by default.

‎.yarn/releases/yarn-3.6.1.cjs

+874
Large diffs are not rendered by default.

‎.yarnrc.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
nodeLinker: node-modules
2+
nmHoistingLimits: workspaces
3+
4+
plugins:
5+
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
6+
spec: "@yarnpkg/plugin-interactive-tools"
7+
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
8+
spec: "@yarnpkg/plugin-workspace-tools"
9+
10+
yarnPath: .yarn/releases/yarn-3.6.1.cjs

‎CODE_OF_CONDUCT.md

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
2+
# Contributor Covenant Code of Conduct
3+
4+
## Our Pledge
5+
6+
We as members, contributors, and leaders pledge to make participation in our
7+
community a harassment-free experience for everyone, regardless of age, body
8+
size, visible or invisible disability, ethnicity, sex characteristics, gender
9+
identity and expression, level of experience, education, socio-economic status,
10+
nationality, personal appearance, race, caste, color, religion, or sexual
11+
identity and orientation.
12+
13+
We pledge to act and interact in ways that contribute to an open, welcoming,
14+
diverse, inclusive, and healthy community.
15+
16+
## Our Standards
17+
18+
Examples of behavior that contributes to a positive environment for our
19+
community include:
20+
21+
* Demonstrating empathy and kindness toward other people
22+
* Being respectful of differing opinions, viewpoints, and experiences
23+
* Giving and gracefully accepting constructive feedback
24+
* Accepting responsibility and apologizing to those affected by our mistakes,
25+
and learning from the experience
26+
* Focusing on what is best not just for us as individuals, but for the overall
27+
community
28+
29+
Examples of unacceptable behavior include:
30+
31+
* The use of sexualized language or imagery, and sexual attention or advances of
32+
any kind
33+
* Trolling, insulting or derogatory comments, and personal or political attacks
34+
* Public or private harassment
35+
* Publishing others' private information, such as a physical or email address,
36+
without their explicit permission
37+
* Other conduct which could reasonably be considered inappropriate in a
38+
professional setting
39+
40+
## Enforcement Responsibilities
41+
42+
Community leaders are responsible for clarifying and enforcing our standards of
43+
acceptable behavior and will take appropriate and fair corrective action in
44+
response to any behavior that they deem inappropriate, threatening, offensive,
45+
or harmful.
46+
47+
Community leaders have the right and responsibility to remove, edit, or reject
48+
comments, commits, code, wiki edits, issues, and other contributions that are
49+
not aligned to this Code of Conduct, and will communicate reasons for moderation
50+
decisions when appropriate.
51+
52+
## Scope
53+
54+
This Code of Conduct applies within all community spaces, and also applies when
55+
an individual is officially representing the community in public spaces.
56+
Examples of representing our community include using an official e-mail address,
57+
posting via an official social media account, or acting as an appointed
58+
representative at an online or offline event.
59+
60+
## Enforcement
61+
62+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
63+
reported to the community leaders responsible for enforcement at
64+
[INSERT CONTACT METHOD].
65+
All complaints will be reviewed and investigated promptly and fairly.
66+
67+
All community leaders are obligated to respect the privacy and security of the
68+
reporter of any incident.
69+
70+
## Enforcement Guidelines
71+
72+
Community leaders will follow these Community Impact Guidelines in determining
73+
the consequences for any action they deem in violation of this Code of Conduct:
74+
75+
### 1. Correction
76+
77+
**Community Impact**: Use of inappropriate language or other behavior deemed
78+
unprofessional or unwelcome in the community.
79+
80+
**Consequence**: A private, written warning from community leaders, providing
81+
clarity around the nature of the violation and an explanation of why the
82+
behavior was inappropriate. A public apology may be requested.
83+
84+
### 2. Warning
85+
86+
**Community Impact**: A violation through a single incident or series of
87+
actions.
88+
89+
**Consequence**: A warning with consequences for continued behavior. No
90+
interaction with the people involved, including unsolicited interaction with
91+
those enforcing the Code of Conduct, for a specified period of time. This
92+
includes avoiding interactions in community spaces as well as external channels
93+
like social media. Violating these terms may lead to a temporary or permanent
94+
ban.
95+
96+
### 3. Temporary Ban
97+
98+
**Community Impact**: A serious violation of community standards, including
99+
sustained inappropriate behavior.
100+
101+
**Consequence**: A temporary ban from any sort of interaction or public
102+
communication with the community for a specified period of time. No public or
103+
private interaction with the people involved, including unsolicited interaction
104+
with those enforcing the Code of Conduct, is allowed during this period.
105+
Violating these terms may lead to a permanent ban.
106+
107+
### 4. Permanent Ban
108+
109+
**Community Impact**: Demonstrating a pattern of violation of community
110+
standards, including sustained inappropriate behavior, harassment of an
111+
individual, or aggression toward or disparagement of classes of individuals.
112+
113+
**Consequence**: A permanent ban from any sort of public interaction within the
114+
community.
115+
116+
## Attribution
117+
118+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
119+
version 2.1, available at
120+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
121+
122+
Community Impact Guidelines were inspired by
123+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
124+
125+
For answers to common questions about this code of conduct, see the FAQ at
126+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
127+
[https://www.contributor-covenant.org/translations][translations].
128+
129+
[homepage]: https://www.contributor-covenant.org
130+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
131+
[Mozilla CoC]: https://github.com/mozilla/diversity
132+
[FAQ]: https://www.contributor-covenant.org/faq
133+
[translations]: https://www.contributor-covenant.org/translations

‎CONTRIBUTING.md

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# Contributing
2+
3+
Contributions are always welcome, no matter how large or small!
4+
5+
We want this community to be friendly and respectful to each other. Please follow it in all your interactions with the project. Before contributing, please read the [code of conduct](./CODE_OF_CONDUCT.md).
6+
7+
## Development workflow
8+
9+
This project is a monorepo managed using [Yarn workspaces](https://yarnpkg.com/features/workspaces). It contains the following packages:
10+
11+
- The library package in the root directory.
12+
- An example app in the `example/` directory.
13+
14+
To get started with the project, run `yarn` in the root directory to install the required dependencies for each package:
15+
16+
```sh
17+
yarn
18+
```
19+
20+
> Since the project relies on Yarn workspaces, you cannot use [`npm`](https://github.com/npm/cli) for development.
21+
22+
The [example app](/example/) demonstrates usage of the library. You need to run it to test any changes you make.
23+
24+
It is configured to use the local version of the library, so any changes you make to the library's source code will be reflected in the example app. Changes to the library's JavaScript code will be reflected in the example app without a rebuild, but native code changes will require a rebuild of the example app.
25+
26+
You can use various commands from the root directory to work with the project.
27+
28+
To start the packager:
29+
30+
```sh
31+
yarn example start
32+
```
33+
34+
To run the example app on Android:
35+
36+
```sh
37+
yarn example android
38+
```
39+
40+
To run the example app on iOS:
41+
42+
```sh
43+
yarn example ios
44+
```
45+
46+
To run the example app on Web:
47+
48+
```sh
49+
yarn example web
50+
```
51+
52+
Make sure your code passes TypeScript and ESLint. Run the following to verify:
53+
54+
```sh
55+
yarn typecheck
56+
yarn lint
57+
```
58+
59+
To fix formatting errors, run the following:
60+
61+
```sh
62+
yarn lint --fix
63+
```
64+
65+
Remember to add tests for your change if possible. Run the unit tests by:
66+
67+
```sh
68+
yarn test
69+
```
70+
71+
### Commit message convention
72+
73+
We follow the [conventional commits specification](https://www.conventionalcommits.org/en) for our commit messages:
74+
75+
- `fix`: bug fixes, e.g. fix crash due to deprecated method.
76+
- `feat`: new features, e.g. add new method to the module.
77+
- `refactor`: code refactor, e.g. migrate from class components to hooks.
78+
- `docs`: changes into documentation, e.g. add usage example for the module..
79+
- `test`: adding or updating tests, e.g. add integration tests using detox.
80+
- `chore`: tooling changes, e.g. change CI config.
81+
82+
Our pre-commit hooks verify that your commit message matches this format when committing.
83+
84+
### Linting and tests
85+
86+
[ESLint](https://eslint.org/), [Prettier](https://prettier.io/), [TypeScript](https://www.typescriptlang.org/)
87+
88+
We use [TypeScript](https://www.typescriptlang.org/) for type checking, [ESLint](https://eslint.org/) with [Prettier](https://prettier.io/) for linting and formatting the code, and [Jest](https://jestjs.io/) for testing.
89+
90+
Our pre-commit hooks verify that the linter and tests pass when committing.
91+
92+
### Publishing to npm
93+
94+
We use [release-it](https://github.com/release-it/release-it) to make it easier to publish new versions. It handles common tasks like bumping version based on semver, creating tags and releases etc.
95+
96+
To publish new versions, run the following:
97+
98+
```sh
99+
yarn release
100+
```
101+
102+
### Scripts
103+
104+
The `package.json` file contains various scripts for common tasks:
105+
106+
- `yarn`: setup project by installing dependencies and pods - run with `POD_INSTALL=0` to skip installing pods.
107+
- `yarn typecheck`: type-check files with TypeScript.
108+
- `yarn lint`: lint files with ESLint.
109+
- `yarn test`: run unit tests with Jest.
110+
- `yarn example start`: start the Metro server for the example app.
111+
- `yarn example android`: run the example app on Android.
112+
- `yarn example ios`: run the example app on iOS.
113+
114+
### Sending a pull request
115+
116+
> **Working on your first pull request?** You can learn how from this _free_ series: [How to Contribute to an Open Source Project on GitHub](https://app.egghead.io/playlists/how-to-contribute-to-an-open-source-project-on-github).
117+
118+
When you're sending a pull request:
119+
120+
- Prefer small pull requests focused on one change.
121+
- Verify that linters and tests are passing.
122+
- Review the documentation to make sure it looks good.
123+
- Follow the pull request template when opening a pull request.
124+
- For pull requests that change the API or implementation, discuss with maintainers first by opening an issue.

‎LICENSE

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Maciej Jastrzebski
4+
Permission is hereby granted, free of charge, to any person obtaining a copy
5+
of this software and associated documentation files (the "Software"), to deal
6+
in the Software without restriction, including without limitation the rights
7+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the Software is
9+
furnished to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in all
12+
copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
SOFTWARE.

‎README.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# swift-regex
2+
3+
Adapation of Swift Regex for TypeScript
4+
5+
## Installation
6+
7+
```sh
8+
npm install swift-regex
9+
```
10+
11+
## Usage
12+
13+
```js
14+
import { multiply } from 'swift-regex';
15+
16+
// ...
17+
18+
const result = await multiply(3, 7);
19+
```
20+
21+
## Contributing
22+
23+
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
24+
25+
## License
26+
27+
MIT
28+
29+
---
30+
31+
Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)

‎babel.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
presets: ['module:metro-react-native-babel-preset'],
3+
};

‎example/App.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './src/App';

‎example/app.json

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"expo": {
3+
"name": "example",
4+
"slug": "example",
5+
"version": "1.0.0",
6+
"orientation": "portrait",
7+
"icon": "./assets/icon.png",
8+
"userInterfaceStyle": "light",
9+
"splash": {
10+
"image": "./assets/splash.png",
11+
"resizeMode": "contain",
12+
"backgroundColor": "#ffffff"
13+
},
14+
"assetBundlePatterns": [
15+
"**/*"
16+
],
17+
"ios": {
18+
"supportsTablet": true
19+
},
20+
"android": {
21+
"adaptiveIcon": {
22+
"foregroundImage": "./assets/adaptive-icon.png",
23+
"backgroundColor": "#ffffff"
24+
}
25+
},
26+
"web": {
27+
"favicon": "./assets/favicon.png"
28+
}
29+
}
30+
}

‎example/assets/adaptive-icon.png

17.1 KB
Loading

‎example/assets/favicon.png

1.43 KB
Loading

‎example/assets/icon.png

21.9 KB
Loading

‎example/assets/splash.png

46.2 KB
Loading

‎example/babel.config.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const path = require('path');
2+
const pak = require('../package.json');
3+
4+
module.exports = function (api) {
5+
api.cache(true);
6+
7+
return {
8+
presets: ['babel-preset-expo'],
9+
plugins: [
10+
[
11+
'module-resolver',
12+
{
13+
extensions: ['.tsx', '.ts', '.js', '.json'],
14+
alias: {
15+
// For development, we want to alias the library to the source
16+
[pak.name]: path.join(__dirname, '..', pak.source),
17+
},
18+
},
19+
],
20+
],
21+
};
22+
};

‎example/metro.config.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const path = require('path');
2+
const escape = require('escape-string-regexp');
3+
const { getDefaultConfig } = require('@expo/metro-config');
4+
const exclusionList = require('metro-config/src/defaults/exclusionList');
5+
const pak = require('../package.json');
6+
7+
const root = path.resolve(__dirname, '..');
8+
const modules = Object.keys({ ...pak.peerDependencies });
9+
10+
const defaultConfig = getDefaultConfig(__dirname);
11+
12+
/**
13+
* Metro configuration
14+
* https://facebook.github.io/metro/docs/configuration
15+
*
16+
* @type {import('metro-config').MetroConfig}
17+
*/
18+
const config = {
19+
...defaultConfig,
20+
21+
projectRoot: __dirname,
22+
watchFolders: [root],
23+
24+
// We need to make sure that only one version is loaded for peerDependencies
25+
// So we block them at the root, and alias them to the versions in example's node_modules
26+
resolver: {
27+
...defaultConfig.resolver,
28+
29+
blacklistRE: exclusionList(
30+
modules.map(
31+
(m) =>
32+
new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`)
33+
)
34+
),
35+
36+
extraNodeModules: modules.reduce((acc, name) => {
37+
acc[name] = path.join(__dirname, 'node_modules', name);
38+
return acc;
39+
}, {}),
40+
},
41+
};
42+
43+
module.exports = config;

‎example/package.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "swift-regex-example",
3+
"version": "1.0.0",
4+
"main": "node_modules/expo/AppEntry.js",
5+
"scripts": {
6+
"start": "expo start",
7+
"android": "expo start --android",
8+
"ios": "expo start --ios",
9+
"web": "expo start --web"
10+
},
11+
"dependencies": {
12+
"expo": "~49.0.15",
13+
"expo-status-bar": "~1.6.0",
14+
"react": "18.2.0",
15+
"react-native": "0.72.6",
16+
"react-dom": "18.2.0",
17+
"react-native-web": "~0.19.6"
18+
},
19+
"devDependencies": {
20+
"@babel/core": "^7.20.0",
21+
"babel-plugin-module-resolver": "^5.0.0",
22+
"@expo/webpack-config": "^18.0.1",
23+
"babel-loader": "^8.1.0"
24+
},
25+
"private": true
26+
}

‎example/src/App.tsx

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import * as React from 'react';
2+
3+
import { StyleSheet, View, Text } from 'react-native';
4+
import { multiply } from 'swift-regex';
5+
6+
export default function App() {
7+
const [result, setResult] = React.useState<number | undefined>();
8+
9+
React.useEffect(() => {
10+
multiply(3, 7).then(setResult);
11+
}, []);
12+
13+
return (
14+
<View style={styles.container}>
15+
<Text>Result: {result}</Text>
16+
</View>
17+
);
18+
}
19+
20+
const styles = StyleSheet.create({
21+
container: {
22+
flex: 1,
23+
alignItems: 'center',
24+
justifyContent: 'center',
25+
},
26+
box: {
27+
width: 60,
28+
height: 60,
29+
marginVertical: 20,
30+
},
31+
});

‎example/tsconfig.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "../tsconfig",
3+
"compilerOptions": {
4+
// Avoid expo-cli auto-generating a tsconfig
5+
}
6+
}

‎example/webpack.config.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const path = require('path');
2+
const createExpoWebpackConfigAsync = require('@expo/webpack-config');
3+
const { resolver } = require('./metro.config');
4+
5+
const root = path.resolve(__dirname, '..');
6+
const node_modules = path.join(__dirname, 'node_modules');
7+
8+
module.exports = async function (env, argv) {
9+
const config = await createExpoWebpackConfigAsync(env, argv);
10+
11+
config.module.rules.push({
12+
test: /\.(js|jsx|ts|tsx)$/,
13+
include: path.resolve(root, 'src'),
14+
use: 'babel-loader',
15+
});
16+
17+
// We need to make sure that only one version is loaded for peerDependencies
18+
// So we alias them to the versions in example's node_modules
19+
Object.assign(config.resolve.alias, {
20+
...resolver.extraNodeModules,
21+
'react-native-web': path.join(node_modules, 'react-native-web'),
22+
});
23+
24+
return config;
25+
};

‎lefthook.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
pre-commit:
2+
parallel: true
3+
commands:
4+
lint:
5+
glob: "*.{js,ts,jsx,tsx}"
6+
run: npx eslint {staged_files}
7+
types:
8+
glob: "*.{js,ts, jsx, tsx}"
9+
run: npx tsc --noEmit
10+
commit-msg:
11+
parallel: true
12+
commands:
13+
commitlint:
14+
run: npx commitlint --edit

‎package.json

+160
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
{
2+
"name": "swift-regex",
3+
"version": "0.1.0",
4+
"description": "Adapation of Swift Regex for TypeScript",
5+
"main": "lib/commonjs/index",
6+
"module": "lib/module/index",
7+
"types": "lib/typescript/src/index.d.ts",
8+
"react-native": "src/index",
9+
"source": "src/index",
10+
"files": [
11+
"src",
12+
"lib",
13+
"android",
14+
"ios",
15+
"cpp",
16+
"*.podspec",
17+
"!ios/build",
18+
"!android/build",
19+
"!android/gradle",
20+
"!android/gradlew",
21+
"!android/gradlew.bat",
22+
"!android/local.properties",
23+
"!**/__tests__",
24+
"!**/__fixtures__",
25+
"!**/__mocks__",
26+
"!**/.*"
27+
],
28+
"scripts": {
29+
"example": "yarn workspace swift-regex-example",
30+
"test": "jest",
31+
"typecheck": "tsc --noEmit",
32+
"lint": "eslint \"**/*.{js,ts,tsx}\"",
33+
"clean": "del-cli lib",
34+
"prepare": "bob build",
35+
"release": "release-it"
36+
},
37+
"keywords": [
38+
"react-native",
39+
"ios",
40+
"android"
41+
],
42+
"repository": "https://github.com/mdjastrzebski/swift-regex",
43+
"author": "Maciej Jastrzebski <mdjastrzebski@gmail.com> (https://github.com/mdjastrzebski)",
44+
"license": "MIT",
45+
"bugs": {
46+
"url": "https://github.com/mdjastrzebski/swift-regex/issues"
47+
},
48+
"homepage": "https://github.com/mdjastrzebski/swift-regex#readme",
49+
"publishConfig": {
50+
"registry": "https://registry.npmjs.org/"
51+
},
52+
"devDependencies": {
53+
"@commitlint/config-conventional": "^17.0.2",
54+
"@evilmartians/lefthook": "^1.5.0",
55+
"@react-native/eslint-config": "^0.72.2",
56+
"@release-it/conventional-changelog": "^5.0.0",
57+
"@types/jest": "^28.1.2",
58+
"@types/react": "~17.0.21",
59+
"@types/react-native": "0.70.0",
60+
"commitlint": "^17.0.2",
61+
"del-cli": "^5.0.0",
62+
"eslint": "^8.4.1",
63+
"eslint-config-prettier": "^8.5.0",
64+
"eslint-plugin-prettier": "^4.0.0",
65+
"jest": "^28.1.1",
66+
"prettier": "^2.0.5",
67+
"react": "18.2.0",
68+
"react-native": "0.72.6",
69+
"react-native-builder-bob": "^0.20.0",
70+
"release-it": "^15.0.0",
71+
"typescript": "^5.0.2"
72+
},
73+
"resolutions": {
74+
"@types/react": "17.0.21"
75+
},
76+
"peerDependencies": {
77+
"react": "*",
78+
"react-native": "*"
79+
},
80+
"workspaces": [
81+
"example"
82+
],
83+
"packageManager": "yarn@3.6.1",
84+
"engines": {
85+
"node": ">= 18.0.0"
86+
},
87+
"jest": {
88+
"preset": "react-native",
89+
"modulePathIgnorePatterns": [
90+
"<rootDir>/example/node_modules",
91+
"<rootDir>/lib/"
92+
]
93+
},
94+
"commitlint": {
95+
"extends": [
96+
"@commitlint/config-conventional"
97+
]
98+
},
99+
"release-it": {
100+
"git": {
101+
"commitMessage": "chore: release ${version}",
102+
"tagName": "v${version}"
103+
},
104+
"npm": {
105+
"publish": true
106+
},
107+
"github": {
108+
"release": true
109+
},
110+
"plugins": {
111+
"@release-it/conventional-changelog": {
112+
"preset": "angular"
113+
}
114+
}
115+
},
116+
"eslintConfig": {
117+
"root": true,
118+
"extends": [
119+
"@react-native",
120+
"prettier"
121+
],
122+
"rules": {
123+
"prettier/prettier": [
124+
"error",
125+
{
126+
"quoteProps": "consistent",
127+
"singleQuote": true,
128+
"tabWidth": 2,
129+
"trailingComma": "es5",
130+
"useTabs": false
131+
}
132+
]
133+
}
134+
},
135+
"eslintIgnore": [
136+
"node_modules/",
137+
"lib/"
138+
],
139+
"prettier": {
140+
"quoteProps": "consistent",
141+
"singleQuote": true,
142+
"tabWidth": 2,
143+
"trailingComma": "es5",
144+
"useTabs": false
145+
},
146+
"react-native-builder-bob": {
147+
"source": "src",
148+
"output": "lib",
149+
"targets": [
150+
"commonjs",
151+
"module",
152+
[
153+
"typescript",
154+
{
155+
"project": "tsconfig.build.json"
156+
}
157+
]
158+
]
159+
}
160+
}

‎src/__tests__/index.test.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
it.todo('write a test');

‎src/index.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function multiply(a: number, b: number): Promise<number> {
2+
return Promise.resolve(a * b);
3+
}

‎tsconfig.build.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
{
3+
"extends": "./tsconfig",
4+
"exclude": ["example"]
5+
}

‎tsconfig.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"compilerOptions": {
3+
"rootDir": ".",
4+
"paths": {
5+
"swift-regex": ["./src/index"]
6+
},
7+
"allowUnreachableCode": false,
8+
"allowUnusedLabels": false,
9+
"esModuleInterop": true,
10+
"forceConsistentCasingInFileNames": true,
11+
"jsx": "react",
12+
"lib": ["esnext"],
13+
"module": "esnext",
14+
"moduleResolution": "node",
15+
"noFallthroughCasesInSwitch": true,
16+
"noImplicitReturns": true,
17+
"noImplicitUseStrict": false,
18+
"noStrictGenericChecks": false,
19+
"noUncheckedIndexedAccess": true,
20+
"noUnusedLocals": true,
21+
"noUnusedParameters": true,
22+
"resolveJsonModule": true,
23+
"skipLibCheck": true,
24+
"strict": true,
25+
"target": "esnext",
26+
"verbatimModuleSyntax": true
27+
}
28+
}

0 commit comments

Comments
 (0)
Please sign in to comment.