summaryrefslogtreecommitdiffstats
path: root/llparse-builder/src/transform
diff options
context:
space:
mode:
Diffstat (limited to 'llparse-builder/src/transform')
-rw-r--r--llparse-builder/src/transform/base.ts12
-rw-r--r--llparse-builder/src/transform/creator.ts28
-rw-r--r--llparse-builder/src/transform/index.ts3
-rw-r--r--llparse-builder/src/transform/to-lower-unsafe.ts7
-rw-r--r--llparse-builder/src/transform/to-lower.ts7
5 files changed, 57 insertions, 0 deletions
diff --git a/llparse-builder/src/transform/base.ts b/llparse-builder/src/transform/base.ts
new file mode 100644
index 0000000..902199c
--- /dev/null
+++ b/llparse-builder/src/transform/base.ts
@@ -0,0 +1,12 @@
+export type TransformName = 'to_lower_unsafe' | 'to_lower';
+
+/**
+ * Character transformation.
+ */
+export abstract class Transform {
+ /**
+ * @param name Transform name
+ */
+ constructor(public readonly name: TransformName) {
+ }
+}
diff --git a/llparse-builder/src/transform/creator.ts b/llparse-builder/src/transform/creator.ts
new file mode 100644
index 0000000..eaf3d5c
--- /dev/null
+++ b/llparse-builder/src/transform/creator.ts
@@ -0,0 +1,28 @@
+import { Transform } from './base';
+import { ToLower } from './to-lower';
+import { ToLowerUnsafe } from './to-lower-unsafe';
+
+/**
+ * API for creating character transformations.
+ *
+ * The results of methods of this class can be used as an argument to:
+ * `p.node().transform(...)`.
+ */
+export class Creator {
+ /**
+ * Unsafe transform to lowercase.
+ *
+ * The operation of this transformation is equivalent to:
+ * `String.fromCharCode(input.charCodeAt(0) | 0x20)`.
+ */
+ public toLowerUnsafe(): Transform {
+ return new ToLowerUnsafe();
+ }
+
+ /**
+ * Safe transform to lowercase.
+ */
+ public toLower(): Transform {
+ return new ToLower();
+ }
+}
diff --git a/llparse-builder/src/transform/index.ts b/llparse-builder/src/transform/index.ts
new file mode 100644
index 0000000..acdcf01
--- /dev/null
+++ b/llparse-builder/src/transform/index.ts
@@ -0,0 +1,3 @@
+export { Transform } from './base';
+export { Creator } from './creator';
+export { ToLowerUnsafe } from './to-lower-unsafe';
diff --git a/llparse-builder/src/transform/to-lower-unsafe.ts b/llparse-builder/src/transform/to-lower-unsafe.ts
new file mode 100644
index 0000000..99d9618
--- /dev/null
+++ b/llparse-builder/src/transform/to-lower-unsafe.ts
@@ -0,0 +1,7 @@
+import { Transform } from './base';
+
+export class ToLowerUnsafe extends Transform {
+ constructor() {
+ super('to_lower_unsafe');
+ }
+}
diff --git a/llparse-builder/src/transform/to-lower.ts b/llparse-builder/src/transform/to-lower.ts
new file mode 100644
index 0000000..b333fce
--- /dev/null
+++ b/llparse-builder/src/transform/to-lower.ts
@@ -0,0 +1,7 @@
+import { Transform } from './base';
+
+export class ToLower extends Transform {
+ constructor() {
+ super('to_lower');
+ }
+}