@sanjai-plugin/myplugin 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Myplugin.podspec +17 -0
- package/Package.swift +28 -0
- package/README.md +37 -0
- package/android/build.gradle +58 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/myvalidator/plugins/team/validator.java +11 -0
- package/android/src/main/java/com/myvalidator/plugins/team/validatorPlugin.java +44 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +31 -0
- package/dist/esm/definitions.d.ts +10 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +12 -0
- package/dist/esm/web.js +28 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +42 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +45 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/validatorPlugin/validator.swift +8 -0
- package/ios/Sources/validatorPlugin/validatorPlugin.swift +23 -0
- package/ios/Tests/validatorPluginTests/validatorTests.swift +15 -0
- package/package.json +80 -0
package/Myplugin.podspec
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = 'Myplugin'
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = package['description']
|
|
9
|
+
s.license = package['license']
|
|
10
|
+
s.homepage = package['repository']['url']
|
|
11
|
+
s.author = package['author']
|
|
12
|
+
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
|
|
13
|
+
s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
|
|
14
|
+
s.ios.deployment_target = '15.0'
|
|
15
|
+
s.dependency 'Capacitor'
|
|
16
|
+
s.swift_version = '5.1'
|
|
17
|
+
end
|
package/Package.swift
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// swift-tools-version: 5.9
|
|
2
|
+
import PackageDescription
|
|
3
|
+
|
|
4
|
+
let package = Package(
|
|
5
|
+
name: "Myplugin",
|
|
6
|
+
platforms: [.iOS(.v15)],
|
|
7
|
+
products: [
|
|
8
|
+
.library(
|
|
9
|
+
name: "Myplugin",
|
|
10
|
+
targets: ["validatorPlugin"])
|
|
11
|
+
],
|
|
12
|
+
dependencies: [
|
|
13
|
+
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0")
|
|
14
|
+
],
|
|
15
|
+
targets: [
|
|
16
|
+
.target(
|
|
17
|
+
name: "validatorPlugin",
|
|
18
|
+
dependencies: [
|
|
19
|
+
.product(name: "Capacitor", package: "capacitor-swift-pm"),
|
|
20
|
+
.product(name: "Cordova", package: "capacitor-swift-pm")
|
|
21
|
+
],
|
|
22
|
+
path: "ios/Sources/validatorPlugin"),
|
|
23
|
+
.testTarget(
|
|
24
|
+
name: "validatorPluginTests",
|
|
25
|
+
dependencies: ["validatorPlugin"],
|
|
26
|
+
path: "ios/Tests/validatorPluginTests")
|
|
27
|
+
]
|
|
28
|
+
)
|
package/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# myplugin
|
|
2
|
+
|
|
3
|
+
demo purpose
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install myplugin
|
|
9
|
+
npx cap sync
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## API
|
|
13
|
+
|
|
14
|
+
<docgen-index>
|
|
15
|
+
|
|
16
|
+
* [`validateField(...)`](#validatefield)
|
|
17
|
+
|
|
18
|
+
</docgen-index>
|
|
19
|
+
|
|
20
|
+
<docgen-api>
|
|
21
|
+
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
|
|
22
|
+
|
|
23
|
+
### validateField(...)
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
validateField(options: { value: string; rule: string; minLength?: number; }) => Promise<{ valid: boolean; message: string; }>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
| Param | Type |
|
|
30
|
+
| ------------- | ----------------------------------------------------------------- |
|
|
31
|
+
| **`options`** | <code>{ value: string; rule: string; minLength?: number; }</code> |
|
|
32
|
+
|
|
33
|
+
**Returns:** <code>Promise<{ valid: boolean; message: string; }></code>
|
|
34
|
+
|
|
35
|
+
--------------------
|
|
36
|
+
|
|
37
|
+
</docgen-api>
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
ext {
|
|
2
|
+
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
|
|
4
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
|
|
5
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.7.0'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
buildscript {
|
|
9
|
+
repositories {
|
|
10
|
+
google()
|
|
11
|
+
mavenCentral()
|
|
12
|
+
}
|
|
13
|
+
dependencies {
|
|
14
|
+
classpath 'com.android.tools.build:gradle:8.13.0'
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
apply plugin: 'com.android.library'
|
|
19
|
+
|
|
20
|
+
android {
|
|
21
|
+
namespace = "com.myvalidator.plugins.team"
|
|
22
|
+
compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
|
|
23
|
+
defaultConfig {
|
|
24
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 24
|
|
25
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
|
|
26
|
+
versionCode 1
|
|
27
|
+
versionName "1.0"
|
|
28
|
+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
29
|
+
}
|
|
30
|
+
buildTypes {
|
|
31
|
+
release {
|
|
32
|
+
minifyEnabled false
|
|
33
|
+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
lintOptions {
|
|
37
|
+
abortOnError = false
|
|
38
|
+
}
|
|
39
|
+
compileOptions {
|
|
40
|
+
sourceCompatibility JavaVersion.VERSION_21
|
|
41
|
+
targetCompatibility JavaVersion.VERSION_21
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
repositories {
|
|
46
|
+
google()
|
|
47
|
+
mavenCentral()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
dependencies {
|
|
52
|
+
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
53
|
+
implementation project(':capacitor-android')
|
|
54
|
+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
55
|
+
testImplementation "junit:junit:$junitVersion"
|
|
56
|
+
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
57
|
+
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
58
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
package com.myvalidator.plugins.team;
|
|
2
|
+
|
|
3
|
+
import com.getcapacitor.JSObject;
|
|
4
|
+
import com.getcapacitor.Plugin;
|
|
5
|
+
import com.getcapacitor.PluginCall;
|
|
6
|
+
import com.getcapacitor.PluginMethod;
|
|
7
|
+
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
8
|
+
|
|
9
|
+
@CapacitorPlugin(name = "Validator")
|
|
10
|
+
public class ValidatorPlugin extends Plugin {
|
|
11
|
+
|
|
12
|
+
@PluginMethod
|
|
13
|
+
public void validateField(PluginCall call) {
|
|
14
|
+
String value = call.getString("value");
|
|
15
|
+
String rule = call.getString("rule");
|
|
16
|
+
Integer minLength = call.getInt("minLength", 0);
|
|
17
|
+
|
|
18
|
+
boolean valid = true;
|
|
19
|
+
String message = "";
|
|
20
|
+
|
|
21
|
+
switch (rule) {
|
|
22
|
+
case "required":
|
|
23
|
+
valid = value != null && !value.trim().isEmpty();
|
|
24
|
+
message = valid ? "" : "This field is required.";
|
|
25
|
+
break;
|
|
26
|
+
|
|
27
|
+
case "email":
|
|
28
|
+
valid = android.util.Patterns.EMAIL_ADDRESS.matcher(value).matches();
|
|
29
|
+
message = valid ? "" : "Invalid email format.";
|
|
30
|
+
break;
|
|
31
|
+
|
|
32
|
+
case "minLength":
|
|
33
|
+
valid = value.length() >= minLength;
|
|
34
|
+
message = valid ? "" : "Minimum length is " + minLength;
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
JSObject ret = new JSObject();
|
|
39
|
+
ret.put("valid", valid);
|
|
40
|
+
ret.put("message", message);
|
|
41
|
+
|
|
42
|
+
call.resolve(ret);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
File without changes
|
package/dist/docs.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"api": {
|
|
3
|
+
"name": "ValidatorPlugin",
|
|
4
|
+
"slug": "validatorplugin",
|
|
5
|
+
"docs": "",
|
|
6
|
+
"tags": [],
|
|
7
|
+
"methods": [
|
|
8
|
+
{
|
|
9
|
+
"name": "validateField",
|
|
10
|
+
"signature": "(options: { value: string; rule: string; minLength?: number; }) => Promise<{ valid: boolean; message: string; }>",
|
|
11
|
+
"parameters": [
|
|
12
|
+
{
|
|
13
|
+
"name": "options",
|
|
14
|
+
"docs": "",
|
|
15
|
+
"type": "{ value: string; rule: string; minLength?: number | undefined; }"
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
"returns": "Promise<{ valid: boolean; message: string; }>",
|
|
19
|
+
"tags": [],
|
|
20
|
+
"docs": "",
|
|
21
|
+
"complexTypes": [],
|
|
22
|
+
"slug": "validatefield"
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
"properties": []
|
|
26
|
+
},
|
|
27
|
+
"interfaces": [],
|
|
28
|
+
"enums": [],
|
|
29
|
+
"typeAliases": [],
|
|
30
|
+
"pluginConfigs": []
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface ValidatorPlugin {\n validateField(options: {\n value: string;\n rule: string; // 'required' | 'email' | 'minLength'\n minLength?: number;\n }): Promise<{ valid: boolean; message: string }>;\n}"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,SAAS,GAAG,cAAc,CAAkB,WAAW,EAAE;IAC7D,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,CAAC;CAC7D,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,SAAS,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { ValidatorPlugin } from './definitions';\n\nconst Validator = registerPlugin<ValidatorPlugin>('Validator', {\n web: () => import('./web').then((m) => new m.ValidatorWeb()),\n});\n\nexport * from './definitions';\nexport { Validator };"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import type { ValidatorPlugin } from './definitions';
|
|
3
|
+
export declare class ValidatorWeb extends WebPlugin implements ValidatorPlugin {
|
|
4
|
+
validateField(options: {
|
|
5
|
+
value: string;
|
|
6
|
+
rule: string;
|
|
7
|
+
minLength?: number;
|
|
8
|
+
}): Promise<{
|
|
9
|
+
valid: boolean;
|
|
10
|
+
message: string;
|
|
11
|
+
}>;
|
|
12
|
+
}
|
package/dist/esm/web.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
export class ValidatorWeb extends WebPlugin {
|
|
3
|
+
async validateField(options) {
|
|
4
|
+
const { value, rule, minLength } = options;
|
|
5
|
+
let valid = true;
|
|
6
|
+
let message = '';
|
|
7
|
+
switch (rule) {
|
|
8
|
+
case 'required':
|
|
9
|
+
valid = value.trim().length > 0;
|
|
10
|
+
message = valid ? '' : 'This field is required.';
|
|
11
|
+
break;
|
|
12
|
+
case 'email':
|
|
13
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
14
|
+
valid = emailRegex.test(value);
|
|
15
|
+
message = valid ? '' : 'Invalid email format.';
|
|
16
|
+
break;
|
|
17
|
+
case 'minLength':
|
|
18
|
+
valid = value.length >= (minLength !== null && minLength !== void 0 ? minLength : 0);
|
|
19
|
+
message = valid ? '' : `Minimum length is ${minLength}`;
|
|
20
|
+
break;
|
|
21
|
+
default:
|
|
22
|
+
valid = true;
|
|
23
|
+
message = '';
|
|
24
|
+
}
|
|
25
|
+
return { valid, message };
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,MAAM,OAAO,YAAa,SAAQ,SAAS;IACzC,KAAK,CAAC,aAAa,CAAC,OAInB;QACC,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;QAE3C,IAAI,KAAK,GAAG,IAAI,CAAC;QACjB,IAAI,OAAO,GAAG,EAAE,CAAC;QAEjB,QAAQ,IAAI,EAAE,CAAC;YACb,KAAK,UAAU;gBACb,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;gBAChC,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,yBAAyB,CAAC;gBACjD,MAAM;YAER,KAAK,OAAO;gBACV,MAAM,UAAU,GAAG,4BAA4B,CAAC;gBAChD,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBAC/B,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,uBAAuB,CAAC;gBAC/C,MAAM;YAER,KAAK,WAAW;gBACd,KAAK,GAAG,KAAK,CAAC,MAAM,IAAI,CAAC,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,CAAC,CAAC,CAAC;gBACzC,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,qBAAqB,SAAS,EAAE,CAAC;gBACxD,MAAM;YAER;gBACE,KAAK,GAAG,IAAI,CAAC;gBACb,OAAO,GAAG,EAAE,CAAC;QACjB,CAAC;QAED,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;IAC5B,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type { ValidatorPlugin } from './definitions';\n\nexport class ValidatorWeb extends WebPlugin implements ValidatorPlugin {\n async validateField(options: {\n value: string;\n rule: string;\n minLength?: number;\n }): Promise<{ valid: boolean; message: string }> {\n const { value, rule, minLength } = options;\n\n let valid = true;\n let message = '';\n\n switch (rule) {\n case 'required':\n valid = value.trim().length > 0;\n message = valid ? '' : 'This field is required.';\n break;\n\n case 'email':\n const emailRegex = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\n valid = emailRegex.test(value);\n message = valid ? '' : 'Invalid email format.';\n break;\n\n case 'minLength':\n valid = value.length >= (minLength ?? 0);\n message = valid ? '' : `Minimum length is ${minLength}`;\n break;\n\n default:\n valid = true;\n message = '';\n }\n\n return { valid, message };\n }\n}"]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@capacitor/core');
|
|
4
|
+
|
|
5
|
+
const Validator = core.registerPlugin('Validator', {
|
|
6
|
+
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.ValidatorWeb()),
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
class ValidatorWeb extends core.WebPlugin {
|
|
10
|
+
async validateField(options) {
|
|
11
|
+
const { value, rule, minLength } = options;
|
|
12
|
+
let valid = true;
|
|
13
|
+
let message = '';
|
|
14
|
+
switch (rule) {
|
|
15
|
+
case 'required':
|
|
16
|
+
valid = value.trim().length > 0;
|
|
17
|
+
message = valid ? '' : 'This field is required.';
|
|
18
|
+
break;
|
|
19
|
+
case 'email':
|
|
20
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
21
|
+
valid = emailRegex.test(value);
|
|
22
|
+
message = valid ? '' : 'Invalid email format.';
|
|
23
|
+
break;
|
|
24
|
+
case 'minLength':
|
|
25
|
+
valid = value.length >= (minLength !== null && minLength !== void 0 ? minLength : 0);
|
|
26
|
+
message = valid ? '' : `Minimum length is ${minLength}`;
|
|
27
|
+
break;
|
|
28
|
+
default:
|
|
29
|
+
valid = true;
|
|
30
|
+
message = '';
|
|
31
|
+
}
|
|
32
|
+
return { valid, message };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
37
|
+
__proto__: null,
|
|
38
|
+
ValidatorWeb: ValidatorWeb
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
exports.Validator = Validator;
|
|
42
|
+
//# sourceMappingURL=plugin.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst Validator = registerPlugin('Validator', {\n web: () => import('./web').then((m) => new m.ValidatorWeb()),\n});\nexport * from './definitions';\nexport { Validator };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class ValidatorWeb extends WebPlugin {\n async validateField(options) {\n const { value, rule, minLength } = options;\n let valid = true;\n let message = '';\n switch (rule) {\n case 'required':\n valid = value.trim().length > 0;\n message = valid ? '' : 'This field is required.';\n break;\n case 'email':\n const emailRegex = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\n valid = emailRegex.test(value);\n message = valid ? '' : 'Invalid email format.';\n break;\n case 'minLength':\n valid = value.length >= (minLength !== null && minLength !== void 0 ? minLength : 0);\n message = valid ? '' : `Minimum length is ${minLength}`;\n break;\n default:\n valid = true;\n message = '';\n }\n return { valid, message };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,SAAS,GAAGA,mBAAc,CAAC,WAAW,EAAE;AAC9C,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,YAAY,EAAE,CAAC;AAChE,CAAC;;ACFM,MAAM,YAAY,SAASC,cAAS,CAAC;AAC5C,IAAI,MAAM,aAAa,CAAC,OAAO,EAAE;AACjC,QAAQ,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,OAAO;AAClD,QAAQ,IAAI,KAAK,GAAG,IAAI;AACxB,QAAQ,IAAI,OAAO,GAAG,EAAE;AACxB,QAAQ,QAAQ,IAAI;AACpB,YAAY,KAAK,UAAU;AAC3B,gBAAgB,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC;AAC/C,gBAAgB,OAAO,GAAG,KAAK,GAAG,EAAE,GAAG,yBAAyB;AAChE,gBAAgB;AAChB,YAAY,KAAK,OAAO;AACxB,gBAAgB,MAAM,UAAU,GAAG,4BAA4B;AAC/D,gBAAgB,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC;AAC9C,gBAAgB,OAAO,GAAG,KAAK,GAAG,EAAE,GAAG,uBAAuB;AAC9D,gBAAgB;AAChB,YAAY,KAAK,WAAW;AAC5B,gBAAgB,KAAK,GAAG,KAAK,CAAC,MAAM,KAAK,SAAS,KAAK,IAAI,IAAI,SAAS,KAAK,MAAM,GAAG,SAAS,GAAG,CAAC,CAAC;AACpG,gBAAgB,OAAO,GAAG,KAAK,GAAG,EAAE,GAAG,CAAC,kBAAkB,EAAE,SAAS,CAAC,CAAC;AACvE,gBAAgB;AAChB,YAAY;AACZ,gBAAgB,KAAK,GAAG,IAAI;AAC5B,gBAAgB,OAAO,GAAG,EAAE;AAC5B;AACA,QAAQ,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE;AACjC,IAAI;AACJ;;;;;;;;;"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
var capacitorvalidator = (function (exports, core) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const Validator = core.registerPlugin('Validator', {
|
|
5
|
+
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.ValidatorWeb()),
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
class ValidatorWeb extends core.WebPlugin {
|
|
9
|
+
async validateField(options) {
|
|
10
|
+
const { value, rule, minLength } = options;
|
|
11
|
+
let valid = true;
|
|
12
|
+
let message = '';
|
|
13
|
+
switch (rule) {
|
|
14
|
+
case 'required':
|
|
15
|
+
valid = value.trim().length > 0;
|
|
16
|
+
message = valid ? '' : 'This field is required.';
|
|
17
|
+
break;
|
|
18
|
+
case 'email':
|
|
19
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
20
|
+
valid = emailRegex.test(value);
|
|
21
|
+
message = valid ? '' : 'Invalid email format.';
|
|
22
|
+
break;
|
|
23
|
+
case 'minLength':
|
|
24
|
+
valid = value.length >= (minLength !== null && minLength !== void 0 ? minLength : 0);
|
|
25
|
+
message = valid ? '' : `Minimum length is ${minLength}`;
|
|
26
|
+
break;
|
|
27
|
+
default:
|
|
28
|
+
valid = true;
|
|
29
|
+
message = '';
|
|
30
|
+
}
|
|
31
|
+
return { valid, message };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
36
|
+
__proto__: null,
|
|
37
|
+
ValidatorWeb: ValidatorWeb
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
exports.Validator = Validator;
|
|
41
|
+
|
|
42
|
+
return exports;
|
|
43
|
+
|
|
44
|
+
})({}, capacitorExports);
|
|
45
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst Validator = registerPlugin('Validator', {\n web: () => import('./web').then((m) => new m.ValidatorWeb()),\n});\nexport * from './definitions';\nexport { Validator };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class ValidatorWeb extends WebPlugin {\n async validateField(options) {\n const { value, rule, minLength } = options;\n let valid = true;\n let message = '';\n switch (rule) {\n case 'required':\n valid = value.trim().length > 0;\n message = valid ? '' : 'This field is required.';\n break;\n case 'email':\n const emailRegex = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\n valid = emailRegex.test(value);\n message = valid ? '' : 'Invalid email format.';\n break;\n case 'minLength':\n valid = value.length >= (minLength !== null && minLength !== void 0 ? minLength : 0);\n message = valid ? '' : `Minimum length is ${minLength}`;\n break;\n default:\n valid = true;\n message = '';\n }\n return { valid, message };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,SAAS,GAAGA,mBAAc,CAAC,WAAW,EAAE;IAC9C,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,YAAY,EAAE,CAAC;IAChE,CAAC;;ICFM,MAAM,YAAY,SAASC,cAAS,CAAC;IAC5C,IAAI,MAAM,aAAa,CAAC,OAAO,EAAE;IACjC,QAAQ,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,OAAO;IAClD,QAAQ,IAAI,KAAK,GAAG,IAAI;IACxB,QAAQ,IAAI,OAAO,GAAG,EAAE;IACxB,QAAQ,QAAQ,IAAI;IACpB,YAAY,KAAK,UAAU;IAC3B,gBAAgB,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC;IAC/C,gBAAgB,OAAO,GAAG,KAAK,GAAG,EAAE,GAAG,yBAAyB;IAChE,gBAAgB;IAChB,YAAY,KAAK,OAAO;IACxB,gBAAgB,MAAM,UAAU,GAAG,4BAA4B;IAC/D,gBAAgB,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC;IAC9C,gBAAgB,OAAO,GAAG,KAAK,GAAG,EAAE,GAAG,uBAAuB;IAC9D,gBAAgB;IAChB,YAAY,KAAK,WAAW;IAC5B,gBAAgB,KAAK,GAAG,KAAK,CAAC,MAAM,KAAK,SAAS,KAAK,IAAI,IAAI,SAAS,KAAK,MAAM,GAAG,SAAS,GAAG,CAAC,CAAC;IACpG,gBAAgB,OAAO,GAAG,KAAK,GAAG,EAAE,GAAG,CAAC,kBAAkB,EAAE,SAAS,CAAC,CAAC;IACvE,gBAAgB;IAChB,YAAY;IACZ,gBAAgB,KAAK,GAAG,IAAI;IAC5B,gBAAgB,OAAO,GAAG,EAAE;IAC5B;IACA,QAAQ,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE;IACjC,IAAI;IACJ;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Please read the Capacitor iOS Plugin Development Guide
|
|
6
|
+
* here: https://capacitorjs.com/docs/plugins/ios
|
|
7
|
+
*/
|
|
8
|
+
@objc(validatorPlugin)
|
|
9
|
+
public class validatorPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
10
|
+
public let identifier = "validatorPlugin"
|
|
11
|
+
public let jsName = "validator"
|
|
12
|
+
public let pluginMethods: [CAPPluginMethod] = [
|
|
13
|
+
CAPPluginMethod(name: "echo", returnType: CAPPluginReturnPromise)
|
|
14
|
+
]
|
|
15
|
+
private let implementation = validator()
|
|
16
|
+
|
|
17
|
+
@objc func echo(_ call: CAPPluginCall) {
|
|
18
|
+
let value = call.getString("value") ?? ""
|
|
19
|
+
call.resolve([
|
|
20
|
+
"value": implementation.echo(value)
|
|
21
|
+
])
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import XCTest
|
|
2
|
+
@testable import validatorPlugin
|
|
3
|
+
|
|
4
|
+
class validatorTests: XCTestCase {
|
|
5
|
+
func testEcho() {
|
|
6
|
+
// This is an example of a functional test case for a plugin.
|
|
7
|
+
// Use XCTAssert and related functions to verify your tests produce the correct results.
|
|
8
|
+
|
|
9
|
+
let implementation = validator()
|
|
10
|
+
let value = "Hello, World!"
|
|
11
|
+
let result = implementation.echo(value)
|
|
12
|
+
|
|
13
|
+
XCTAssertEqual(value, result)
|
|
14
|
+
}
|
|
15
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sanjai-plugin/myplugin",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "demo purpose",
|
|
5
|
+
"main": "dist/plugin.cjs.js",
|
|
6
|
+
"module": "dist/esm/index.js",
|
|
7
|
+
"types": "dist/esm/index.d.ts",
|
|
8
|
+
"unpkg": "dist/plugin.js",
|
|
9
|
+
"files": [
|
|
10
|
+
"android/src/main/",
|
|
11
|
+
"android/build.gradle",
|
|
12
|
+
"dist/",
|
|
13
|
+
"ios/Sources",
|
|
14
|
+
"ios/Tests",
|
|
15
|
+
"Package.swift",
|
|
16
|
+
"Myplugin.podspec"
|
|
17
|
+
],
|
|
18
|
+
"author": "sanjai",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/<user>/<repo>.git"
|
|
23
|
+
},
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/<user>/<repo>/issues"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"capacitor",
|
|
29
|
+
"plugin",
|
|
30
|
+
"native"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|
|
34
|
+
"verify:ios": "xcodebuild -scheme Myplugin -destination generic/platform=iOS",
|
|
35
|
+
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
36
|
+
"verify:web": "npm run build",
|
|
37
|
+
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
38
|
+
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
|
|
39
|
+
"eslint": "eslint . --ext ts",
|
|
40
|
+
"prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
|
|
41
|
+
"swiftlint": "node-swiftlint",
|
|
42
|
+
"docgen": "docgen --api ValidatorPlugin --output-readme README.md --output-json dist/docs.json",
|
|
43
|
+
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
|
|
44
|
+
"clean": "rimraf ./dist",
|
|
45
|
+
"watch": "tsc --watch",
|
|
46
|
+
"prepublishOnly": "npm run build"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@capacitor/android": "^8.0.0",
|
|
50
|
+
"@capacitor/core": "^8.0.0",
|
|
51
|
+
"@capacitor/docgen": "^0.3.1",
|
|
52
|
+
"@capacitor/ios": "^8.0.0",
|
|
53
|
+
"@ionic/eslint-config": "^0.4.0",
|
|
54
|
+
"@ionic/prettier-config": "^4.0.0",
|
|
55
|
+
"@ionic/swiftlint-config": "^2.0.0",
|
|
56
|
+
"eslint": "^8.57.1",
|
|
57
|
+
"prettier": "^3.6.2",
|
|
58
|
+
"prettier-plugin-java": "^2.7.7",
|
|
59
|
+
"rimraf": "^6.1.3",
|
|
60
|
+
"rollup": "^4.53.2",
|
|
61
|
+
"swiftlint": "^2.0.0",
|
|
62
|
+
"typescript": "^5.9.3"
|
|
63
|
+
},
|
|
64
|
+
"peerDependencies": {
|
|
65
|
+
"@capacitor/core": ">=8.0.0"
|
|
66
|
+
},
|
|
67
|
+
"prettier": "@ionic/prettier-config",
|
|
68
|
+
"swiftlint": "@ionic/swiftlint-config",
|
|
69
|
+
"eslintConfig": {
|
|
70
|
+
"extends": "@ionic/eslint-config/recommended"
|
|
71
|
+
},
|
|
72
|
+
"capacitor": {
|
|
73
|
+
"ios": {
|
|
74
|
+
"src": "ios"
|
|
75
|
+
},
|
|
76
|
+
"android": {
|
|
77
|
+
"src": "android"
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|