okai 0.0.3 → 0.0.7

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/dist/utils.js ADDED
@@ -0,0 +1,192 @@
1
+ export function plural(word, amount) {
2
+ if (amount !== undefined && amount === 1) {
3
+ return word;
4
+ }
5
+ const plural = {
6
+ '(quiz)$': "$1zes",
7
+ '^(ox)$': "$1en",
8
+ '([m|l])ouse$': "$1ice",
9
+ '(matr|vert|ind)ix|ex$': "$1ices",
10
+ '(x|ch|ss|sh)$': "$1es",
11
+ '([^aeiouy]|qu)y$': "$1ies",
12
+ '(hive)$': "$1s",
13
+ '(?:([^f])fe|([lr])f)$': "$1$2ves",
14
+ '(shea|lea|loa|thie)f$': "$1ves",
15
+ 'sis$': "ses",
16
+ '([ti])um$': "$1a",
17
+ '(tomat|potat|ech|her|vet)o$': "$1oes",
18
+ '(bu)s$': "$1ses",
19
+ '(alias)$': "$1es",
20
+ '(octop)us$': "$1i",
21
+ '(ax|test)is$': "$1es",
22
+ '(us)$': "$1es",
23
+ '([^s]+)$': "$1s"
24
+ };
25
+ const irregular = {
26
+ 'move': 'moves',
27
+ 'foot': 'feet',
28
+ 'goose': 'geese',
29
+ 'sex': 'sexes',
30
+ 'child': 'children',
31
+ 'man': 'men',
32
+ 'tooth': 'teeth',
33
+ 'person': 'people'
34
+ };
35
+ const uncountable = [
36
+ 'sheep',
37
+ 'fish',
38
+ 'deer',
39
+ 'moose',
40
+ 'series',
41
+ 'species',
42
+ 'money',
43
+ 'rice',
44
+ 'information',
45
+ 'equipment',
46
+ 'bison',
47
+ 'cod',
48
+ 'offspring',
49
+ 'pike',
50
+ 'salmon',
51
+ 'shrimp',
52
+ 'swine',
53
+ 'trout',
54
+ 'aircraft',
55
+ 'hovercraft',
56
+ 'spacecraft',
57
+ 'sugar',
58
+ 'tuna',
59
+ 'you',
60
+ 'wood'
61
+ ];
62
+ // save some time in the case that singular and plural are the same
63
+ if (uncountable.indexOf(word.toLowerCase()) >= 0) {
64
+ return word;
65
+ }
66
+ // check for irregular forms
67
+ for (const w in irregular) {
68
+ const pattern = new RegExp(`${w}$`, 'i');
69
+ const replace = irregular[w];
70
+ if (pattern.test(word)) {
71
+ return word.replace(pattern, replace);
72
+ }
73
+ }
74
+ // check for matches using regular expressions
75
+ for (const reg in plural) {
76
+ const pattern = new RegExp(reg, 'i');
77
+ if (pattern.test(word)) {
78
+ return word.replace(pattern, plural[reg]);
79
+ }
80
+ }
81
+ return word;
82
+ }
83
+ export function requestKey(date) {
84
+ return `requests/${timestampKey(date)}`;
85
+ }
86
+ export function timestampKey(date) {
87
+ const year = date.getFullYear();
88
+ const month = String(date.getMonth() + 1).padStart(2, '0');
89
+ const day = String(date.getDate()).padStart(2, '0');
90
+ const timestamp = date.valueOf();
91
+ return `${year}/${month}/${day}/${timestamp}`;
92
+ }
93
+ export function indentLines(src, indent = ' ') {
94
+ return src.split('\n').map(x => indent + x).join('\n');
95
+ }
96
+ export function trimStart(str, chars = ' ') {
97
+ const cleanStr = String(str);
98
+ const charsToTrim = new Set(chars);
99
+ let start = 0;
100
+ while (start < cleanStr.length && charsToTrim.has(cleanStr[start])) {
101
+ start++;
102
+ }
103
+ return cleanStr.slice(start);
104
+ }
105
+ export function leftPart(s, needle) {
106
+ if (s == null)
107
+ return null;
108
+ let pos = s.indexOf(needle);
109
+ return pos == -1
110
+ ? s
111
+ : s.substring(0, pos);
112
+ }
113
+ export function splitCase(t) {
114
+ return typeof t != 'string' ? t : t.replace(/([A-Z]|[0-9]+)/g, ' $1').replace(/_/g, ' ').trim();
115
+ }
116
+ export function refCount(t) {
117
+ return t.properties?.filter(x => x.attributes?.some(x => x.name === 'References')).length || 0;
118
+ }
119
+ export function getGroupName(ast) {
120
+ return plural(ast.types.sort((x, y) => refCount(y) - refCount(x))[0].name);
121
+ }
122
+ export function toPascalCase(s) {
123
+ if (!s)
124
+ return '';
125
+ const isAllCaps = s.match(/^[A-Z0-9_]+$/);
126
+ if (isAllCaps) {
127
+ const words = s.split('_');
128
+ return words.map(x => x[0].toUpperCase() + x.substring(1).toLowerCase()).join('');
129
+ }
130
+ if (s.includes('_')) {
131
+ return s.split('_').map(x => x[0].toUpperCase() + x.substring(1)).join('');
132
+ }
133
+ return s.charAt(0).toUpperCase() + s.substring(1);
134
+ }
135
+ export function toCamelCase(s) {
136
+ s = toPascalCase(s);
137
+ if (!s)
138
+ return '';
139
+ return s.charAt(0).toLowerCase() + s.substring(1);
140
+ }
141
+ export function camelToKebabCase(str) {
142
+ if (!str || str.length <= 1)
143
+ return str.toLowerCase();
144
+ // Insert hyphen before capitals and numbers, convert to lowercase
145
+ return str
146
+ .replace(/([A-Z0-9])/g, '-$1')
147
+ .toLowerCase()
148
+ // Remove leading hyphen if exists
149
+ .replace(/^-/, '')
150
+ // Replace multiple hyphens with single hyphen
151
+ .replace(/-+/g, '-');
152
+ }
153
+ export function replaceMyApp(input, projectName) {
154
+ const condensed = projectName.replace(/_/g, '');
155
+ const kebabCase = camelToKebabCase(condensed);
156
+ return input
157
+ .replace(/My_App/g, projectName)
158
+ .replace(/MyApp/g, projectName)
159
+ .replace(/My App/g, splitCase(condensed))
160
+ .replace(/my-app/g, kebabCase)
161
+ .replace(/myapp/g, condensed.toLowerCase())
162
+ .replace(/my_app/g, projectName.toLowerCase());
163
+ }
164
+ export class ResponseStatus {
165
+ constructor(init) { Object.assign(this, init); }
166
+ errorCode;
167
+ message;
168
+ stackTrace;
169
+ errors;
170
+ meta;
171
+ }
172
+ export class ResponseError {
173
+ constructor(init) { Object.assign(this, init); }
174
+ errorCode;
175
+ fieldName;
176
+ message;
177
+ meta;
178
+ }
179
+ export class ErrorResponse {
180
+ constructor(init) { Object.assign(this, init); }
181
+ type;
182
+ responseStatus;
183
+ }
184
+ export function createError(errorCode, message, fieldName) {
185
+ return new ErrorResponse({
186
+ responseStatus: new ResponseStatus({
187
+ errorCode,
188
+ message,
189
+ errors: fieldName ? [new ResponseError({ errorCode, message, fieldName })] : undefined
190
+ })
191
+ });
192
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "okai",
3
3
  "type": "module",
4
- "version": "0.0.3",
4
+ "version": "0.0.7",
5
5
  "bin": "./dist/okai.js",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",
@@ -12,7 +12,7 @@
12
12
  "import": "./dist/index.js"
13
13
  },
14
14
  "scripts": {
15
- "build": "bun run build.ts",
15
+ "build": "bun run clean && tsc",
16
16
  "clean": "shx rm -rf ./dist",
17
17
  "test": "bun test --",
18
18
  "prepublishOnly": "bun run build",
package/dist/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- // Generated by dts-bundle-generator v9.5.1
2
-
3
- export declare function cli(args: string[]): Promise<void>;
4
-
5
- export {};
package/dist/okai.d.ts DELETED
@@ -1,5 +0,0 @@
1
- // Generated by dts-bundle-generator v9.5.1
2
-
3
- export declare function cli(args: string[]): Promise<void>;
4
-
5
- export {};