MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

make radix3 printTree prettier

+76 -23
+75 -22
examples/server/radix3.js
··· 208 208 for (let i = 0; i < methods.length; i = i + 1) { 209 209 const method = methods[i]; 210 210 console.log('[' + method + ']'); 211 - this.printNode(this.methods[method], '', true); 211 + 212 + const routes = []; 213 + this.collectRoutes(this.methods[method], '', routes); 214 + 215 + const tree = {}; 216 + for (let j = 0; j < routes.length; j = j + 1) { 217 + const route = routes[j]; 218 + const parts = this.splitPath(route.path); 219 + let current = tree; 220 + for (let k = 0; k < parts.length; k = k + 1) { 221 + const part = parts[k]; 222 + if (current[part] === undefined) { 223 + current[part] = { _children: {}, _handler: false }; 224 + } 225 + if (k === parts.length - 1) { 226 + current[part]._handler = route.hasHandler; 227 + } 228 + current = current[part]._children; 229 + } 230 + } 231 + 232 + this.printPathTree(tree, ''); 212 233 if (i < methods.length - 1) console.log(''); 213 234 } 214 235 } 215 236 216 - printNode(node, prefix, isLast) { 217 - const marker = isLast ? 'โ””โ”€ ' : 'โ”œโ”€ '; 218 - let line = prefix + marker; 237 + splitPath(path) { 238 + const parts = []; 239 + let i = 0; 219 240 220 - if (node.prefix !== '') { 221 - line = line + '"' + node.prefix + '"'; 222 - } else { 223 - line = line + '(root)'; 241 + while (i < path.length) { 242 + if (path[i] === '/') { 243 + let segment = '/'; 244 + i = i + 1; 245 + while (i < path.length && path[i] !== '/' && path[i] !== ':' && path[i] !== '*') { 246 + segment = segment + path[i]; 247 + i = i + 1; 248 + } 249 + if (segment !== '/') { 250 + parts.push(segment); 251 + } else if (parts.length === 0) { 252 + parts.push('/'); 253 + } 254 + } else if (path[i] === ':' || path[i] === '*') { 255 + let segment = path[i]; 256 + i = i + 1; 257 + while (i < path.length && path[i] !== '/') { 258 + segment = segment + path[i]; 259 + i = i + 1; 260 + } 261 + parts.push(segment); 262 + } else { 263 + i = i + 1; 264 + } 224 265 } 225 266 226 - if (node.handler !== undefined) { 227 - line = line + ' [HANDLER]'; 228 - } 267 + return parts; 268 + } 229 269 230 - if (node.paramName !== undefined) { 231 - line = line + ' :' + node.paramName; 270 + printPathTree(tree, indent) { 271 + const keys = Object.keys(tree); 272 + for (let i = 0; i < keys.length; i = i + 1) { 273 + const key = keys[i]; 274 + const node = tree[key]; 275 + const isLast = i === keys.length - 1; 276 + const marker = isLast ? 'โ””โ”€ ' : 'โ”œโ”€ '; 277 + let line = indent + marker + key; 278 + if (node._handler) { 279 + line = line + ' [HANDLER]'; 280 + } 281 + console.log(line); 282 + const childIndent = indent + (isLast ? ' ' : 'โ”‚ '); 283 + this.printPathTree(node._children, childIndent); 232 284 } 285 + } 233 286 234 - console.log(line); 235 - const childPrefix = prefix + (isLast ? ' ' : 'โ”‚ '); 287 + collectRoutes(node, currentPath, routes) { 288 + const path = currentPath + node.prefix; 289 + 290 + if (node.handler !== undefined) { 291 + routes.push({ path: path, hasHandler: true }); 292 + } 236 293 237 294 for (let i = 0; i < node.children.length; i = i + 1) { 238 - const isLastChild = i === node.children.length - 1 && node.paramChild === undefined && node.wildcardChild === undefined; 239 - this.printNode(node.children[i], childPrefix, isLastChild); 295 + this.collectRoutes(node.children[i], path, routes); 240 296 } 241 297 242 298 if (node.paramChild !== undefined) { 243 - const isLastChild = node.wildcardChild === undefined; 244 - console.log(childPrefix + (isLastChild ? 'โ””โ”€ ' : 'โ”œโ”€ ') + ':' + node.paramChild.paramName); 245 - this.printNode(node.paramChild, childPrefix + (isLastChild ? ' ' : 'โ”‚ '), true); 299 + this.collectRoutes(node.paramChild, path + ':' + node.paramChild.paramName, routes); 246 300 } 247 301 248 302 if (node.wildcardChild !== undefined) { 249 - console.log(childPrefix + 'โ””โ”€ *' + node.wildcardChild.paramName); 250 - this.printNode(node.wildcardChild, childPrefix + ' ', true); 303 + routes.push({ path: path + '*' + node.wildcardChild.paramName, hasHandler: node.wildcardChild.handler !== undefined }); 251 304 } 252 305 } 253 306 }
+1 -1
meson.build
··· 74 74 build_date = run_command('date', '+%Y-%m-%d', check: true).stdout().strip() 75 75 76 76 version_conf = configuration_data() 77 - version_conf.set('ANT_VERSION', '0.1.0.23') 77 + version_conf.set('ANT_VERSION', '0.1.0.24') 78 78 version_conf.set('ANT_GIT_HASH', git_hash) 79 79 version_conf.set('ANT_BUILD_DATE', build_date) 80 80