@expressive/sql 0.1.0 → 0.1.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/package.json +4 -1
- package/.turbo/turbo-build.log +0 -21
- package/src/columns/Bool.ts +0 -64
- package/src/columns/Num.ts +0 -54
- package/src/columns/One.test.ts +0 -131
- package/src/columns/One.ts +0 -49
- package/src/columns/Str.ts +0 -75
- package/src/columns/Time.ts +0 -29
- package/src/connection/Connection.ts +0 -117
- package/src/connection/Generator.ts +0 -303
- package/src/index.ts +0 -14
- package/src/query/Builder.ts +0 -466
- package/src/query/Computed.ts +0 -76
- package/src/query/Query.test.ts +0 -8
- package/src/query/Query.ts +0 -241
- package/src/tests/delete.test.ts +0 -48
- package/src/tests/insert.test.ts +0 -47
- package/src/tests/join.test.ts +0 -242
- package/src/tests/math.test.ts +0 -69
- package/src/tests/select.test.ts +0 -115
- package/src/tests/template.test.ts +0 -16
- package/src/tests/update.test.ts +0 -85
- package/src/tests/where.test.ts +0 -347
- package/src/type/Field.ts +0 -186
- package/src/type/Table.test.ts +0 -24
- package/src/type/Table.ts +0 -31
- package/src/type/Type.test.ts +0 -67
- package/src/type/Type.ts +0 -144
- package/src/utils.ts +0 -59
package/src/type/Field.ts
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import { Query } from '..';
|
|
2
|
-
import { Builder, Cond } from '../query/Builder';
|
|
3
|
-
import { capitalize, create, escape, freeze, getOwnPropertyDescriptor, underscore } from '../utils';
|
|
4
|
-
import { Type } from './Type';
|
|
5
|
-
|
|
6
|
-
const REGISTER = new Map<Type.EntityType, Map<string, Field>>();
|
|
7
|
-
|
|
8
|
-
type Nullable = { nullable: true };
|
|
9
|
-
type Optional = { optional: true };
|
|
10
|
-
|
|
11
|
-
declare namespace Field {
|
|
12
|
-
type Init<T extends Field = Field> = (self: T) => Partial<T> | void;
|
|
13
|
-
|
|
14
|
-
type Opts<T extends Field = Field> = Partial<T> | Init<T>;
|
|
15
|
-
|
|
16
|
-
type Modifier<T, TT extends Field> =
|
|
17
|
-
T extends { nullable: true } ? TT & Nullable :
|
|
18
|
-
T extends { fallback?: any, increment?: true } ? TT & Optional :
|
|
19
|
-
TT;
|
|
20
|
-
|
|
21
|
-
type Specify<T, TT extends Field, D extends Field = TT> =
|
|
22
|
-
Modifier<T, T extends { type: infer U } ? Extract<TT, { type: U }> : D>;
|
|
23
|
-
|
|
24
|
-
type Returns<T> = Field & { get(value: any): T }
|
|
25
|
-
|
|
26
|
-
type Accepts<T> = Field & { set(value: T, data: unknown): void }
|
|
27
|
-
|
|
28
|
-
type Queries<T> = Field & { use(table: Builder): T }
|
|
29
|
-
|
|
30
|
-
type Updates<T> =
|
|
31
|
-
T extends Accepts<infer U> ?
|
|
32
|
-
(T extends Nullable ? U | null : U) | undefined :
|
|
33
|
-
never;
|
|
34
|
-
|
|
35
|
-
type Assigns<T> =
|
|
36
|
-
T extends Accepts<infer U> ?
|
|
37
|
-
T extends Nullable ? U | null | undefined :
|
|
38
|
-
T extends Optional ? U | undefined :
|
|
39
|
-
U :
|
|
40
|
-
never;
|
|
41
|
-
|
|
42
|
-
type Output = Record<string, string | number>;
|
|
43
|
-
|
|
44
|
-
type Compare<T> = {
|
|
45
|
-
is(value: Query.Value<T>): Cond;
|
|
46
|
-
not(value: Query.Value<T>): Cond;
|
|
47
|
-
over(value: Query.Value<T>, orEqual?: boolean): Cond;
|
|
48
|
-
under(value: Query.Value<T>, orEqual?: boolean): Cond;
|
|
49
|
-
in(value: Query.Value<T>[]): Cond;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
class Field<T = unknown> {
|
|
54
|
-
type = "";
|
|
55
|
-
unique = false;
|
|
56
|
-
nullable = false;
|
|
57
|
-
optional = false;
|
|
58
|
-
increment = false;
|
|
59
|
-
fallback?: unknown;
|
|
60
|
-
|
|
61
|
-
property!: string;
|
|
62
|
-
parent!: Type.EntityType;
|
|
63
|
-
|
|
64
|
-
table?: Query.Table;
|
|
65
|
-
query?: Builder;
|
|
66
|
-
|
|
67
|
-
foreignKey?: string;
|
|
68
|
-
foreignTable?: string;
|
|
69
|
-
|
|
70
|
-
/** Real datatype of this field in database. */
|
|
71
|
-
datatype!: string;
|
|
72
|
-
|
|
73
|
-
column!: string;
|
|
74
|
-
|
|
75
|
-
constructor(private options?: Field.Opts){}
|
|
76
|
-
|
|
77
|
-
init(property: string, parent: Type.EntityType): this {
|
|
78
|
-
let options = this.options;
|
|
79
|
-
const field = create(this);
|
|
80
|
-
|
|
81
|
-
field.parent = parent;
|
|
82
|
-
field.property = property;
|
|
83
|
-
field.column = underscore(property);
|
|
84
|
-
|
|
85
|
-
if (typeof options === "function")
|
|
86
|
-
options = options(field) || {};
|
|
87
|
-
|
|
88
|
-
for(const key in options){
|
|
89
|
-
const value = (options as any)[key];
|
|
90
|
-
|
|
91
|
-
if(value !== undefined)
|
|
92
|
-
(field as any)[key] = value;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if(!field.datatype)
|
|
96
|
-
field.datatype = field.type;
|
|
97
|
-
|
|
98
|
-
return field;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Optional method generates value of property this Field is applied to when accessed inside a query.
|
|
103
|
-
* If not defined, the value will be the Field itself.
|
|
104
|
-
*
|
|
105
|
-
* @returns {T} Value to be used in context of query, interfacing with this Field.
|
|
106
|
-
*/
|
|
107
|
-
use?(query: Builder): unknown;
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* This method dictates behavior of this field when converted from a javascript context to SQL.
|
|
111
|
-
*
|
|
112
|
-
* Use this method to validate, sanitize or convert data before it is inserted into the database.
|
|
113
|
-
*/
|
|
114
|
-
set(value: T): any {
|
|
115
|
-
return value;
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* This method dictates behavior of this field when converted from a SQL context to javascript.
|
|
120
|
-
*
|
|
121
|
-
* Use this method to parse data incoming from the database itself. For example, you might convert
|
|
122
|
-
* a TINYINT(1) field to a boolean, or a DATETIME field to a Date object.
|
|
123
|
-
*/
|
|
124
|
-
get(value: any): T {
|
|
125
|
-
return value;
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
raw(value: T): string {
|
|
129
|
-
return escape(this.set(value));
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* This method is used to compare this field with another value in a query.
|
|
134
|
-
*
|
|
135
|
-
* @param acc Set of comparisons to be added to if not part of a group.
|
|
136
|
-
*/
|
|
137
|
-
where(): Field.Compare<T> {
|
|
138
|
-
const use = (op: string) =>
|
|
139
|
-
(right: unknown, orEqual?: boolean) =>
|
|
140
|
-
this.query!.where(this, op + (orEqual ? '=' : ''), right)
|
|
141
|
-
|
|
142
|
-
return <any> {
|
|
143
|
-
is: use("="),
|
|
144
|
-
in: use("IN"),
|
|
145
|
-
not: use("<>"),
|
|
146
|
-
over: use(">"),
|
|
147
|
-
under: use("<")
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function fields(from: Type.EntityType){
|
|
153
|
-
let fields = REGISTER.get(from);
|
|
154
|
-
|
|
155
|
-
if(!fields){
|
|
156
|
-
fields = new Map<string, Field>();
|
|
157
|
-
|
|
158
|
-
REGISTER.set(from, fields);
|
|
159
|
-
|
|
160
|
-
const reference = new (from as any)();
|
|
161
|
-
|
|
162
|
-
for(const key in reference){
|
|
163
|
-
const { value } = getOwnPropertyDescriptor(reference, key)!;
|
|
164
|
-
|
|
165
|
-
if(!(value instanceof Field))
|
|
166
|
-
throw new Error(
|
|
167
|
-
`Entities do not support normal values, only fields. ` +
|
|
168
|
-
`Did you forget to import \`${capitalize(typeof value)}\`?`
|
|
169
|
-
);
|
|
170
|
-
|
|
171
|
-
const instance = value.init(key, from);
|
|
172
|
-
|
|
173
|
-
from.fields.set(key, instance);
|
|
174
|
-
freeze(instance);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
return fields;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
export {
|
|
182
|
-
fields,
|
|
183
|
-
Field,
|
|
184
|
-
Nullable,
|
|
185
|
-
Optional
|
|
186
|
-
};
|
package/src/type/Table.test.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Query, Str, Table, Type } from '..';
|
|
2
|
-
it("will alias types with a schema", () => {
|
|
3
|
-
class Foo extends Type {
|
|
4
|
-
this = Table({ schema: "foobar" });
|
|
5
|
-
|
|
6
|
-
name = Str();
|
|
7
|
-
color = Str();
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const query = Query(where => {
|
|
11
|
-
const foo = where(Foo);
|
|
12
|
-
|
|
13
|
-
where(foo.color).is("red");
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
expect(query).toMatchInlineSnapshot(`
|
|
17
|
-
SELECT
|
|
18
|
-
COUNT(*)
|
|
19
|
-
FROM
|
|
20
|
-
foobar.foo T0
|
|
21
|
-
WHERE
|
|
22
|
-
T0.color = 'red'
|
|
23
|
-
`);
|
|
24
|
-
})
|
package/src/type/Table.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { assign } from '../utils';
|
|
2
|
-
import { Field } from './Field';
|
|
3
|
-
import { Type } from './Type';
|
|
4
|
-
|
|
5
|
-
namespace Table {
|
|
6
|
-
export interface Options {
|
|
7
|
-
name?: string;
|
|
8
|
-
schema?: string;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function Table(name: string, opts?: Table.Options): Type.EntityType;
|
|
13
|
-
function Table(opts: Table.Options): Type.EntityType;
|
|
14
|
-
function Table(arg1: string | Table.Options, arg2?: Table.Options){
|
|
15
|
-
return new Field(({ parent }) => {
|
|
16
|
-
if(typeof arg1 == "string"){
|
|
17
|
-
const [name, schema] = arg1.split(".").reverse();
|
|
18
|
-
|
|
19
|
-
arg1 = { schema, ...arg2, name };
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const { name, ...rest } = arg1;
|
|
23
|
-
|
|
24
|
-
if(name)
|
|
25
|
-
parent.table = name;
|
|
26
|
-
|
|
27
|
-
assign(parent, rest);
|
|
28
|
-
}) as any;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export { Table }
|
package/src/type/Type.test.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { Type, Num } from '..';
|
|
2
|
-
|
|
3
|
-
class Item extends Type {
|
|
4
|
-
number = Num();
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
describe("get method", () => {
|
|
8
|
-
it("will fetch rows", async () => {
|
|
9
|
-
const query = Item.get();
|
|
10
|
-
|
|
11
|
-
expect(query).toMatchInlineSnapshot(`
|
|
12
|
-
SELECT
|
|
13
|
-
item.id AS "id",
|
|
14
|
-
item.number AS "number"
|
|
15
|
-
FROM
|
|
16
|
-
item
|
|
17
|
-
`);
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
it("will limit rows", async () => {
|
|
21
|
-
const query = Item.get(5);
|
|
22
|
-
|
|
23
|
-
expect(query).toMatchInlineSnapshot(`
|
|
24
|
-
SELECT
|
|
25
|
-
item.id AS "id",
|
|
26
|
-
item.number AS "number"
|
|
27
|
-
FROM
|
|
28
|
-
item
|
|
29
|
-
LIMIT
|
|
30
|
-
5
|
|
31
|
-
`);
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
it("will query rows", async () => {
|
|
35
|
-
const query = Item.get((item, where) => {
|
|
36
|
-
where(item.number).over(5);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
expect(query).toMatchInlineSnapshot(`
|
|
40
|
-
SELECT
|
|
41
|
-
item.id AS "id",
|
|
42
|
-
item.number AS "number"
|
|
43
|
-
FROM
|
|
44
|
-
item
|
|
45
|
-
WHERE
|
|
46
|
-
item.number > 5
|
|
47
|
-
`);
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
it("will limit queried rows", async () => {
|
|
51
|
-
const query = Item.get(2, (item, where) => {
|
|
52
|
-
where(item.number).over(5);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
expect(query).toMatchInlineSnapshot(`
|
|
56
|
-
SELECT
|
|
57
|
-
item.id AS "id",
|
|
58
|
-
item.number AS "number"
|
|
59
|
-
FROM
|
|
60
|
-
item
|
|
61
|
-
WHERE
|
|
62
|
-
item.number > 5
|
|
63
|
-
LIMIT
|
|
64
|
-
2
|
|
65
|
-
`);
|
|
66
|
-
})
|
|
67
|
-
})
|
package/src/type/Type.ts
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { Connection, Query } from '..';
|
|
2
|
-
import { defineProperty, isIterable, underscore } from '../utils';
|
|
3
|
-
import { Field, fields, Nullable, Optional } from './Field';
|
|
4
|
-
|
|
5
|
-
declare namespace Type {
|
|
6
|
-
type EntityType<T extends Type = Type> =
|
|
7
|
-
& (abstract new () => T)
|
|
8
|
-
& typeof Type;
|
|
9
|
-
|
|
10
|
-
type Fields<T extends Type, O extends Partial<Field> = never> = {
|
|
11
|
-
[K in keyof T]: T[K] extends Field ? T[K] extends O ? never : K : never
|
|
12
|
-
}[keyof T];
|
|
13
|
-
|
|
14
|
-
type Required<T extends Type> = Fields<T, Nullable | Optional>;
|
|
15
|
-
|
|
16
|
-
type NonNull<T extends Type> = Fields<T, Nullable>;
|
|
17
|
-
|
|
18
|
-
type Insert<T extends Type> =
|
|
19
|
-
& { [K in Fields<T>]?: Field.Assigns<T[K]> }
|
|
20
|
-
& { [K in Required<T>]: Field.Assigns<T[K]> }
|
|
21
|
-
|
|
22
|
-
type Values<T extends Type> = { "id": number } & {
|
|
23
|
-
[K in Fields<T>]: T[K] extends Field.Returns<infer U> ? U : never
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
type Query<T extends Type, R> =
|
|
27
|
-
(query: Query.From<T>, where: Query.Where) => R;
|
|
28
|
-
|
|
29
|
-
interface InsertOp extends PromiseLike<void> {
|
|
30
|
-
toString(): string;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
abstract class Type {
|
|
35
|
-
this!: Type.EntityType;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Primary key of this entity.
|
|
39
|
-
* May be any name in the actual database, however requred to be `id` as property of this type.
|
|
40
|
-
*/
|
|
41
|
-
id = new Primary();
|
|
42
|
-
|
|
43
|
-
static schema = "";
|
|
44
|
-
|
|
45
|
-
static connection?: Connection;
|
|
46
|
-
|
|
47
|
-
static get fields(){
|
|
48
|
-
return fields(this);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
static get table(){
|
|
52
|
-
// chop off trailing numbers from transpiled class name
|
|
53
|
-
return this.table = underscore(this.name.replace(/\d+$/, ""));
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
static set table(value: string){
|
|
57
|
-
defineProperty(this, "table", { value });
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
static toString(){
|
|
61
|
-
return this.name;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
static is(obj: unknown): obj is Type.EntityType {
|
|
65
|
-
return typeof obj === 'function' && obj.prototype instanceof Type;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
static insert<T extends Type>(this: Type.EntityType<T>, entries: Type.Insert<T> | Type.Insert<T>[]): Query<number>;
|
|
69
|
-
static insert<T extends Type>(this: Type.EntityType<T>, number: number, map: (index: number) => Type.Insert<T>): Query<number>;
|
|
70
|
-
static insert<T extends Type, I>(this: Type.EntityType<T>, forEach: Array<I>, map: (value: I, index: number) => Type.Insert<T>): Query<number>;
|
|
71
|
-
static insert<T extends Type>(
|
|
72
|
-
this: Type.EntityType<T>,
|
|
73
|
-
arg1: Type.Insert<T> | Iterable<unknown> | number,
|
|
74
|
-
arg2?: Type.Insert<any> | Function,
|
|
75
|
-
){
|
|
76
|
-
let data: Type.Insert<T>[];
|
|
77
|
-
|
|
78
|
-
if(typeof arg2 == "function"){
|
|
79
|
-
if(typeof arg1 == "number")
|
|
80
|
-
data = Array.from({ length: arg1 }, (_, i) => arg2(i));
|
|
81
|
-
else if(isIterable(arg1))
|
|
82
|
-
data = Array.from(arg1, arg2 as (i: unknown, k: number) => Type.Insert<T>);
|
|
83
|
-
else
|
|
84
|
-
throw new Error("Map function needs an input iterable or a number to generate data.");
|
|
85
|
-
}
|
|
86
|
-
else if(isIterable(arg1))
|
|
87
|
-
data = Array.from(arg1) as Type.Insert<T>[];
|
|
88
|
-
else if(typeof arg1 == "object")
|
|
89
|
-
data = [arg1];
|
|
90
|
-
else
|
|
91
|
-
throw new Error("Invalid input for insert method.");
|
|
92
|
-
|
|
93
|
-
return Query(where => {
|
|
94
|
-
where(this, ...data);
|
|
95
|
-
})
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
static get<T extends Type>(this: Type.EntityType<T>, limit?: number): Query.Selects<T>;
|
|
99
|
-
static get<T extends Type>(this: Type.EntityType<T>, where?: Type.Query<T, void>): Query.Selects<T>;
|
|
100
|
-
static get<T extends Type, R>(this: Type.EntityType<T>, limit: number, where: Type.Query<T, R>): Query.Selects<R>;
|
|
101
|
-
static get<T extends Type, R>(this: Type.EntityType<T>, arg1?: Type.Query<T, R> | number, arg2?: Type.Query<T, R>){
|
|
102
|
-
const limit = typeof arg1 == "number" ? arg1 : undefined;
|
|
103
|
-
const query = typeof arg1 == "function" ? arg1 : arg2;
|
|
104
|
-
|
|
105
|
-
return Query<any>(where => {
|
|
106
|
-
const self = where(this);
|
|
107
|
-
|
|
108
|
-
if(limit)
|
|
109
|
-
where(limit);
|
|
110
|
-
|
|
111
|
-
return typeof query == "function" && query(self, where) || self;
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
static one<T extends Type, R extends {}>(this: Type.EntityType<T>, query: Type.Query<T, R>): Promise<Query.Extract<R>>;
|
|
116
|
-
static one<T extends Type>(this: Type.EntityType<T>, query?: Type.Query<T, void>): Promise<Type.Values<T>>;
|
|
117
|
-
static one<T extends Type>(this: Type.EntityType<T>, id: number): Promise<Type.Values<T>>;
|
|
118
|
-
static one(this: Type.EntityType, query?: Type.Query<Type, any> | number){
|
|
119
|
-
return Query(where => {
|
|
120
|
-
const self = where(this);
|
|
121
|
-
|
|
122
|
-
if(typeof query == "function")
|
|
123
|
-
return query(self, where) || self;
|
|
124
|
-
|
|
125
|
-
if(typeof query == "number")
|
|
126
|
-
where(self.id).is(query);
|
|
127
|
-
else
|
|
128
|
-
where(self.id).desc();
|
|
129
|
-
|
|
130
|
-
return self;
|
|
131
|
-
}).one(true);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
class Primary extends Field<number> {
|
|
136
|
-
readonly type = "int";
|
|
137
|
-
readonly increment = true;
|
|
138
|
-
readonly optional = true;
|
|
139
|
-
readonly nullable = false;
|
|
140
|
-
readonly primary = true;
|
|
141
|
-
readonly unique = true;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export { Type }
|
package/src/utils.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
export function capitalize(string: string){
|
|
2
|
-
return string[0].toUpperCase() + string.slice(1);
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export function isIterable(obj: unknown): obj is Iterable<unknown> {
|
|
6
|
-
type MaybeIterable = {
|
|
7
|
-
[Symbol.iterator]?: () => IterableIterator<unknown>;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
return obj != null && typeof (obj as MaybeIterable)[Symbol.iterator] === 'function';
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function underscore(str: string){
|
|
14
|
-
return str.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function escape(value: any){
|
|
18
|
-
if(typeof value != "string")
|
|
19
|
-
return value;
|
|
20
|
-
|
|
21
|
-
value = value
|
|
22
|
-
.replace(/[\0\n\r\b\t\\'"\x1a]/g, s => (
|
|
23
|
-
s == "\0" ? "\\0" :
|
|
24
|
-
s == "\n" ? "\\n" :
|
|
25
|
-
s == "\r" ? "\\r" :
|
|
26
|
-
s == "\b" ? "\\b" :
|
|
27
|
-
s == "\t" ? "\\t" :
|
|
28
|
-
s == "\x1a" ? "\\Z" :
|
|
29
|
-
"\\" + s
|
|
30
|
-
))
|
|
31
|
-
.replace(/[\x00-\x1f\x7f-\x9f]/g, ch => (
|
|
32
|
-
'\\x' + ch.charCodeAt(0).toString(16).padStart(2, '0')
|
|
33
|
-
));
|
|
34
|
-
|
|
35
|
-
return `'${value}'`;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const {
|
|
39
|
-
assign,
|
|
40
|
-
create,
|
|
41
|
-
defineProperty,
|
|
42
|
-
entries,
|
|
43
|
-
freeze,
|
|
44
|
-
getOwnPropertyDescriptor,
|
|
45
|
-
getOwnPropertyNames,
|
|
46
|
-
values,
|
|
47
|
-
} = Object;
|
|
48
|
-
|
|
49
|
-
export {
|
|
50
|
-
assign,
|
|
51
|
-
create,
|
|
52
|
-
defineProperty,
|
|
53
|
-
entries,
|
|
54
|
-
freeze,
|
|
55
|
-
getOwnPropertyDescriptor,
|
|
56
|
-
getOwnPropertyNames,
|
|
57
|
-
values,
|
|
58
|
-
escape
|
|
59
|
-
}
|