Skip to content

Commit 5636b46

Browse files
authored
Merge pull request #388 from formidablejs/feature/code-clean-up
feat: clean up code
2 parents 465c593 + 0d38e5d commit 5636b46

30 files changed

+538
-472
lines changed

package-lock.json

Lines changed: 286 additions & 331 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Auth/Drivers/Driver.imba

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ export default class Driver
282282
if isValid !== true
283283
let errors = {}
284284

285-
isValid.forEach do(field)
285+
for field in isValid
286286
errors[field] = [
287287
"The {field} is invalid or has already taken."
288288
]

src/Database/Database.imba

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ try
3131
let results\object[] = await this
3232

3333
if columns && Array.isArray(columns) && columns.length > 0
34-
return results.map do(result)
34+
let mappedResults = []
35+
for result in results
3536
const object = {}
36-
3737
for column in columns
3838
object[column] = result[column]
39-
40-
return object
39+
mappedResults.push(object)
40+
return mappedResults
4141

4242
if this._hidden && Array.isArray(this._hidden) && this._hidden.length > 0
4343
for result in results
@@ -129,37 +129,56 @@ try
129129

130130
url = url.length > 1 ? url.replace(/\/+$/, '') + '/' : ''
131131

132+
params = []
133+
keys = Object.keys(query)
134+
for key in keys
135+
params.push(key + '=' + encodeURIComponent(key == 'page' ? (results.pagination.firstPage) : query[key]))
132136
links.firstPage = {
133137
label: 'First',
134138
active: results.pagination.firstPage === results.pagination.currentPage,
135-
url: url + '?' + Object.keys(query).map(do(key) key + '=' + encodeURIComponent(key == 'page' ? (results.pagination.firstPage) : query[key])).join('&')
139+
url: url + '?' + params.join('&')
136140
}
137141

142+
params = []
143+
keys = Object.keys(query)
144+
for key in keys
145+
params.push(key + '=' + encodeURIComponent(key == 'page' ? (results.pagination.prevPage) : query[key]))
138146
links.prevPage = results.pagination.prevPage ? {
139147
label: 'Previous',
140148
active: results.pagination.prevPage === results.pagination.currentPage,
141-
url: url + '?' + Object.keys(query).map(do(key) key + '=' + encodeURIComponent(key == 'page' ? (results.pagination.prevPage) : query[key])).join('&')
149+
url: url + '?' + params.join('&')
142150
} : null
143151

144152
for page in pages
145153
query.page = page
146-
154+
params = []
155+
keys = Object.keys(query)
156+
for key in keys
157+
params.push(key + '=' + encodeURIComponent(query[key]))
147158
links[page] = {
148159
label: page,
149160
active: page === results.pagination.currentPage,
150-
url: url + '?' + Object.keys(query).map(do(key) key + '=' + encodeURIComponent(query[key])).join('&')
161+
url: url + '?' + params.join('&')
151162
}
152163

164+
params = []
165+
keys = Object.keys(query)
166+
for key in keys
167+
params.push(key + '=' + encodeURIComponent(key == 'page' ? (results.pagination.nextPage) : query[key]))
153168
links.nextPage = results.pagination.nextPage ? {
154169
label: 'Next',
155170
active: results.pagination.nextPage === results.pagination.currentPage,
156-
url: url + '?' + Object.keys(query).map(do(key) key + '=' + encodeURIComponent(key == 'page' ? (results.pagination.nextPage) : query[key])).join('&')
171+
url: url + '?' + params.join('&')
157172
} : null
158173

174+
params = []
175+
keys = Object.keys(query)
176+
for key in keys
177+
params.push(key + '=' + encodeURIComponent(key == 'page' ? (results.pagination.lastPage) : query[key]))
159178
links.lastPage = {
160179
label: 'Last',
161180
active: results.pagination.lastPage === results.pagination.currentPage,
162-
url: url + '?' + Object.keys(query).map(do(key) key + '=' + encodeURIComponent(key == 'page' ? (results.pagination.lastPage) : query[key])).join('&')
181+
url: url + '?' + params.join('&')
163182
}
164183

165184
results.pagination.links = links

src/Environment/Repository.imba

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,12 @@ export default class Repository
3636
const results = output.match(/\$\{(.*?)\}/g)
3737

3838
if !isEmpty(results)
39-
results.forEach do(variable)
39+
for variable in results
4040
output = output.replace(variable, self.variables[variable.slice(2, -1)])
4141

42+
# results.forEach do(variable)
43+
# output = output.replace(variable, self.variables[variable.slice(2, -1)])
44+
4245
if isEmpty(output) then return default
4346

4447
['true', 'false'].includes(output.toLowerCase!) ? output = JSON.parse(output) : (output === 'null' ? null : output)

src/Foundation/Application.imba

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,5 +227,5 @@ export default class Application
227227
resolver.register!
228228

229229
if resolver.context && Array.isArray(resolver.context)
230-
resolver.context.forEach do(context)
230+
for context in resolver.context
231231
self.context.inject(context)

src/Foundation/Console.imba

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,11 @@ export default class Console
125125
const nodeEnv = args.find do(arg) arg.startsWith('--MODE=')
126126
const nodeEnvValue = nodeEnv ? nodeEnv.split('=')[1] : 'development'
127127

128-
process.argv = process.argv.filter do(arg) !arg.startsWith('--MODE=')
128+
let filteredArgv = []
129+
for arg in process.argv
130+
if !arg.startsWith('--MODE=')
131+
filteredArgv.push(arg)
132+
process.argv = filteredArgv
129133

130134
modes.includes(nodeEnvValue)
131135

@@ -148,7 +152,7 @@ export default class Console
148152
let host = 'localhost'
149153
let addr = false
150154

151-
args.forEach do(arg)
155+
for arg in args
152156
port = arg.split('=')[1] if arg.startsWith('--port')
153157
host = arg.split('=')[1] if arg.startsWith('--host') || arg.startsWith('-h')
154158
addr = true if arg == '--addr'

src/Foundation/Console/Commands/DbSeedCommand.imba

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class DbSeedCommand < Command
6363
const root = process.cwd!
6464

6565
Output.group { newLine: false }, do
66-
results[0].forEach do(seeder)
66+
for seeder in results[0]
6767
self.message 'info', "Seeder \x1b[1m[{seeder.substring(root.length + 1)}]\x1b[0m ran successfully."
6868

6969
exit!

src/Foundation/Console/Commands/MigrationCommand.imba

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class MigrationCommand < Command
5252

5353
if results[1].length > 0
5454
Output.group { newLine: false }, do
55-
results[1].forEach do(migration)
55+
for migration in results[1]
5656
self.message 'info', "<fg:green>{action === 'rollback' ? 'Rollback' : 'Migrate'}:</fg:green> {migration}"
5757

5858
if exitOnEnd

src/Foundation/Console/Commands/PackagePublishCommand.imba

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ export class PackagePublishCommand < Command
6464
def handle
6565
let tags\string[] = self.option('tag').split(',')
6666

67-
tags.forEach do(optTag) self.persist optTag
67+
for optTag in tags
68+
self.persist optTag
6869

6970
self.exit!
7071

@@ -75,7 +76,7 @@ export class PackagePublishCommand < Command
7576
if typeof self.publisher[optTag] !== 'object'
7677
return self.write "<fg:red>{optTag} is missing paths.</fg:red>"
7778

78-
Object.keys(self.publisher[optTag].paths).forEach do(entry)
79+
for entry in Object.keys(self.publisher[optTag].paths)
7980
const file = join self.package, self.publisher[optTag].paths[entry]
8081

8182
if existsSync(entry) && !self.option('force', false)

src/Foundation/Console/Commands/RouteListCommand.imba

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@ export class RouteListCommand < Command
2424
const list = []
2525
const methods = self.option('method') ? (Array.isArray(self.option('method')) ? self.option('method') : [self.option('method')]) : ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS', 'HEAD', 'TRACE', 'CONNECT']
2626

27-
const routes = self.app.routes!.filter(do(route)
28-
methods.map(do(method) method.toUpperCase!).includes(route.method.toUpperCase!)
29-
)
27+
let normalizedMethods = []
28+
for method in methods
29+
normalizedMethods.push(method.toUpperCase!)
30+
let routes = []
31+
for route in self.app.routes!
32+
if normalizedMethods.includes(route.method.toUpperCase!)
33+
routes.push(route)
3034

3135
if self.option('legacy')
3236
self.table(routes)

0 commit comments

Comments
 (0)