Best JavaScript code snippet using storybook-root
routes.js
Source:routes.js
1/**2 * Generated by "@vuepress/internal-routes"3 */4import { injectComponentOption, ensureAsyncComponentsLoaded } from '@app/util'5import rootMixins from '@internal/root-mixins'6import GlobalLayout from "/Users/xule/vuepress/node_modules/@vuepress/core/lib/client/components/GlobalLayout.vue"7injectComponentOption(GlobalLayout, 'mixins', rootMixins)8export const routes = [9 {10 name: "v-73453928",11 path: "/api/cli.html",12 component: GlobalLayout,13 beforeEnter: (to, from, next) => {14 ensureAsyncComponentsLoaded("Layout", "v-73453928").then(next)15 },16 },17 {18 name: "v-5d81d274",19 path: "/api/node.html",20 component: GlobalLayout,21 beforeEnter: (to, from, next) => {22 ensureAsyncComponentsLoaded("Layout", "v-5d81d274").then(next)23 },24 },25 {26 name: "v-3c48d225",27 path: "/faq/",28 component: GlobalLayout,29 beforeEnter: (to, from, next) => {30 ensureAsyncComponentsLoaded("Layout", "v-3c48d225").then(next)31 },32 },33 {34 path: "/faq/index.html",35 redirect: "/faq/"36 },37 {38 name: "v-21d2ac23",39 path: "/config/",40 component: GlobalLayout,41 beforeEnter: (to, from, next) => {42 ensureAsyncComponentsLoaded("Layout", "v-21d2ac23").then(next)43 },44 },45 {46 path: "/config/index.html",47 redirect: "/config/"48 },49 {50 name: "v-d5771bce",51 path: "/guide/",52 component: GlobalLayout,53 beforeEnter: (to, from, next) => {54 ensureAsyncComponentsLoaded("Layout", "v-d5771bce").then(next)55 },56 },57 {58 path: "/guide/index.html",59 redirect: "/guide/"60 },61 {62 name: "v-09c23cc8",63 path: "/guide/assets.html",64 component: GlobalLayout,65 beforeEnter: (to, from, next) => {66 ensureAsyncComponentsLoaded("Layout", "v-09c23cc8").then(next)67 },68 },69 {70 name: "v-8e1ab568",71 path: "/guide/basic-config.html",72 component: GlobalLayout,73 beforeEnter: (to, from, next) => {74 ensureAsyncComponentsLoaded("Layout", "v-8e1ab568").then(next)75 },76 },77 {78 name: "v-263a0700",79 path: "/guide/deploy.html",80 component: GlobalLayout,81 beforeEnter: (to, from, next) => {82 ensureAsyncComponentsLoaded("Layout", "v-263a0700").then(next)83 },84 },85 {86 name: "v-38f82170",87 path: "/guide/directory-structure.html",88 component: GlobalLayout,89 beforeEnter: (to, from, next) => {90 ensureAsyncComponentsLoaded("Layout", "v-38f82170").then(next)91 },92 },93 {94 name: "v-32d45ae8",95 path: "/guide/frontmatter.html",96 component: GlobalLayout,97 beforeEnter: (to, from, next) => {98 ensureAsyncComponentsLoaded("Layout", "v-32d45ae8").then(next)99 },100 },101 {102 name: "v-411d91a8",103 path: "/guide/getting-started.html",104 component: GlobalLayout,105 beforeEnter: (to, from, next) => {106 ensureAsyncComponentsLoaded("Layout", "v-411d91a8").then(next)107 },108 },109 {110 name: "v-1def10c8",111 path: "/guide/global-computed.html",112 component: GlobalLayout,113 beforeEnter: (to, from, next) => {114 ensureAsyncComponentsLoaded("Layout", "v-1def10c8").then(next)115 },116 },117 {118 name: "v-32196c68",119 path: "/guide/markdown-slot.html",120 component: GlobalLayout,121 beforeEnter: (to, from, next) => {122 ensureAsyncComponentsLoaded("Layout", "v-32196c68").then(next)123 },124 },125 {126 name: "v-8150c4dc",127 path: "/guide/i18n.html",128 component: GlobalLayout,129 beforeEnter: (to, from, next) => {130 ensureAsyncComponentsLoaded("Layout", "v-8150c4dc").then(next)131 },132 },133 {134 name: "v-af314a20",135 path: "/guide/markdown.html",136 component: GlobalLayout,137 beforeEnter: (to, from, next) => {138 ensureAsyncComponentsLoaded("Layout", "v-af314a20").then(next)139 },140 },141 {142 name: "v-4dc37c88",143 path: "/guide/using-vue.html",144 component: GlobalLayout,145 beforeEnter: (to, from, next) => {146 ensureAsyncComponentsLoaded("Layout", "v-4dc37c88").then(next)147 },148 },149 {150 name: "v-994d2284",151 path: "/guide/permalinks.html",152 component: GlobalLayout,153 beforeEnter: (to, from, next) => {154 ensureAsyncComponentsLoaded("Layout", "v-994d2284").then(next)155 },156 },157 {158 name: "v-410b8f01",159 path: "/",160 component: GlobalLayout,161 beforeEnter: (to, from, next) => {162 ensureAsyncComponentsLoaded("Layout", "v-410b8f01").then(next)163 },164 },165 {166 path: "/index.html",167 redirect: "/"168 },169 {170 name: "v-6b3ec228",171 path: "/miscellaneous/design-concepts.html",172 component: GlobalLayout,173 beforeEnter: (to, from, next) => {174 ensureAsyncComponentsLoaded("Layout", "v-6b3ec228").then(next)175 },176 },177 {178 name: "v-5ec9ab14",179 path: "/miscellaneous/glossary.html",180 component: GlobalLayout,181 beforeEnter: (to, from, next) => {182 ensureAsyncComponentsLoaded("Layout", "v-5ec9ab14").then(next)183 },184 },185 {186 name: "v-0f964348",187 path: "/miscellaneous/local-development.html",188 component: GlobalLayout,189 beforeEnter: (to, from, next) => {190 ensureAsyncComponentsLoaded("Layout", "v-0f964348").then(next)191 },192 },193 {194 name: "v-c6511c70",195 path: "/miscellaneous/migration-guide.html",196 component: GlobalLayout,197 beforeEnter: (to, from, next) => {198 ensureAsyncComponentsLoaded("Layout", "v-c6511c70").then(next)199 },200 },201 {202 name: "v-14317003",203 path: "/plugin/",204 component: GlobalLayout,205 beforeEnter: (to, from, next) => {206 ensureAsyncComponentsLoaded("Layout", "v-14317003").then(next)207 },208 },209 {210 path: "/plugin/index.html",211 redirect: "/plugin/"212 },213 {214 name: "v-175d40f4",215 path: "/plugin/context-api.html",216 component: GlobalLayout,217 beforeEnter: (to, from, next) => {218 ensureAsyncComponentsLoaded("Layout", "v-175d40f4").then(next)219 },220 },221 {222 name: "v-40b442b0",223 path: "/plugin/life-cycle.html",224 component: GlobalLayout,225 beforeEnter: (to, from, next) => {226 ensureAsyncComponentsLoaded("Layout", "v-40b442b0").then(next)227 },228 },229 {230 name: "v-2e976786",231 path: "/plugin/official/plugin-back-to-top.html",232 component: GlobalLayout,233 beforeEnter: (to, from, next) => {234 ensureAsyncComponentsLoaded("Layout", "v-2e976786").then(next)235 },236 },237 {238 name: "v-71567518",239 path: "/plugin/official/plugin-active-header-links.html",240 component: GlobalLayout,241 beforeEnter: (to, from, next) => {242 ensureAsyncComponentsLoaded("Layout", "v-71567518").then(next)243 },244 },245 {246 name: "v-25663e70",247 path: "/plugin/official/plugin-blog.html",248 component: GlobalLayout,249 beforeEnter: (to, from, next) => {250 ensureAsyncComponentsLoaded("Layout", "v-25663e70").then(next)251 },252 },253 {254 name: "v-2dfe26c8",255 path: "/plugin/official/plugin-google-analytics.html",256 component: GlobalLayout,257 beforeEnter: (to, from, next) => {258 ensureAsyncComponentsLoaded("Layout", "v-2dfe26c8").then(next)259 },260 },261 {262 name: "v-2924e9f0",263 path: "/plugin/official/plugin-last-updated.html",264 component: GlobalLayout,265 beforeEnter: (to, from, next) => {266 ensureAsyncComponentsLoaded("Layout", "v-2924e9f0").then(next)267 },268 },269 {270 name: "v-722ca282",271 path: "/plugin/official/plugin-medium-zoom.html",272 component: GlobalLayout,273 beforeEnter: (to, from, next) => {274 ensureAsyncComponentsLoaded("Layout", "v-722ca282").then(next)275 },276 },277 {278 name: "v-f8b47738",279 path: "/plugin/official/plugin-pwa.html",280 component: GlobalLayout,281 beforeEnter: (to, from, next) => {282 ensureAsyncComponentsLoaded("Layout", "v-f8b47738").then(next)283 },284 },285 {286 name: "v-aa74ab3c",287 path: "/plugin/official/plugin-nprogress.html",288 component: GlobalLayout,289 beforeEnter: (to, from, next) => {290 ensureAsyncComponentsLoaded("Layout", "v-aa74ab3c").then(next)291 },292 },293 {294 name: "v-c163e850",295 path: "/plugin/official/plugin-register-components.html",296 component: GlobalLayout,297 beforeEnter: (to, from, next) => {298 ensureAsyncComponentsLoaded("Layout", "v-c163e850").then(next)299 },300 },301 {302 name: "v-905043f0",303 path: "/plugin/official/plugin-search.html",304 component: GlobalLayout,305 beforeEnter: (to, from, next) => {306 ensureAsyncComponentsLoaded("Layout", "v-905043f0").then(next)307 },308 },309 {310 name: "v-64e466f0",311 path: "/plugin/option-api.html",312 component: GlobalLayout,313 beforeEnter: (to, from, next) => {314 ensureAsyncComponentsLoaded("Layout", "v-64e466f0").then(next)315 },316 },317 {318 name: "v-66baf8c8",319 path: "/plugin/using-a-plugin.html",320 component: GlobalLayout,321 beforeEnter: (to, from, next) => {322 ensureAsyncComponentsLoaded("Layout", "v-66baf8c8").then(next)323 },324 },325 {326 name: "v-359e33c8",327 path: "/plugin/writing-a-plugin.html",328 component: GlobalLayout,329 beforeEnter: (to, from, next) => {330 ensureAsyncComponentsLoaded("Layout", "v-359e33c8").then(next)331 },332 },333 {334 name: "v-7836a9bf",335 path: "/theme/",336 component: GlobalLayout,337 beforeEnter: (to, from, next) => {338 ensureAsyncComponentsLoaded("Layout", "v-7836a9bf").then(next)339 },340 },341 {342 path: "/theme/index.html",343 redirect: "/theme/"344 },345 {346 name: "v-2d4a2f28",347 path: "/theme/blog-theme.html",348 component: GlobalLayout,349 beforeEnter: (to, from, next) => {350 ensureAsyncComponentsLoaded("Layout", "v-2d4a2f28").then(next)351 },352 },353 {354 name: "v-245d0084",355 path: "/theme/default-theme-config.html",356 component: GlobalLayout,357 beforeEnter: (to, from, next) => {358 ensureAsyncComponentsLoaded("Layout", "v-245d0084").then(next)359 },360 },361 {362 name: "v-99b66e70",363 path: "/theme/inheritance.html",364 component: GlobalLayout,365 beforeEnter: (to, from, next) => {366 ensureAsyncComponentsLoaded("Layout", "v-99b66e70").then(next)367 },368 },369 {370 name: "v-8bc734b8",371 path: "/theme/option-api.html",372 component: GlobalLayout,373 beforeEnter: (to, from, next) => {374 ensureAsyncComponentsLoaded("Layout", "v-8bc734b8").then(next)375 },376 },377 {378 name: "v-7edc83f0",379 path: "/theme/using-a-theme.html",380 component: GlobalLayout,381 beforeEnter: (to, from, next) => {382 ensureAsyncComponentsLoaded("Layout", "v-7edc83f0").then(next)383 },384 },385 {386 name: "v-5a6f8a88",387 path: "/theme/writing-a-theme.html",388 component: GlobalLayout,389 beforeEnter: (to, from, next) => {390 ensureAsyncComponentsLoaded("Layout", "v-5a6f8a88").then(next)391 },392 },393 {394 name: "v-666b1d23",395 path: "/zh/",396 component: GlobalLayout,397 beforeEnter: (to, from, next) => {398 ensureAsyncComponentsLoaded("Layout", "v-666b1d23").then(next)399 },400 },401 {402 path: "/zh/index.html",403 redirect: "/zh/"404 },405 {406 name: "v-13647ba0",407 path: "/zh/api/cli.html",408 component: GlobalLayout,409 beforeEnter: (to, from, next) => {410 ensureAsyncComponentsLoaded("Layout", "v-13647ba0").then(next)411 },412 },413 {414 name: "v-a2111570",415 path: "/zh/api/node.html",416 component: GlobalLayout,417 beforeEnter: (to, from, next) => {418 ensureAsyncComponentsLoaded("Layout", "v-a2111570").then(next)419 },420 },421 {422 name: "v-1fc5904b",423 path: "/zh/config/",424 component: GlobalLayout,425 beforeEnter: (to, from, next) => {426 ensureAsyncComponentsLoaded("Layout", "v-1fc5904b").then(next)427 },428 },429 {430 path: "/zh/config/index.html",431 redirect: "/zh/config/"432 },433 {434 name: "v-0320befa",435 path: "/zh/guide/",436 component: GlobalLayout,437 beforeEnter: (to, from, next) => {438 ensureAsyncComponentsLoaded("Layout", "v-0320befa").then(next)439 },440 },441 {442 path: "/zh/guide/index.html",443 redirect: "/zh/guide/"444 },445 {446 name: "v-209103c3",447 path: "/zh/faq/",448 component: GlobalLayout,449 beforeEnter: (to, from, next) => {450 ensureAsyncComponentsLoaded("Layout", "v-209103c3").then(next)451 },452 },453 {454 path: "/zh/faq/index.html",455 redirect: "/zh/faq/"456 },457 {458 name: "v-5680bda8",459 path: "/zh/guide/assets.html",460 component: GlobalLayout,461 beforeEnter: (to, from, next) => {462 ensureAsyncComponentsLoaded("Layout", "v-5680bda8").then(next)463 },464 },465 {466 name: "v-d6f6e0b0",467 path: "/zh/guide/basic-config.html",468 component: GlobalLayout,469 beforeEnter: (to, from, next) => {470 ensureAsyncComponentsLoaded("Layout", "v-d6f6e0b0").then(next)471 },472 },473 {474 name: "v-63929028",475 path: "/zh/guide/deploy.html",476 component: GlobalLayout,477 beforeEnter: (to, from, next) => {478 ensureAsyncComponentsLoaded("Layout", "v-63929028").then(next)479 },480 },481 {482 name: "v-bb8d2e70",483 path: "/zh/guide/frontmatter.html",484 component: GlobalLayout,485 beforeEnter: (to, from, next) => {486 ensureAsyncComponentsLoaded("Layout", "v-bb8d2e70").then(next)487 },488 },489 {490 name: "v-59102394",491 path: "/zh/guide/directory-structure.html",492 component: GlobalLayout,493 beforeEnter: (to, from, next) => {494 ensureAsyncComponentsLoaded("Layout", "v-59102394").then(next)495 },496 },497 {498 name: "v-01e8eea8",499 path: "/zh/guide/getting-started.html",500 component: GlobalLayout,501 beforeEnter: (to, from, next) => {502 ensureAsyncComponentsLoaded("Layout", "v-01e8eea8").then(next)503 },504 },505 {506 name: "v-41132dee",507 path: "/zh/guide/global-computed.html",508 component: GlobalLayout,509 beforeEnter: (to, from, next) => {510 ensureAsyncComponentsLoaded("Layout", "v-41132dee").then(next)511 },512 },513 {514 name: "v-e247f1f0",515 path: "/zh/guide/i18n.html",516 component: GlobalLayout,517 beforeEnter: (to, from, next) => {518 ensureAsyncComponentsLoaded("Layout", "v-e247f1f0").then(next)519 },520 },521 {522 name: "v-0fbb8d38",523 path: "/zh/guide/markdown-slot.html",524 component: GlobalLayout,525 beforeEnter: (to, from, next) => {526 ensureAsyncComponentsLoaded("Layout", "v-0fbb8d38").then(next)527 },528 },529 {530 name: "v-51584b68",531 path: "/zh/guide/markdown.html",532 component: GlobalLayout,533 beforeEnter: (to, from, next) => {534 ensureAsyncComponentsLoaded("Layout", "v-51584b68").then(next)535 },536 },537 {538 name: "v-4a237dc8",539 path: "/zh/guide/permalinks.html",540 component: GlobalLayout,541 beforeEnter: (to, from, next) => {542 ensureAsyncComponentsLoaded("Layout", "v-4a237dc8").then(next)543 },544 },545 {546 name: "v-db7effbc",547 path: "/zh/guide/using-vue.html",548 component: GlobalLayout,549 beforeEnter: (to, from, next) => {550 ensureAsyncComponentsLoaded("Layout", "v-db7effbc").then(next)551 },552 },553 {554 name: "v-03ff2544",555 path: "/zh/miscellaneous/design-concepts.html",556 component: GlobalLayout,557 beforeEnter: (to, from, next) => {558 ensureAsyncComponentsLoaded("Layout", "v-03ff2544").then(next)559 },560 },561 {562 name: "v-629d8906",563 path: "/zh/miscellaneous/local-development.html",564 component: GlobalLayout,565 beforeEnter: (to, from, next) => {566 ensureAsyncComponentsLoaded("Layout", "v-629d8906").then(next)567 },568 },569 {570 name: "v-008ba970",571 path: "/zh/miscellaneous/glossary.html",572 component: GlobalLayout,573 beforeEnter: (to, from, next) => {574 ensureAsyncComponentsLoaded("Layout", "v-008ba970").then(next)575 },576 },577 {578 name: "v-1e0d7b04",579 path: "/zh/miscellaneous/migration-guide.html",580 component: GlobalLayout,581 beforeEnter: (to, from, next) => {582 ensureAsyncComponentsLoaded("Layout", "v-1e0d7b04").then(next)583 },584 },585 {586 name: "v-156e71ae",587 path: "/zh/plugin/",588 component: GlobalLayout,589 beforeEnter: (to, from, next) => {590 ensureAsyncComponentsLoaded("Layout", "v-156e71ae").then(next)591 },592 },593 {594 path: "/zh/plugin/index.html",595 redirect: "/zh/plugin/"596 },597 {598 name: "v-c16013b0",599 path: "/zh/plugin/context-api.html",600 component: GlobalLayout,601 beforeEnter: (to, from, next) => {602 ensureAsyncComponentsLoaded("Layout", "v-c16013b0").then(next)603 },604 },605 {606 name: "v-ccb33fd8",607 path: "/zh/plugin/life-cycle.html",608 component: GlobalLayout,609 beforeEnter: (to, from, next) => {610 ensureAsyncComponentsLoaded("Layout", "v-ccb33fd8").then(next)611 },612 },613 {614 name: "v-60720370",615 path: "/zh/plugin/official/plugin-back-to-top.html",616 component: GlobalLayout,617 beforeEnter: (to, from, next) => {618 ensureAsyncComponentsLoaded("Layout", "v-60720370").then(next)619 },620 },621 {622 name: "v-0f63a530",623 path: "/zh/plugin/official/plugin-active-header-links.html",624 component: GlobalLayout,625 beforeEnter: (to, from, next) => {626 ensureAsyncComponentsLoaded("Layout", "v-0f63a530").then(next)627 },628 },629 {630 name: "v-7a9f680e",631 path: "/zh/plugin/official/plugin-blog.html",632 component: GlobalLayout,633 beforeEnter: (to, from, next) => {634 ensureAsyncComponentsLoaded("Layout", "v-7a9f680e").then(next)635 },636 },637 {638 name: "v-fe11c624",639 path: "/zh/plugin/official/plugin-google-analytics.html",640 component: GlobalLayout,641 beforeEnter: (to, from, next) => {642 ensureAsyncComponentsLoaded("Layout", "v-fe11c624").then(next)643 },644 },645 {646 name: "v-9114df6c",647 path: "/zh/plugin/official/plugin-last-updated.html",648 component: GlobalLayout,649 beforeEnter: (to, from, next) => {650 ensureAsyncComponentsLoaded("Layout", "v-9114df6c").then(next)651 },652 },653 {654 name: "v-e5c827f0",655 path: "/zh/plugin/official/plugin-medium-zoom.html",656 component: GlobalLayout,657 beforeEnter: (to, from, next) => {658 ensureAsyncComponentsLoaded("Layout", "v-e5c827f0").then(next)659 },660 },661 {662 name: "v-240d2588",663 path: "/zh/plugin/official/plugin-nprogress.html",664 component: GlobalLayout,665 beforeEnter: (to, from, next) => {666 ensureAsyncComponentsLoaded("Layout", "v-240d2588").then(next)667 },668 },669 {670 name: "v-024ec828",671 path: "/zh/plugin/official/plugin-pwa.html",672 component: GlobalLayout,673 beforeEnter: (to, from, next) => {674 ensureAsyncComponentsLoaded("Layout", "v-024ec828").then(next)675 },676 },677 {678 name: "v-ba834d30",679 path: "/zh/plugin/official/plugin-register-components.html",680 component: GlobalLayout,681 beforeEnter: (to, from, next) => {682 ensureAsyncComponentsLoaded("Layout", "v-ba834d30").then(next)683 },684 },685 {686 name: "v-456df90c",687 path: "/zh/plugin/option-api.html",688 component: GlobalLayout,689 beforeEnter: (to, from, next) => {690 ensureAsyncComponentsLoaded("Layout", "v-456df90c").then(next)691 },692 },693 {694 name: "v-1fad9fc2",695 path: "/zh/plugin/official/plugin-search.html",696 component: GlobalLayout,697 beforeEnter: (to, from, next) => {698 ensureAsyncComponentsLoaded("Layout", "v-1fad9fc2").then(next)699 },700 },701 {702 name: "v-7f65df24",703 path: "/zh/plugin/using-a-plugin.html",704 component: GlobalLayout,705 beforeEnter: (to, from, next) => {706 ensureAsyncComponentsLoaded("Layout", "v-7f65df24").then(next)707 },708 },709 {710 name: "v-32270544",711 path: "/zh/plugin/writing-a-plugin.html",712 component: GlobalLayout,713 beforeEnter: (to, from, next) => {714 ensureAsyncComponentsLoaded("Layout", "v-32270544").then(next)715 },716 },717 {718 name: "v-df9adcba",719 path: "/zh/theme/",720 component: GlobalLayout,721 beforeEnter: (to, from, next) => {722 ensureAsyncComponentsLoaded("Layout", "v-df9adcba").then(next)723 },724 },725 {726 path: "/zh/theme/index.html",727 redirect: "/zh/theme/"728 },729 {730 name: "v-26f723e8",731 path: "/zh/theme/blog-theme.html",732 component: GlobalLayout,733 beforeEnter: (to, from, next) => {734 ensureAsyncComponentsLoaded("Layout", "v-26f723e8").then(next)735 },736 },737 {738 name: "v-7c12ebb0",739 path: "/zh/theme/default-theme-config.html",740 component: GlobalLayout,741 beforeEnter: (to, from, next) => {742 ensureAsyncComponentsLoaded("Layout", "v-7c12ebb0").then(next)743 },744 },745 {746 name: "v-51e8742e",747 path: "/zh/theme/inheritance.html",748 component: GlobalLayout,749 beforeEnter: (to, from, next) => {750 ensureAsyncComponentsLoaded("Layout", "v-51e8742e").then(next)751 },752 },753 {754 name: "v-e739d730",755 path: "/zh/theme/option-api.html",756 component: GlobalLayout,757 beforeEnter: (to, from, next) => {758 ensureAsyncComponentsLoaded("Layout", "v-e739d730").then(next)759 },760 },761 {762 name: "v-2594b9da",763 path: "/zh/theme/using-a-theme.html",764 component: GlobalLayout,765 beforeEnter: (to, from, next) => {766 ensureAsyncComponentsLoaded("Layout", "v-2594b9da").then(next)767 },768 },769 {770 name: "v-3e75e6ea",771 path: "/zh/theme/writing-a-theme.html",772 component: GlobalLayout,773 beforeEnter: (to, from, next) => {774 ensureAsyncComponentsLoaded("Layout", "v-3e75e6ea").then(next)775 },776 },777 {778 path: '*',779 component: GlobalLayout780 }...
bootstrap.js
Source:bootstrap.js
...93 this.cont.nesting = 0;94 setTimeout(next, 0);95 }96 else {97 next();98 }99 }100}101Factor.prototype.push_data = function(v, next) {102 factor.cont.data_stack.push(v);103 factor.call_next(next);104}105Factor.prototype.use = function(v, next) {106 factor.cont.data_stack.push(v);107 factor.get_word("kernel", "use+").execute(next);108}109Factor.prototype.using = function(v, next) {110 factor.cont.data_stack.push(v);111 factor.get_word("kernel", "using").execute(next);112}113var fjsc_repl = false;114Factor.prototype.set_in = function(v, next) {115 factor.cont.data_stack.push(v);116 factor.get_word("kernel", "set-in").execute(next);117 if (fjsc_repl) {118 fjsc_repl.ps = '( ' + v + ' )';119 }120}121Factor.prototype.get_word = function(vocab,name) {122 return factor.vocabs[vocab][name];123}124Factor.prototype.find_word = function(name) {125 for(var v = 0; v<factor.using_vocabs.length; ++v) {126 var w = factor.vocabs[factor.using_vocabs[v]][name];127 if(w)128 return w;129 }130 return false;131}132Factor.prototype.add_word = function(vocab,name, source, func) {133 var v = factor.vocabs[vocab];134 if(!v) {135 v = { };136 factor.vocabs[vocab] = v;137 }138 v[name] = new Word(vocab,name,source,func);139}140Factor.prototype.remove_word = function(vocab,name) {141 var v = factor.vocabs[vocab];142 if(!v) {143 v = { };144 factor.vocabs[vocab] = v;145 }146 delete v[name];147}148 149Factor.prototype.define_word = function(name, source, func, next) {150 factor.vocabs[factor.in_vocab][name] = new Word(factor.in_vocab, name, source, function(next) {151 var old = factor.cont.next;152 factor.cont.next = function() {153 factor.cont.next = old;154 factor.call_next(next);155 }156 func();157 });158 factor.call_next(next);159}160Factor.prototype.make_quotation = function(source, func) {161 return new Word("quotations", "quotation", source, function(next) {162 var old = factor.cont.next;163 factor.cont.next = function() {164 factor.cont.next = old;165 factor.call_next(next);166 }167 func();168 });169}170Factor.prototype.server_eval = function(text, handler, next) {171 var self = this;172 $.post("compile", { code: text }, function(result) {173 factor.run_eval = function(func) {174 factor.cont.next = function() { handler(text,result); } 175 try {176 func(factor);177 } catch(ex) {178 alert("Error Parsing Javascript: " + ex); 179 handler(text, result);180 }181 if(next) 182 factor.call_next(next);183 }184 try {185 eval("factor.run_eval" + result);186 } catch(e) {187 factor.run_eval(function() { alert("Error Parsing Javascript: " + e); });188 }189 });190}191/* kernel-internals vocabulary */192factor.add_word("kernel-internals", ">n", "primitive", function(next) {193 var data_stack = factor.cont.data_stack;194 var name_stack = factor.cont.name_stack;195 name_stack.push(data_stack.pop());196 factor.call_next(next);197});198factor.add_word("kernel-internals", "n>", "primitive", function(next) {199 var data_stack = factor.cont.data_stack;200 var name_stack = factor.cont.name_stack;201 data_stack.push(name_stack.pop());202 factor.call_next(next);203});204/* Kernel Vocabulary */205factor.add_word("kernel","dup", "primitive", function(next) {206 var stack = factor.cont.data_stack;207 stack[stack.length] = stack[stack.length-1];208 factor.call_next(next);209});210factor.add_word("kernel", "drop", "primitive", function(next) {211 factor.cont.data_stack.pop();212 factor.call_next(next);213});214factor.add_word("kernel", "nip", "primitive", function(next) {215 var stack = factor.cont.data_stack;216 stack[stack.length-2] = stack[stack.length-1];217 stack.pop();218 factor.call_next(next);219});220factor.add_word("kernel", "over", "primitive", function(next) {221 var stack = factor.cont.data_stack;222 stack[stack.length] = stack[stack.length-2];223 factor.call_next(next);224});225factor.add_word("kernel", "pick", "primitive", function(next) {226 var stack = factor.cont.data_stack;227 stack[stack.length] = stack[stack.length-3];228 factor.call_next(next);229});230factor.add_word("kernel", "swap", "primitive", function(next) {231 var stack = factor.cont.data_stack;232 var temp = stack[stack.length-2];233 stack[stack.length-2] = stack[stack.length-1];234 stack[stack.length-1] = temp;235 factor.call_next(next);236});237factor.add_word("kernel", ">r", "primitive", function(next) {238 var data_stack = factor.cont.data_stack;239 var retain_stack = factor.cont.retain_stack;240 retain_stack.push(data_stack.pop());241 factor.call_next(next);242});243factor.add_word("kernel", "r>", "primitive", function(next) {244 var data_stack = factor.cont.data_stack;245 var retain_stack = factor.cont.retain_stack;246 data_stack.push(retain_stack.pop());247 factor.call_next(next);248});249factor.add_word("kernel", "call", "primitive", function(next) {250 var quot = factor.cont.data_stack.pop();251 quot.execute(next);252});253factor.add_word("kernel", "execute", "primitive", function(next) {254 var quot = factor.cont.data_stack.pop();255 quot.execute(next);256});257factor.add_word("kernel", "clear", "primitive", function(next) {258 factor.cont.data_stack = [];259 factor.cont.retain_stack = [];260 factor.call_next(next);261});262factor.add_word("kernel", "if", "primitive", function(next) { 263 var stack = factor.cont.data_stack;264 var else_quot = stack.pop();265 var then_quot = stack.pop();266 var condition = stack.pop();267 if(condition) {268 then_quot.execute(next);269 } else {270 else_quot.execute(next);271 }272});273factor.add_word("kernel", "f", "primitive", function(next) { 274 factor.cont.data_stack.push(false);275 factor.call_next(next);276});277factor.add_word("kernel", "t", "primitive", function(next) { 278 factor.cont.data_stack.push(true);279 factor.call_next(next);280});281factor.add_word("kernel", "=", "primitive", function(next) { 282 var stack = factor.cont.data_stack;283 stack.push(stack.pop()==stack.pop());284 factor.call_next(next);285});286factor.add_word("kernel", "bootstrap", "primitive", function(next) { 287 factor.cont.data_stack.push("/responder/fjsc-resources/bootstrap.factor");288 factor.get_word("parser", "run-file").execute(next);289});290factor.add_word("kernel", "callcc0", "primitive", function(next) { 291 var data_stack = factor.cont.data_stack;292 var quot = data_stack.pop();293 var new_cont = factor.cont.clone(); 294 var old_next = factor.cont.next;295 factor.cont.next = function() {296 factor.cont.next = old_next;297 factor.call_next(next);298 }299 new_cont.data_stack.push(factor.cont);300 factor.cont = new_cont;301 quot.execute(next); 302});303factor.add_word("kernel", "callcc1", "primitive", function(next) { 304 factor.get_word("kernel", "callcc0").execute(next);305});306factor.add_word("kernel", "continue", "primitive", function(next) { 307 var data_stack = factor.cont.data_stack;308 var cont = data_stack.pop(); 309 factor.cont = cont.clone();310 factor.call_next(cont.next);311});312factor.add_word("kernel", "continue-with", "primitive", function(next) { 313 var data_stack = factor.cont.data_stack;314 var cont = data_stack.pop(); 315 var data = data_stack.pop(); 316 factor.cont = cont.clone();317 factor.cont.data_stack.push(data);318 factor.call_next(cont.next);319});320factor.add_word("kernel", "set-in", "primitive", function(next) { 321 var stack = factor.cont.data_stack;322 var vocab = stack.pop();323 var v = factor.vocabs[vocab];324 if(!v) {325 v = { };326 factor.vocabs[vocab] = v;327 }328 factor.in_vocab = vocab;329 factor.call_next(next); 330});331factor.add_word("kernel", "current-vocab", "primitive", function(next) { 332 var stack = factor.cont.data_stack;333 stack.push(factor.in_vocab);334 factor.call_next(next); 335});336factor.add_word("kernel", "use+", "primitive", function(next) { 337 var stack = factor.cont.data_stack;338 var vocab = stack.pop();339 var v = factor.vocabs[vocab];340 if(!v) {341 v = { };342 factor.vocabs[vocab] = v;343 }344 factor.using_vocabs.push(vocab);345 factor.call_next(next); 346});347factor.add_word("kernel", "using", "primitive", function(next) { 348 var stack = factor.cont.data_stack;349 var vocabs = stack.pop();350 for(var i=0;i<vocabs.length;++i) { 351 var v = factor.vocabs[vocabs[i]];352 if(!v) {353 v = { };354 factor.vocabs[vocabs[i]] = v;355 }356 factor.using_vocabs.push(vocabs[i]);357 }358 factor.call_next(next); 359});360factor.add_word("kernel", "current-using", "primitive", function(next) { 361 var stack = factor.cont.data_stack;362 stack.push(factor.using_vocabs);363 factor.call_next(next); 364});365factor.add_word("kernel", "forget", "primitive", function(next) { 366 var stack = factor.cont.data_stack;367 var word = stack.pop();368 factor.remove_word(word.vocab, word.name);369 factor.call_next(next); 370});371factor.add_word("kernel", ">function", "primitive", function(next) { 372 var stack = factor.cont.data_stack;373 var word = stack.pop();374 stack.push(function() { word.func(function() { }) });375 factor.call_next(next); 376});377factor.add_word("kernel", "curry", "primitive", function(next) { 378 var stack = factor.cont.data_stack;379 var quot = stack.pop();380 var value = stack.pop();381 382 stack.push(factor.make_quotation("quotation", function(next) {383 factor.cont.data_stack.push(value); 384 quot.execute(factor.cont.next);385 }));386 factor.call_next(next);387});388/* Math vocabulary */389factor.add_word("math", "*", "primitive", function(next) {390 var stack = factor.cont.data_stack;391 stack.push(stack.pop() * stack.pop());392 factor.call_next(next);393});394factor.add_word("math", "+", "primitive", function(next) {395 var stack = factor.cont.data_stack;396 stack.push(stack.pop() + stack.pop());397 factor.call_next(next);398});399factor.add_word("math", "-", "primitive", function(next) {400 var stack = factor.cont.data_stack;401 var v1 = stack.pop();402 var v2 = stack.pop();403 stack.push(v2 - v1);404 factor.call_next(next);405});406factor.add_word("math", "/", "primitive", function(next) {407 var stack = factor.cont.data_stack;408 var v1 = stack.pop();409 var v2 = stack.pop();410 stack.push(v2 / v1);411 factor.call_next(next);412});413factor.add_word("parser", "run-file", "primitive", function(next) { 414 var stack = factor.cont.data_stack;415 var url = stack.pop();416 $.get(url, function(result) {417 factor.server_eval(result, function() { }, next);418 });419});420factor.add_word("alien", "alien-invoke", "primitive", function(next) { 421 var stack = factor.cont.data_stack;422 var arg_types = stack.pop();423 var method_name = stack.pop();424 var library_name = stack.pop();425 var return_values = stack.pop();426 var obj = stack.pop();427 var args = [ ];428 for(var i = 0; i < arg_types.length; ++i) {429 args[i] = stack.pop();430 }431 var func = obj[method_name];432 if(method_name=="alert") {433 func = function(a) { alert(a); }434 }435 var v = func.apply(obj, args.reverse());436 if(return_values.length > 0)437 stack.push(v);438 factor.call_next(next);439});440factor.add_word("alien", "alien-property", "primitive", function(next) { 441 var stack = factor.cont.data_stack;442 var obj = stack.pop();443 var property_name = stack.pop();444 var v = obj[property_name];445 stack.push(v);446 factor.call_next(next);447});448factor.add_word("alien", "set-alien-property", "primitive", function(next) { 449 var stack = factor.cont.data_stack;450 var obj = stack.pop();451 var property_name = stack.pop();452 var data = stack.pop();453 obj[property_name] = v;454 factor.call_next(next);455});456factor.add_word("alien", "uneval", "primitive", function(next) {457 var stack = factor.cont.data_stack;458 stack.push(uneval(stack.pop()));459 factor.call_next(next);460});461factor.add_word("words", "vocabs", "primitive", function(next) { 462 var stack = factor.cont.data_stack;463 var result = [];464 for(v in factor.vocabs) {465 result.push(v);466 }467 stack.push(result);468 factor.call_next(next);469});470factor.add_word("words", "words", "primitive", function(next) { 471 var stack = factor.cont.data_stack;472 var vocab = factor.vocabs[stack.pop()];473 var result = [];474 for(w in vocab) {475 result.push(vocab[w]);476 }477 stack.push(result);478 factor.call_next(next);479});480factor.add_word("words", "all-words", "primitive", function(next) { 481 var stack = factor.cont.data_stack;482 var result = [];483 for(v in factor.vocabs) {484 for(w in factor.vocabs[v]) {485 result.push(factor.vocabs[v][w]);486 }487 }488 stack.push(result);489 factor.call_next(next);490});491/* Sequences vocabulary */492factor.add_word("sequences", "nth", "primitive", function(next) { 493 var stack = factor.cont.data_stack;494 var seq = stack.pop();495 var index = stack.pop();496 stack.push(seq[index]);497 factor.call_next(next);498});499factor.add_word("sequences", "first", "primitive", function(next) { 500 var stack = factor.cont.data_stack;501 var seq = stack.pop();502 stack.push(seq[0]);503 factor.call_next(next);504});505factor.add_word("sequences", "second", "primitive", function(next) { 506 var stack = factor.cont.data_stack;507 var seq = stack.pop();508 stack.push(seq[1]);509 factor.call_next(next);510});511factor.add_word("sequences", "third", "primitive", function(next) { 512 var stack = factor.cont.data_stack;513 var seq = stack.pop();514 stack.push(seq[2]);515 factor.call_next(next);516});517factor.add_word("sequences", "fourth", "primitive", function(next) { 518 var stack = factor.cont.data_stack;519 var seq = stack.pop();520 stack.push(seq[0]);521 factor.call_next(next);522});523factor.add_word("sequences", "first2", "primitive", function(next) { 524 var stack = factor.cont.data_stack;525 var seq = stack.pop();526 stack.push(seq[0],seq[1]);527 factor.call_next(next);528});529factor.add_word("sequences", "first3", "primitive", function(next) { 530 var stack = factor.cont.data_stack;531 var seq = stack.pop();532 stack.push(seq[0],seq[1],seq[2]);533 factor.call_next(next);534});535factor.add_word("sequences", "first4", "primitive", function(next) { 536 var stack = factor.cont.data_stack;537 var seq = stack.pop();538 stack.push(seq[0],seq[1],seq[2],seq[3]);539 factor.call_next(next);540});541factor.add_word("sequences", "each", "primitive", function(next) { 542 var stack = factor.cont.data_stack;543 var quot = stack.pop();544 var seq = stack.pop();545 for(var i=0;i<seq.length;++i) { 546 stack.push(seq[i]);547 quot.execute();548 }549 factor.call_next(next);550});551factor.add_word("sequences", "map", "primitive", function(next) { 552 var stack = factor.cont.data_stack;553 var quot = stack.pop();554 var seq = stack.pop();555 var result = [ ];556 for(var i=0;i<seq.length;++i) { 557 stack.push(seq[i]);558 quot.execute();559 result[i]=stack.pop();560 }561 stack.push(result);562 factor.call_next(next);563});564factor.add_word("sequences", "reduce", "primitive", function(next) { 565 var stack = factor.cont.data_stack;566 var quot = stack.pop();567 var prev = stack.pop();568 var seq = stack.pop();569 for(var i=0;i<seq.length;++i) { 570 stack.push(prev);571 stack.push(seq[i]);572 quot.execute();573 prev=stack.pop();Al574 }575 stack.push(prev);576 factor.call_next(next);577});578/* hashtables vocabulary */579factor.add_word("hashtables", "alist>hash", "primitive", function(next) { 580 var stack = factor.cont.data_stack;581 var alist = stack.pop();582 stack.push(new Hashtable().fromAlist(alist));583 factor.call_next(next);584});585factor.add_word("hashtables", "hash>alist", "primitive", function(next) { 586 var stack = factor.cont.data_stack;587 var hashtable = stack.pop();588 stack.push(hashtable.toAlist());589 factor.call_next(next);590});591factor.add_word("hashtables", "hash", "primitive", function(next) { 592 var stack = factor.cont.data_stack;593 var hashtable = stack.pop();594 var key = stack.pop();595 stack.push(hashtable.get(key));596 factor.call_next(next);597});598factor.add_word("hashtables", "set-hash", "primitive", function(next) { 599 var stack = factor.cont.data_stack;600 var hashtable = stack.pop();601 var key = stack.pop();602 var value = stack.pop();603 hashtable.set(key, value);604 factor.call_next(next);605});606factor.add_word("sequences", "hash-each", "primitive", function(next) { 607 var stack = factor.cont.data_stack;608 var quot = stack.pop();609 var hashtable = stack.pop().table;610 for(k in hashtable) { 611 var v = hashtable[k]; 612 stack.push(k, v);613 quot.execute();614 }615 factor.call_next(next);616});617factor.add_word("sequences", "hash-map", "primitive", function(next) { 618 var stack = factor.cont.data_stack;619 var quot = stack.pop();620 var hashtable = stack.pop().table;621 var result = [ ];622 for(k in hashtable) { 623 var v = hashtable[k];624 stack.push(k,v);625 quot.execute();626 result.push(stack.pop());627 }628 stack.push(result);629 factor.call_next(next);630});631/* browser-dom vocab */632factor.add_word("browser-dom", "window", "primitive", function(next) { 633 factor.cont.data_stack.push(window);634 factor.call_next(next);635});636factor.add_word("browser-dom", "document", "primitive", function(next) { 637 factor.cont.data_stack.push(document);638 factor.call_next(next);639});640factor.add_word("browser-dom", "load-script", "primitive", function(next) { 641 var stack = factor.cont.data_stack;642 $("head/script#jsonrequest").remove();643 var script = document.createElement("script");644 script.id = "jsonrequest"; 645 script.type = "text/javascript";646 script.src = stack.pop();647 $("head").append(script);648 factor.call_next(next); 649});650var handle_json = false;651factor.add_word("browser-dom", "json-request", "primitive", function(next) { 652 var stack = factor.cont.data_stack;653 handle_json = function(data) { 654 factor.cont.data_stack.push(data);655 factor.call_next(next);656 }657 factor.get_word("browser-dom", "load-script").execute();...
tags.js
Source:tags.js
...35 async.parallel([36 async.apply(db.setAdd, 'topic:' + tid + ':tags', tags),37 async.apply(db.sortedSetsAdd, keys, timestamp, tid),38 ], function (err) {39 next(err);40 });41 },42 function (next) {43 async.each(tags, updateTagCount, next);44 },45 ], callback);46 };47 function filterCategoryTags(tags, tid, callback) {48 async.waterfall([49 function (next) {50 Topics.getTopicField(tid, 'cid', next);51 },52 function (cid, next) {53 db.getSortedSetRange('cid:' + cid + ':tag:whitelist', 0, -1, next);54 },55 function (tagWhitelist, next) {56 if (!tagWhitelist.length) {57 return next(null, tags);58 }59 tags = tags.filter(function (tag) {60 return tagWhitelist.indexOf(tag) !== -1;61 });62 next(null, tags);63 },64 ], callback);65 }66 Topics.createEmptyTag = function (tag, callback) {67 if (!tag) {68 return callback(new Error('[[error:invalid-tag]]'));69 }70 tag = utils.cleanUpTag(tag, meta.config.maximumTagLength);71 if (tag.length < (meta.config.minimumTagLength || 3)) {72 return callback(new Error('[[error:tag-too-short]]'));73 }74 async.waterfall([75 function (next) {76 db.isSortedSetMember('tags:topic:count', tag, next);77 },78 function (isMember, next) {79 if (isMember) {80 return next();81 }82 db.sortedSetAdd('tags:topic:count', 0, tag, next);83 },84 ], callback);85 };86 Topics.updateTags = function (data, callback) {87 async.eachSeries(data, function (tagData, next) {88 db.setObject('tag:' + tagData.value, {89 color: tagData.color,90 bgColor: tagData.bgColor,91 }, next);92 }, callback);93 };94 Topics.renameTags = function (data, callback) {95 async.eachSeries(data, function (tagData, next) {96 renameTag(tagData.value, tagData.newName, next);97 }, callback);98 };99 function renameTag(tag, newTagName, callback) {100 if (!newTagName || tag === newTagName) {101 return setImmediate(callback);102 }103 async.waterfall([104 function (next) {105 Topics.createEmptyTag(newTagName, next);106 },107 function (next) {108 batch.processSortedSet('tag:' + tag + ':topics', function (tids, next) {109 async.waterfall([110 function (next) {111 db.sortedSetScores('tag:' + tag + ':topics', tids, next);112 },113 function (scores, next) {114 db.sortedSetAdd('tag:' + newTagName + ':topics', scores, tids, next);115 },116 function (next) {117 var keys = tids.map(function (tid) {118 return 'topic:' + tid + ':tags';119 });120 async.series([121 async.apply(db.sortedSetRemove, 'tag:' + tag + ':topics', tids),122 async.apply(db.setsRemove, keys, tag),123 async.apply(db.setsAdd, keys, newTagName),124 ], next);125 },126 ], next);127 }, next);128 },129 function (next) {130 Topics.deleteTag(tag, next);131 },132 function (next) {133 updateTagCount(newTagName, next);134 },135 ], callback);136 }137 function updateTagCount(tag, callback) {138 callback = callback || function () {};139 async.waterfall([140 function (next) {141 Topics.getTagTopicCount(tag, next);142 },143 function (count, next) {144 count = count || 0;145 db.sortedSetAdd('tags:topic:count', count, tag, next);146 },147 ], callback);148 }149 Topics.getTagTids = function (tag, start, stop, callback) {150 db.getSortedSetRevRange('tag:' + tag + ':topics', start, stop, callback);151 };152 Topics.getTagTopicCount = function (tag, callback) {153 db.sortedSetCard('tag:' + tag + ':topics', callback);154 };155 Topics.deleteTags = function (tags, callback) {156 if (!Array.isArray(tags) || !tags.length) {157 return callback();158 }159 async.series([160 function (next) {161 removeTagsFromTopics(tags, next);162 },163 function (next) {164 var keys = tags.map(function (tag) {165 return 'tag:' + tag + ':topics';166 });167 db.deleteAll(keys, next);168 },169 function (next) {170 db.sortedSetRemove('tags:topic:count', tags, next);171 },172 function (next) {173 db.deleteAll(tags.map(function (tag) {174 return 'tag:' + tag;175 }), next);176 },177 ], function (err) {178 callback(err);179 });180 };181 function removeTagsFromTopics(tags, callback) {182 async.eachLimit(tags, 50, function (tag, next) {183 db.getSortedSetRange('tag:' + tag + ':topics', 0, -1, function (err, tids) {184 if (err || !tids.length) {185 return next(err);186 }187 var keys = tids.map(function (tid) {188 return 'topic:' + tid + ':tags';189 });190 db.setsRemove(keys, tag, next);191 });192 }, callback);193 }194 Topics.deleteTag = function (tag, callback) {195 Topics.deleteTags([tag], callback);196 };197 Topics.getTags = function (start, stop, callback) {198 async.waterfall([199 function (next) {200 db.getSortedSetRevRangeWithScores('tags:topic:count', start, stop, next);201 },202 function (tags, next) {203 Topics.getTagData(tags, next);204 },205 ], callback);206 };207 Topics.getTagData = function (tags, callback) {208 var keys = tags.map(function (tag) {209 return 'tag:' + tag.value;210 });211 async.waterfall([212 function (next) {213 db.getObjects(keys, next);214 },215 function (tagData, next) {216 tags.forEach(function (tag, index) {217 tag.valueEscaped = validator.escape(String(tag.value));218 tag.color = tagData[index] ? tagData[index].color : '';219 tag.bgColor = tagData[index] ? tagData[index].bgColor : '';220 });221 next(null, tags);222 },223 ], callback);224 };225 Topics.getTopicTags = function (tid, callback) {226 db.getSetMembers('topic:' + tid + ':tags', callback);227 };228 Topics.getTopicsTags = function (tids, callback) {229 var keys = tids.map(function (tid) {230 return 'topic:' + tid + ':tags';231 });232 db.getSetsMembers(keys, callback);233 };234 Topics.getTopicTagsObjects = function (tid, callback) {235 Topics.getTopicsTagsObjects([tid], function (err, data) {236 callback(err, Array.isArray(data) && data.length ? data[0] : []);237 });238 };239 Topics.getTopicsTagsObjects = function (tids, callback) {240 var sets = tids.map(function (tid) {241 return 'topic:' + tid + ':tags';242 });243 var uniqueTopicTags;244 var topicTags;245 async.waterfall([246 function (next) {247 db.getSetsMembers(sets, next);248 },249 function (_topicTags, next) {250 topicTags = _topicTags;251 uniqueTopicTags = _.uniq(_.flatten(topicTags));252 var tags = uniqueTopicTags.map(function (tag) {253 return { value: tag };254 });255 async.parallel({256 tagData: function (next) {257 Topics.getTagData(tags, next);258 },259 counts: function (next) {260 db.sortedSetScores('tags:topic:count', uniqueTopicTags, next);261 },262 }, next);263 },264 function (results, next) {265 results.tagData.forEach(function (tag, index) {266 tag.score = results.counts[index] ? results.counts[index] : 0;267 });268 var tagData = _.zipObject(uniqueTopicTags, results.tagData);269 topicTags.forEach(function (tags, index) {270 if (Array.isArray(tags)) {271 topicTags[index] = tags.map(function (tag) { return tagData[tag]; });272 topicTags[index].sort(function (tag1, tag2) {273 return tag2.score - tag1.score;274 });275 }276 });277 next(null, topicTags);278 },279 ], callback);280 };281 Topics.updateTopicTags = function (tid, tags, callback) {282 callback = callback || function () {};283 async.waterfall([284 function (next) {285 Topics.deleteTopicTags(tid, next);286 },287 function (next) {288 Topics.getTopicField(tid, 'timestamp', next);289 },290 function (timestamp, next) {291 Topics.createTags(tags, tid, timestamp, next);292 },293 ], callback);294 };295 Topics.deleteTopicTags = function (tid, callback) {296 async.waterfall([297 function (next) {298 Topics.getTopicTags(tid, next);299 },300 function (tags, next) {301 async.series([302 function (next) {303 db.delete('topic:' + tid + ':tags', next);304 },305 function (next) {306 var sets = tags.map(function (tag) {307 return 'tag:' + tag + ':topics';308 });309 db.sortedSetsRemove(sets, tid, next);310 },311 function (next) {312 async.each(tags, function (tag, next) {313 updateTagCount(tag, next);314 }, next);315 },316 ], next);317 },318 ], function (err) {319 callback(err);320 });321 };322 Topics.searchTags = function (data, callback) {323 if (!data || !data.query) {324 return callback(null, []);325 }326 async.waterfall([327 function (next) {328 if (plugins.hasListeners('filter:topics.searchTags')) {329 plugins.fireHook('filter:topics.searchTags', { data: data }, next);330 } else {331 findMatches(data.query, 0, next);332 }333 },334 function (result, next) {335 plugins.fireHook('filter:tags.search', { data: data, matches: result.matches }, next);336 },337 function (result, next) {338 next(null, result.matches);339 },340 ], callback);341 };342 Topics.autocompleteTags = function (data, callback) {343 if (!data || !data.query) {344 return callback(null, []);345 }346 async.waterfall([347 function (next) {348 if (plugins.hasListeners('filter:topics.autocompleteTags')) {349 plugins.fireHook('filter:topics.autocompleteTags', { data: data }, next);350 } else {351 findMatches(data.query, data.cid, next);352 }353 },354 function (result, next) {355 next(null, result.matches);356 },357 ], callback);358 };359 function findMatches(query, cid, callback) {360 async.waterfall([361 function (next) {362 if (parseInt(cid, 10)) {363 db.getSortedSetRange('cid:' + cid + ':tag:whitelist', 0, -1, next);364 } else {365 setImmediate(next, null, []);366 }367 },368 function (tagWhitelist, next) {369 if (tagWhitelist.length) {370 setImmediate(next, null, tagWhitelist);371 } else {372 db.getSortedSetRevRange('tags:topic:count', 0, -1, next);373 }374 },375 function (tags, next) {376 query = query.toLowerCase();377 var matches = [];378 for (var i = 0; i < tags.length; i += 1) {379 if (tags[i].toLowerCase().startsWith(query)) {380 matches.push(tags[i]);381 if (matches.length > 19) {382 break;383 }384 }385 }386 matches = matches.sort(function (a, b) {387 return a > b;388 });389 next(null, { matches: matches });390 },391 ], callback);392 }393 Topics.searchAndLoadTags = function (data, callback) {394 var searchResult = {395 tags: [],396 matchCount: 0,397 pageCount: 1,398 };399 if (!data || !data.query || !data.query.length) {400 return callback(null, searchResult);401 }402 async.waterfall([403 function (next) {404 Topics.searchTags(data, next);405 },406 function (tags, next) {407 async.parallel({408 counts: function (next) {409 db.sortedSetScores('tags:topic:count', tags, next);410 },411 tagData: function (next) {412 tags = tags.map(function (tag) {413 return { value: tag };414 });415 Topics.getTagData(tags, next);416 },417 }, next);418 },419 function (results, next) {420 results.tagData.forEach(function (tag, index) {421 tag.score = results.counts[index];422 });423 results.tagData.sort(function (a, b) {424 return b.score - a.score;425 });426 searchResult.tags = results.tagData;427 searchResult.matchCount = results.tagData.length;428 searchResult.pageCount = 1;429 next(null, searchResult);430 },431 ], callback);432 };433 Topics.getRelatedTopics = function (topicData, uid, callback) {434 if (plugins.hasListeners('filter:topic.getRelatedTopics')) {435 return plugins.fireHook('filter:topic.getRelatedTopics', { topic: topicData, uid: uid }, callback);436 }437 var maximumTopics = parseInt(meta.config.maximumRelatedTopics, 10) || 0;438 if (maximumTopics === 0 || !topicData.tags || !topicData.tags.length) {439 return callback(null, []);440 }441 maximumTopics = maximumTopics || 5;442 async.waterfall([443 function (next) {444 async.map(topicData.tags, function (tag, next) {445 Topics.getTagTids(tag.value, 0, 5, next);446 }, next);447 },448 function (tids, next) {449 tids = _.shuffle(_.uniq(_.flatten(tids))).slice(0, maximumTopics);450 Topics.getTopics(tids, uid, next);451 },452 function (topics, next) {453 topics = topics.filter(function (topic) {454 return topic && !topic.deleted && parseInt(topic.uid, 10) !== parseInt(uid, 10);455 });456 next(null, topics);457 },458 ], callback);459 };...
General.js
Source:General.js
1'use strict';2var General = require('./GeneralService');3module.exports.addmultisigaddress = function addmultisigaddress (req, res, next) {4 General.addmultisigaddress(req.swagger.params, res, next);5};6module.exports.dumpprivkey = function dumpprivkey (req, res, next) {7 General.dumpprivkey(req.swagger.params, res, next);8};9module.exports.dumpwallet = function dumpwallet (req, res, next) {10 General.dumpwallet(req.swagger.params, res, next);11};12module.exports.encryptwallet = function encryptwallet (req, res, next) {13 General.encryptwallet(req.swagger.params, res, next);14};15module.exports.generate = function generate (req, res, next) {16 General.generate(req.swagger.params, res, next);17};18module.exports.generatepublickey = function generatepublickey (req, res, next) {19 General.generatepublickey(req.swagger.params, res, next);20};21module.exports.getaccount = function getaccount (req, res, next) {22 General.getaccount(req.swagger.params, res, next);23};24module.exports.getaccountaddress = function getaccountaddress (req, res, next) {25 General.getaccountaddress(req.swagger.params, res, next);26};27module.exports.getaddressesbyaccount = function getaddressesbyaccount (req, res, next) {28 General.getaddressesbyaccount(req.swagger.params, res, next);29};30module.exports.getbalance = function getbalance (req, res, next) {31 General.getbalance(req.swagger.params, res, next);32};33module.exports.getblock = function getblock (req, res, next) {34 General.getblock(req.swagger.params, res, next);35};36module.exports.getblockchaininfo = function getblockchaininfo (req, res, next) {37 General.getblockchaininfo(req.swagger.params, res, next);38};39module.exports.getblockcount = function getblockcount (req, res, next) {40 General.getblockcount(req.swagger.params, res, next);41};42module.exports.getinfo = function getinfo (req, res, next) {43 General.getinfo(req.swagger.params, res, next);44};45module.exports.getmempoolinfo = function getmempoolinfo (req, res, next) {46 General.getmempoolinfo(req.swagger.params, res, next);47}48module.exports.getdifficulty = function getdifficulty (req, res, next) {49 General.getdifficulty(req.swagger.params, res, next);50}51module.exports.getmininginfo = function getmininginfo (req, res, next) {52 General.getmininginfo(req.swagger.params, res, next);53};54module.exports.getnetworkinfo = function getnetworkinfo (req, res, next) {55 General.getnetworkinfo(req.swagger.params, res, next);56};57module.exports.getnewaddress = function getnewaddress (req, res, next) {58 General.getnewaddress(req.swagger.params, res, next);59};60module.exports.getpeerinfo = function getpeerinfo (req, res, next) {61 General.getpeerinfo(req.swagger.params, res, next);62};63module.exports.getreceivedbyaccount = function getreceivedbyaccount (req, res, next) {64 General.getreceivedbyaccount(req.swagger.params, res, next);65};66module.exports.getreceivedbyaddress = function getreceivedbyaddress (req, res, next) {67 General.getreceivedbyaddress(req.swagger.params, res, next);68};69module.exports.gettransaction = function gettransaction (req, res, next) {70 General.gettransaction(req.swagger.params, res, next);71};72module.exports.getunconfirmedbalance = function getunconfirmedbalance (req, res, next) {73 General.getunconfirmedbalance(req.swagger.params, res, next);74};75module.exports.getwalletinfo = function getwalletinfo (req, res, next) {76 General.getwalletinfo(req.swagger.params, res, next);77};78module.exports.importaddress = function importaddress (req, res, next) {79 General.importaddress(req.swagger.params, res, next);80};81module.exports.importprivkey = function importprivkey (req, res, next) {82 General.importprivkey(req.swagger.params, res, next);83};84module.exports.importpubkey = function importpubkey (req, res, next) {85 General.importpubkey(req.swagger.params, res, next);86};87module.exports.importwallet = function importwallet (req, res, next) {88 General.importwallet(req.swagger.params, res, next);89};90module.exports.listaccounts = function listaccounts (req, res, next) {91 General.listaccounts(req.swagger.params, res, next);92};93module.exports.listaddressgroupings = function listaddressgroupings (req, res, next) {94 General.listaddressgroupings(req.swagger.params, res, next);95};96module.exports.listreceivedbyaccount = function listreceivedbyaccount (req, res, next) {97 General.listreceivedbyaccount(req.swagger.params, res, next);98};99module.exports.listreceivedbyaddress = function listreceivedbyaddress (req, res, next) {100 General.listreceivedbyaddress(req.swagger.params, res, next);101};102module.exports.listsinceblock = function listsinceblock (req, res, next) {103 General.listsinceblock(req.swagger.params, res, next);104};105module.exports.listtransactions = function listtransactions (req, res, next) {106 General.listtransactions(req.swagger.params, res, next);107};108module.exports.listunspent = function listunspent (req, res, next) {109 General.listunspent(req.swagger.params, res, next);110};111module.exports.move = function move (req, res, next) {112 General.move(req.swagger.params, res, next);113};114module.exports.sendfrom = function sendfrom (req, res, next) {115 General.sendfrom(req.swagger.params, res, next);116};117module.exports.sendmany = function sendmany (req, res, next) {118 General.sendmany(req.swagger.params, res, next);119};120module.exports.sendtoaddress = function sendtoaddress (req, res, next) {121 General.sendtoaddress(req.swagger.params, res, next);122};123module.exports.signmessage = function signmessage (req, res, next) {124 General.signmessage(req.swagger.params, res, next);125};126module.exports.syscoindecoderawtransaction = function syscoindecoderawtransaction (req, res, next) {127 General.syscoindecoderawtransaction(req.swagger.params, res, next);128};129module.exports.validateaddress = function validateaddress (req, res, next) {130 General.validateaddress(req.swagger.params, res, next);131};132module.exports.verifymessage = function verifymessage (req, res, next) {133 General.verifymessage(req.swagger.params, res, next);134};135module.exports.walletlock = function walletlock (req, res, next) {136 General.walletlock(req.swagger.params, res, next);137};138module.exports.walletpassphrase = function walletpassphrase (req, res, next) {139 General.walletpassphrase(req.swagger.params, res, next);140};141module.exports.walletpassphrasechange = function walletpassphrasechange (req, res, next) {142 General.walletpassphrasechange(req.swagger.params, res, next);143};144module.exports.syscoinlistreceivedbyaddress = function syscoinlistreceivedbyaddress (req, res, next) {145 General.syscoinlistreceivedbyaddress(req.swagger.params, res, next);146};147module.exports.getaddressbalance = function getaddressbalance (req, res, next) {148 console.log(req.swagger.params);149 General.getaddressbalance(req.swagger.params, res, next);150};151module.exports.getaddressdeltas = function getaddressdeltas (req, res, next) {152 General.getaddressdeltas(req.swagger.params, res, next);153};154module.exports.getaddressmempool = function getaddressmempool (req, res, next) {155 General.getaddressmempool(req.swagger.params, res, next);156};157module.exports.syscoinsendrawtransaction = function getaddressmempool (req, res, next) {158 General.syscoinsendrawtransaction(req.swagger.params, res, next);159};160module.exports.getgenerate = function getgenerate (req, res, next) {161 General.getgenerate(req.swagger.params, res, next);162};163module.exports.setgenerate = function setgenerate (req, res, next) {164 General.setgenerate(req.swagger.params, res, next);165};166module.exports.setnetworkactive = function setnetworkactive (req, res, next) {167 General.setnetworkactive(req.swagger.params, res, next);168};169module.exports.mnsync = function mnsync (req, res, next) {170 General.mnsync(req.swagger.params, res, next);171};172module.exports.dumphdinfo = function dumphdinfo (req, res, next) {173 General.dumphdinfo(req.swagger.params, res, next);174};175module.exports.debug = function debug (req, res, next) {176 General.debug(req.swagger.params, res, next);177};178module.exports.instantsendtoaddress = function debug (req, res, next) {179 General.instantsendtoaddress(req.swagger.params, res, next);180};181module.exports.getaddresstxids = function getaddresstxids (req, res, next) {182 General.getaddresstxids(req.swagger.params, res, next);183};184module.exports.getblockhashes = function getblockhashes (req, res, next) {185 General.getblockhashes(req.swagger.params, res, next);186};187module.exports.getblockhash = function getblockhash (req, res, next) {188 General.getblockhash(req.swagger.params, res, next);189}190module.exports.getblockheaders = function getblockheaders (req, res, next) {191 General.getblockheaders(req.swagger.params, res, next);192};193module.exports.getchaintips = function getchaintips (req, res, next) {194 General.getchaintips(req.swagger.params, res, next);195};196module.exports.getspentinfo = function getspentinfo (req, res, next) {197 General.getspentinfo(req.swagger.params, res, next);198};199module.exports.getgovernanceinfo = function getgovernanceinfo (req, res, next) {200 General.getgovernanceinfo(req.swagger.params, res, next);201};202module.exports.getpoolinfo = function getpoolinfo (req, res, next) {203 General.getpoolinfo(req.swagger.params, res, next);204};205module.exports.getsuperblockbudget = function getsuperblockbudget (req, res, next) {206 General.getsuperblockbudget(req.swagger.params, res, next);207};208module.exports.gobject = function gobject (req, res, next) {209 General.gobject(req.swagger.params, res, next);210};211module.exports.masternode = function masternode (req, res, next) {212 General.masternode(req.swagger.params, res, next);213};214module.exports.masternodebroadcast = function masternodebroadcast (req, res, next) {215 General.masternodebroadcast(req.swagger.params, res, next);216};217module.exports.masternodelist = function masternodelist (req, res, next) {218 General.masternodelist(req.swagger.params, res, next);219};220module.exports.fundrawtransaction = function masternodelist (req, res, next) {221 General.fundrawtransaction(req.swagger.params, res, next);222};223module.exports.getblocktemplate = function masternodelist (req, res, next) {224 General.getblocktemplate(req.swagger.params, res, next);225};226module.exports.signrawtransaction = function masternodelist (req, res, next) {227 General.signrawtransaction(req.swagger.params, res, next);228};229module.exports.lockunspent = function masternodelist (req, res, next) {230 General.lockunspent(req.swagger.params, res, next);231};232module.exports.getaddressutxos = function getaddressutxos (req, res, next) {233 General.getaddressutxos(req.swagger.params, res, next);234};235module.exports.setaccount = function setaccount (req, res, next) {236 General.setaccount(req.swagger.params, res, next);237};238module.exports.resendwallettransactions = function resendwallettransactions (req, res, next) {239 General.resendwallettransactions(req.swagger.params, res, next);...
create.js
Source:create.js
...78 ], next);79 },80 function (results, next) {81 plugins.fireHook('action:topic.save', { topic: _.clone(topicData) });82 next(null, topicData.tid);83 },84 ], callback);85 };86 Topics.post = function (data, callback) {87 var uid = data.uid;88 data.title = String(data.title).trim();89 data.tags = data.tags || [];90 async.waterfall([91 function (next) {92 check(data.title, meta.config.minimumTitleLength, meta.config.maximumTitleLength, 'title-too-short', 'title-too-long', next);93 },94 function (next) {95 check(data.tags, meta.config.minimumTagsPerTopic, meta.config.maximumTagsPerTopic, 'not-enough-tags', 'too-many-tags', next);96 },97 function (next) {98 if (data.content) {99 data.content = utils.rtrim(data.content);100 }101 check(data.content, meta.config.minimumPostLength, meta.config.maximumPostLength, 'content-too-short', 'content-too-long', next);102 },103 function (next) {104 async.parallel({105 categoryExists: function (next) {106 categories.exists(data.cid, next);107 },108 canCreate: function (next) {109 privileges.categories.can('topics:create', data.cid, data.uid, next);110 },111 canTag: function (next) {112 if (!data.tags.length) {113 return next(null, true);114 }115 privileges.categories.can('topics:tag', data.cid, data.uid, next);116 },117 }, next);118 },119 function (results, next) {120 if (!results.categoryExists) {121 return next(new Error('[[error:no-category]]'));122 }123 if (!results.canCreate || !results.canTag) {124 return next(new Error('[[error:no-privileges]]'));125 }126 guestHandleValid(data, next);127 },128 function (next) {129 user.isReadyToPost(data.uid, data.cid, next);130 },131 function (next) {132 plugins.fireHook('filter:topic.post', data, next);133 },134 function (filteredData, next) {135 data = filteredData;136 Topics.create(data, next);137 },138 function (tid, next) {139 var postData = data;140 postData.tid = tid;141 postData.ip = data.req ? data.req.ip : null;142 postData.isMain = true;143 posts.create(postData, next);144 },145 function (postData, next) {146 onNewPost(postData, data, next);147 },148 function (postData, next) {149 async.parallel({150 postData: function (next) {151 next(null, postData);152 },153 settings: function (next) {154 user.getSettings(uid, function (err, settings) {155 if (err) {156 return next(err);157 }158 if (settings.followTopicsOnCreate) {159 Topics.follow(postData.tid, uid, next);160 } else {161 next();162 }163 });164 },165 topicData: function (next) {166 Topics.getTopicsByTids([postData.tid], uid, next);167 },168 }, next);169 },170 function (result, next) {171 if (!Array.isArray(result.topicData) || !result.topicData.length) {172 return next(new Error('[[error:no-topic]]'));173 }174 result.topicData = result.topicData[0];175 result.topicData.unreplied = 1;176 result.topicData.mainPost = result.postData;177 result.postData.index = 0;178 analytics.increment(['topics', 'topics:byCid:' + result.topicData.cid]);179 plugins.fireHook('action:topic.post', { topic: result.topicData, post: result.postData, data: data });180 if (parseInt(uid, 10)) {181 user.notifications.sendTopicNotificationToFollowers(uid, result.topicData, result.postData);182 }183 next(null, {184 topicData: result.topicData,185 postData: result.postData,186 });187 },188 ], callback);189 };190 Topics.reply = function (data, callback) {191 var tid = data.tid;192 var uid = data.uid;193 var postData;194 async.waterfall([195 function (next) {196 Topics.getTopicField(tid, 'cid', next);197 },198 function (cid, next) {199 data.cid = cid;200 async.parallel({201 topicData: async.apply(Topics.getTopicData, tid),202 canReply: async.apply(privileges.topics.can, 'topics:reply', tid, uid),203 isAdminOrMod: async.apply(privileges.categories.isAdminOrMod, data.cid, uid),204 }, next);205 },206 function (results, next) {207 if (!results.topicData) {208 return next(new Error('[[error:no-topic]]'));209 }210 if (parseInt(results.topicData.locked, 10) === 1 && !results.isAdminOrMod) {211 return next(new Error('[[error:topic-locked]]'));212 }213 if (parseInt(results.topicData.deleted, 10) === 1 && !results.isAdminOrMod) {214 return next(new Error('[[error:topic-deleted]]'));215 }216 if (!results.canReply) {217 return next(new Error('[[error:no-privileges]]'));218 }219 guestHandleValid(data, next);220 },221 function (next) {222 user.isReadyToPost(uid, data.cid, next);223 },224 function (next) {225 plugins.fireHook('filter:topic.reply', data, next);226 },227 function (filteredData, next) {228 if (data.content) {229 data.content = utils.rtrim(data.content);230 }231 check(data.content, meta.config.minimumPostLength, meta.config.maximumPostLength, 'content-too-short', 'content-too-long', next);232 },233 function (next) {234 data.ip = data.req ? data.req.ip : null;235 posts.create(data, next);236 },237 function (_postData, next) {238 postData = _postData;239 onNewPost(postData, data, next);240 },241 function (postData, next) {242 user.getSettings(uid, next);243 },244 function (settings, next) {245 if (settings.followTopicsOnReply) {246 Topics.follow(postData.tid, uid);247 }248 if (parseInt(uid, 10)) {249 user.setUserField(uid, 'lastonline', Date.now());250 }251 Topics.notifyFollowers(postData, uid);252 analytics.increment(['posts', 'posts:byCid:' + data.cid]);253 plugins.fireHook('action:topic.reply', { post: _.clone(postData), data: data });254 next(null, postData);255 },256 ], callback);257 };258 function onNewPost(postData, data, callback) {259 var tid = postData.tid;260 var uid = postData.uid;261 async.waterfall([262 function (next) {263 Topics.markAsUnreadForAll(tid, next);264 },265 function (next) {266 Topics.markAsRead([tid], uid, next);267 },268 function (markedRead, next) {269 async.parallel({270 userInfo: function (next) {271 posts.getUserInfoForPosts([postData.uid], uid, next);272 },273 topicInfo: function (next) {274 Topics.getTopicFields(tid, ['tid', 'title', 'slug', 'cid', 'postcount', 'mainPid'], next);275 },276 parents: function (next) {277 Topics.addParentPosts([postData], next);278 },279 content: function (next) {280 posts.parsePost(postData, next);281 },282 }, next);283 },284 function (results, next) {285 postData.user = results.userInfo[0];286 postData.topic = results.topicInfo;287 postData.index = parseInt(results.topicInfo.postcount, 10) - 1;288 // Username override for guests, if enabled289 if (parseInt(meta.config.allowGuestHandles, 10) === 1 && parseInt(postData.uid, 10) === 0 && data.handle) {290 postData.user.username = validator.escape(String(data.handle));291 }292 postData.votes = 0;293 postData.bookmarked = false;294 postData.display_edit_tools = true;295 postData.display_delete_tools = true;296 postData.display_moderator_tools = true;297 postData.display_move_tools = true;298 postData.selfPost = false;299 postData.timestampISO = utils.toISOString(postData.timestamp);300 postData.topic.title = String(postData.topic.title);301 next(null, postData);302 },303 ], callback);304 }305 function check(item, min, max, minError, maxError, callback) {306 // Trim and remove HTML (latter for composers that send in HTML, like redactor)307 if (typeof item === 'string') {308 item = utils.stripHTMLTags(item).trim();309 }310 if (item === null || item === undefined || item.length < parseInt(min, 10)) {311 return callback(new Error('[[error:' + minError + ', ' + min + ']]'));312 } else if (item.length > parseInt(max, 10)) {313 return callback(new Error('[[error:' + maxError + ', ' + max + ']]'));314 }315 callback();...
tokenize.js
Source:tokenize.js
1const openBracket = '{'.charCodeAt(0);2const closeBracket = '}'.charCodeAt(0);3const openParen = '('.charCodeAt(0);4const closeParen = ')'.charCodeAt(0);5const singleQuote = "'".charCodeAt(0);6const doubleQuote = '"'.charCodeAt(0);7const backslash = '\\'.charCodeAt(0);8const slash = '/'.charCodeAt(0);9const period = '.'.charCodeAt(0);10const comma = ','.charCodeAt(0);11const colon = ':'.charCodeAt(0);12const asterisk = '*'.charCodeAt(0);13const minus = '-'.charCodeAt(0);14const plus = '+'.charCodeAt(0);15const pound = '#'.charCodeAt(0);16const newline = '\n'.charCodeAt(0);17const space = ' '.charCodeAt(0);18const feed = '\f'.charCodeAt(0);19const tab = '\t'.charCodeAt(0);20const cr = '\r'.charCodeAt(0);21const at = '@'.charCodeAt(0);22const lowerE = 'e'.charCodeAt(0);23const upperE = 'E'.charCodeAt(0);24const digit0 = '0'.charCodeAt(0);25const digit9 = '9'.charCodeAt(0);26const lowerU = 'u'.charCodeAt(0);27const upperU = 'U'.charCodeAt(0);28const atEnd = /[ \n\t\r\{\(\)'"\\;,/]/g;29const wordEnd = /[ \n\t\r\(\)\{\}\*:;@!&'"\+\|~>,\[\]\\]|\/(?=\*)/g;30const wordEndNum = /[ \n\t\r\(\)\{\}\*:;@!&'"\-\+\|~>,\[\]\\]|\//g;31const alphaNum = /^[a-z0-9]/i;32const unicodeRange = /^[a-f0-9?\-]/i;33const util = require('util');34const TokenizeError = require('./errors/TokenizeError');35module.exports = function tokenize(input, options) {36 options = options || {};37 const tokens = [];38 const css = input.valueOf();39 const length = css.length;40 let offset = -1;41 let line = 1;42 let pos = 0;43 let parentCount = 0;44 let isURLArg = null;45 let code;46 let next;47 let quote;48 let lines;49 let last;50 let content;51 let escape;52 let nextLine;53 let nextOffset;54 let escaped;55 let escapePos;56 let nextChar;57 function unclosed(what) {58 const message = util.format(59 'Unclosed %s at line: %d, column: %d, token: %d',60 what,61 line,62 pos - offset,63 pos64 );65 throw new TokenizeError(message);66 }67 function tokenizeError() {68 const message = util.format(69 'Syntax error at line: %d, column: %d, token: %d',70 line,71 pos - offset,72 pos73 );74 throw new TokenizeError(message);75 }76 while (pos < length) {77 code = css.charCodeAt(pos);78 if (code === newline) {79 offset = pos;80 line += 1;81 }82 switch (code) {83 case newline:84 case space:85 case tab:86 case cr:87 case feed:88 next = pos;89 do {90 next += 1;91 code = css.charCodeAt(next);92 if (code === newline) {93 offset = next;94 line += 1;95 }96 } while (97 code === space ||98 code === newline ||99 code === tab ||100 code === cr ||101 code === feed102 );103 tokens.push(['space', css.slice(pos, next), line, pos - offset, line, next - offset, pos]);104 pos = next - 1;105 break;106 case colon:107 next = pos + 1;108 tokens.push(['colon', css.slice(pos, next), line, pos - offset, line, next - offset, pos]);109 pos = next - 1;110 break;111 case comma:112 next = pos + 1;113 tokens.push(['comma', css.slice(pos, next), line, pos - offset, line, next - offset, pos]);114 pos = next - 1;115 break;116 case openBracket:117 tokens.push(['{', '{', line, pos - offset, line, next - offset, pos]);118 break;119 case closeBracket:120 tokens.push(['}', '}', line, pos - offset, line, next - offset, pos]);121 break;122 case openParen:123 parentCount++;124 isURLArg =125 !isURLArg &&126 parentCount === 1 &&127 tokens.length > 0 &&128 tokens[tokens.length - 1][0] === 'word' &&129 tokens[tokens.length - 1][1] === 'url';130 tokens.push(['(', '(', line, pos - offset, line, next - offset, pos]);131 break;132 case closeParen:133 parentCount--;134 isURLArg = !isURLArg && parentCount === 1;135 tokens.push([')', ')', line, pos - offset, line, next - offset, pos]);136 break;137 case singleQuote:138 case doubleQuote:139 quote = code === singleQuote ? "'" : '"';140 next = pos;141 do {142 escaped = false;143 next = css.indexOf(quote, next + 1);144 if (next === -1) {145 unclosed('quote', quote);146 }147 escapePos = next;148 while (css.charCodeAt(escapePos - 1) === backslash) {149 escapePos -= 1;150 escaped = !escaped;151 }152 } while (escaped);153 tokens.push([154 'string',155 css.slice(pos, next + 1),156 line,157 pos - offset,158 line,159 next - offset,160 pos161 ]);162 pos = next;163 break;164 case at:165 atEnd.lastIndex = pos + 1;166 atEnd.test(css);167 if (atEnd.lastIndex === 0) {168 next = css.length - 1;169 } else {170 next = atEnd.lastIndex - 2;171 }172 tokens.push([173 'atword',174 css.slice(pos, next + 1),175 line,176 pos - offset,177 line,178 next - offset,179 pos180 ]);181 pos = next;182 break;183 case backslash:184 next = pos;185 code = css.charCodeAt(next + 1);186 if (187 escape &&188 (code !== slash &&189 code !== space &&190 code !== newline &&191 code !== tab &&192 code !== cr &&193 code !== feed)194 ) {195 next += 1;196 }197 tokens.push([198 'word',199 css.slice(pos, next + 1),200 line,201 pos - offset,202 line,203 next - offset,204 pos205 ]);206 pos = next;207 break;208 case plus:209 case minus:210 case asterisk:211 next = pos + 1;212 nextChar = css.slice(pos + 1, next + 1);213 const prevChar = css.slice(pos - 1, pos);214 // if the operator is immediately followed by a word character, then we215 // have a prefix of some kind, and should fall-through. eg. -webkit216 // look for --* for custom variables217 if (code === minus && nextChar.charCodeAt(0) === minus) {218 next++;219 tokens.push(['word', css.slice(pos, next), line, pos - offset, line, next - offset, pos]);220 pos = next - 1;221 break;222 }223 tokens.push([224 'operator',225 css.slice(pos, next),226 line,227 pos - offset,228 line,229 next - offset,230 pos231 ]);232 pos = next - 1;233 break;234 default:235 if (236 code === slash &&237 (css.charCodeAt(pos + 1) === asterisk ||238 (options.loose && !isURLArg && css.charCodeAt(pos + 1) === slash))239 ) {240 const isStandardComment = css.charCodeAt(pos + 1) === asterisk;241 if (isStandardComment) {242 next = css.indexOf('*/', pos + 2) + 1;243 if (next === 0) {244 unclosed('comment', '*/');245 }246 } else {247 const newlinePos = css.indexOf('\n', pos + 2);248 next = newlinePos !== -1 ? newlinePos - 1 : length;249 }250 content = css.slice(pos, next + 1);251 lines = content.split('\n');252 last = lines.length - 1;253 if (last > 0) {254 nextLine = line + last;255 nextOffset = next - lines[last].length;256 } else {257 nextLine = line;258 nextOffset = offset;259 }260 tokens.push(['comment', content, line, pos - offset, nextLine, next - nextOffset, pos]);261 offset = nextOffset;262 line = nextLine;263 pos = next;264 } else if (code === pound && !alphaNum.test(css.slice(pos + 1, pos + 2))) {265 next = pos + 1;266 tokens.push(['#', css.slice(pos, next), line, pos - offset, line, next - offset, pos]);267 pos = next - 1;268 } else if ((code === lowerU || code === upperU) && css.charCodeAt(pos + 1) === plus) {269 next = pos + 2;270 do {271 next += 1;272 code = css.charCodeAt(next);273 } while (next < length && unicodeRange.test(css.slice(next, next + 1)));274 tokens.push([275 'unicoderange',276 css.slice(pos, next),277 line,278 pos - offset,279 line,280 next - offset,281 pos282 ]);283 pos = next - 1;284 }285 // catch a regular slash, that isn't a comment286 else if (code === slash) {287 next = pos + 1;288 tokens.push([289 'operator',290 css.slice(pos, next),291 line,292 pos - offset,293 line,294 next - offset,295 pos296 ]);297 pos = next - 1;298 } else {299 let regex = wordEnd;300 // we're dealing with a word that starts with a number301 // those get treated differently302 if (code >= digit0 && code <= digit9) {303 regex = wordEndNum;304 }305 regex.lastIndex = pos + 1;306 regex.test(css);307 if (regex.lastIndex === 0) {308 next = css.length - 1;309 } else {310 next = regex.lastIndex - 2;311 }312 // Exponential number notation with minus or plus: 1e-10, 1e+10313 if (regex === wordEndNum || code === period) {314 const ncode = css.charCodeAt(next);315 const ncode1 = css.charCodeAt(next + 1);316 const ncode2 = css.charCodeAt(next + 2);317 if (318 (ncode === lowerE || ncode === upperE) &&319 (ncode1 === minus || ncode1 === plus) &&320 (ncode2 >= digit0 && ncode2 <= digit9)321 ) {322 wordEndNum.lastIndex = next + 2;323 wordEndNum.test(css);324 if (wordEndNum.lastIndex === 0) {325 next = css.length - 1;326 } else {327 next = wordEndNum.lastIndex - 2;328 }329 }330 }331 tokens.push([332 'word',333 css.slice(pos, next + 1),334 line,335 pos - offset,336 line,337 next - offset,338 pos339 ]);340 pos = next;341 }342 break;343 }344 pos++;345 }346 return tokens;...
delete.js
Source:delete.js
...39 ], next);40 },41 function (results, next) {42 plugins.fireHook('action:post.delete', { post: _.clone(postData), uid: uid });43 next(null, postData);44 },45 ], callback);46 };47 Posts.restore = function (pid, uid, callback) {48 var postData;49 async.waterfall([50 function (next) {51 plugins.fireHook('filter:post.restore', { pid: pid, uid: uid }, next);52 },53 function (data, next) {54 Posts.setPostFields(pid, { deleted: 0, deleterUid: 0 }, next);55 },56 function (next) {57 Posts.getPostFields(pid, ['pid', 'tid', 'uid', 'content', 'timestamp'], next);58 },59 function (_post, next) {60 postData = _post;61 topics.getTopicFields(_post.tid, ['tid', 'cid', 'pinned'], next);62 },63 function (topicData, next) {64 postData.cid = topicData.cid;65 async.parallel([66 function (next) {67 updateTopicTimestamp(topicData, next);68 },69 function (next) {70 db.sortedSetAdd('cid:' + topicData.cid + ':pids', postData.timestamp, pid, next);71 },72 function (next) {73 topics.updateTeaser(postData.tid, next);74 },75 ], next);76 },77 function (results, next) {78 plugins.fireHook('action:post.restore', { post: _.clone(postData), uid: uid });79 next(null, postData);80 },81 ], callback);82 };83 function updateTopicTimestamp(topicData, callback) {84 var timestamp;85 async.waterfall([86 function (next) {87 topics.getLatestUndeletedPid(topicData.tid, next);88 },89 function (pid, next) {90 if (!parseInt(pid, 10)) {91 return callback();92 }93 Posts.getPostField(pid, 'timestamp', next);94 },95 function (_timestamp, next) {96 timestamp = _timestamp;97 if (!parseInt(timestamp, 10)) {98 return callback();99 }100 topics.updateTimestamp(topicData.tid, timestamp, next);101 },102 function (next) {103 if (parseInt(topicData.pinned, 10) !== 1) {104 db.sortedSetAdd('cid:' + topicData.cid + ':tids', timestamp, topicData.tid, next);105 } else {106 next();107 }108 },109 ], callback);110 }111 Posts.purge = function (pid, uid, callback) {112 async.waterfall([113 function (next) {114 Posts.exists(pid, next);115 },116 function (exists, next) {117 if (!exists) {118 return callback();119 }120 plugins.fireHook('filter:post.purge', { pid: pid, uid: uid }, next);121 },122 function (data, next) {123 async.parallel([124 function (next) {125 deletePostFromTopicUserNotification(pid, next);126 },127 function (next) {128 deletePostFromCategoryRecentPosts(pid, next);129 },130 function (next) {131 deletePostFromUsersBookmarks(pid, next);132 },133 function (next) {134 deletePostFromUsersVotes(pid, next);135 },136 function (next) {137 deletePostFromReplies(pid, next);138 },139 function (next) {140 deletePostFromGroups(pid, next);141 },142 function (next) {143 db.sortedSetsRemove(['posts:pid', 'posts:votes', 'posts:flagged'], pid, next);144 },145 ], function (err) {146 next(err);147 });148 },149 function (next) {150 Posts.getPostData(pid, next);151 },152 function (postData, next) {153 plugins.fireHook('action:post.purge', { post: postData, uid: uid });154 db.delete('post:' + pid, next);155 },156 ], callback);157 };158 function deletePostFromTopicUserNotification(pid, callback) {159 var postData;160 async.waterfall([...
queue.js
Source:queue.js
...22 data: data,23 }, next);24 },25 function (result, next) {26 next(null, result.shouldQueue);27 },28 ], callback);29 };30 Posts.addToQueue = function (data, callback) {31 var type = data.title ? 'topic' : 'reply';32 var id = type + '-' + Date.now();33 async.waterfall([34 function (next) {35 canPost(type, data, next);36 },37 function (next) {38 db.sortedSetAdd('post:queue', Date.now(), id, next);39 },40 function (next) {41 db.setObject('post:queue:' + id, {42 id: id,43 uid: data.uid,44 type: type,45 data: JSON.stringify(data),46 }, next);47 },48 function (next) {49 user.setUserField(data.uid, 'lastqueuetime', Date.now(), next);50 },51 function (next) {52 async.parallel({53 notification: function (next) {54 notifications.create({55 type: 'post-queue',56 nid: 'post-queue-' + id,57 mergeId: 'post-queue',58 bodyShort: '[[notifications:post_awaiting_review]]',59 bodyLong: data.content,60 path: '/post-queue',61 }, next);62 },63 cid: function (next) {64 getCid(type, data, next);65 },66 }, next);67 },68 function (results, next) {69 if (results.notification) {70 notifications.pushGroups(results.notification, ['administrators', 'Global Moderators', 'cid:' + results.cid + ':privileges:moderate'], next);71 } else {72 next();73 }74 },75 function (next) {76 next(null, {77 id: id,78 type: type,79 queued: true,80 message: '[[success:post-queued]]',81 });82 },83 ], callback);84 };85 function getCid(type, data, callback) {86 if (type === 'topic') {87 return setImmediate(callback, null, data.cid);88 } else if (type === 'reply') {89 topics.getTopicField(data.tid, 'cid', callback);90 } else {91 return setImmediate(callback, null, null);92 }93 }94 function canPost(type, data, callback) {95 async.waterfall([96 function (next) {97 getCid(type, data, next);98 },99 function (cid, next) {100 async.parallel({101 canPost: function (next) {102 if (type === 'topic') {103 privileges.categories.can('topics:create', cid, data.uid, next);104 } else if (type === 'reply') {105 privileges.categories.can('topics:reply', cid, data.uid, next);106 }107 },108 isReadyToQueue: function (next) {109 user.isReadyToQueue(data.uid, cid, next);110 },111 }, next);112 },113 function (results, next) {114 if (!results.canPost) {115 return next(new Error('[[error:no-privileges]]'));116 }117 next();118 },119 ], callback);120 }121 Posts.removeFromQueue = function (id, callback) {122 async.waterfall([123 function (next) {124 db.sortedSetRemove('post:queue', id, next);125 },126 function (next) {127 db.delete('post:queue:' + id, next);128 },129 function (next) {130 notifications.rescind('post-queued-' + id, next);131 },132 ], callback);133 };134 Posts.submitFromQueue = function (id, callback) {135 async.waterfall([136 function (next) {137 getParsedObject(id, next);138 },139 function (data, next) {140 if (!data) {141 return callback();142 }143 if (data.type === 'topic') {144 createTopic(data.data, next);145 } else if (data.type === 'reply') {146 createReply(data.data, next);147 }148 },149 function (next) {150 Posts.removeFromQueue(id, next);151 },152 ], callback);153 };154 function getParsedObject(id, callback) {155 async.waterfall([156 function (next) {157 db.getObject('post:queue:' + id, next);158 },159 function (data, next) {160 if (!data) {161 return callback();162 }163 try {164 data.data = JSON.parse(data.data);165 } catch (err) {166 return next(err);167 }168 next(null, data);169 },170 ], callback);171 }172 function createTopic(data, callback) {173 async.waterfall([174 function (next) {175 topics.post(data, next);176 },177 function (result, next) {178 socketHelpers.notifyNew(data.uid, 'newTopic', { posts: [result.postData], topic: result.topicData });179 next();180 },181 ], callback);182 }183 function createReply(data, callback) {184 async.waterfall([185 function (next) {186 topics.reply(data, next);187 },188 function (postData, next) {189 var result = {190 posts: [postData],191 'reputation:disabled': parseInt(meta.config['reputation:disabled'], 10) === 1,192 'downvote:disabled': parseInt(meta.config['downvote:disabled'], 10) === 1,193 };194 socketHelpers.notifyNew(data.uid, 'newPost', result);195 next();196 },197 ], callback);198 }199 Posts.editQueuedContent = function (uid, id, content, callback) {200 async.waterfall([201 function (next) {202 Posts.canEditQueue(uid, id, next);203 },204 function (canEditQueue, next) {205 if (!canEditQueue) {206 return callback(new Error('[[error:no-privileges]]'));207 }208 getParsedObject(id, next);209 },210 function (data, next) {211 if (!data) {212 return callback();213 }214 data.data.content = content;215 db.setObjectField('post:queue:' + id, 'data', JSON.stringify(data.data), next);216 },217 ], callback);218 };219 Posts.canEditQueue = function (uid, id, callback) {220 async.waterfall([221 function (next) {222 async.parallel({223 isAdminOrGlobalMod: function (next) {224 user.isAdminOrGlobalMod(uid, next);225 },226 data: function (next) {227 getParsedObject(id, next);228 },229 }, next);230 },231 function (results, next) {232 if (results.isAdminOrGlobalMod) {233 return callback(null, true);234 }235 if (!results.data) {236 return callback(null, false);237 }238 if (results.data.type === 'topic') {239 next(null, results.data.data.cid);240 } else if (results.data.type === 'reply') {241 topics.getTopicField(results.data.data.tid, 'cid', next);242 }243 },244 function (cid, next) {245 user.isModerator(uid, cid, next);246 },247 ], callback);248 };...
Using AI Code Generation
1import { storiesOf } from '@storybook/react'2import { action } from '@storybook/addon-actions'3import { linkTo } from '@storybook/addon-links'4import { Button, Welcome } from '@storybook/react/demo'5storiesOf('Welcome', module).add('to Storybook', () => <Welcome showApp={linkTo('Button')} />)6storiesOf('Button', module)7 .add('with text', () => (8 <Button onClick={action('clicked')}>Hello Button</Button>9 .add('with some emoji', () => (10 <Button onClick={action('clicked')}>π π π π―</Button>11storiesOf('Button', module)12 .add('with text', () => (13 <Button onClick={action('clicked')}>Hello Button</Button>14 .add('with some emoji', () => (15 <Button onClick={action('clicked')}>π π π π―</Button>16storiesOf('Button', module)17 .add('with text', () => (18 <Button onClick={action('clicked')}>Hello Button</Button>19 .add('with some emoji', () => (20 <Button onClick={action('clicked')}>π π π π―</Button>21storiesOf('Button', module)22 .add('with text', () => (23 <Button onClick={action('clicked')}>Hello Button</Button>24 .add('with some emoji', () => (25 <Button onClick={action('clicked')}>π π π π―</Button>26storiesOf('Button', module)27 .add('with text', () => (28 <Button onClick={action('clicked')}>Hello Button</Button>29 .add('with some emoji', () => (30 <Button onClick={action('clicked')}>π π π π―</Button>31storiesOf('Button', module)32 .add('with text', () => (33 <Button onClick={action('clicked')}>Hello Button</Button>
Using AI Code Generation
1import { storiesOf } from '@storybook/react';2import { action } from '@storybook/addon-actions';3import { linkTo } from '@storybook/addon-links';4import { withInfo } from '@storybook/addon-info';5import { withKnobs, text, boolean, number } from '@storybook/addon-knobs/react';6import { withNotes } from '@storybook/addon-notes';7import { withOptions } from '@storybook/addon-options';8import { withViewport } from '@storybook/addon-viewport';9import { withConsole } from '@storybook/addon-console';10import { withBackgrounds } from '@storybook/addon-backgrounds';11storiesOf('Addon|withInfo', module)12 .addDecorator(withInfo)13 .addDecorator(withKnobs)14 .addDecorator(withNotes)15 .addDecorator(withOptions)16 .addDecorator(withViewport)17 .addDecorator(withConsole)18 .addDecorator(withBackgrounds)19 .add('with text', () => <button onClick={action('clicked')}>Hello Button</button>, {20 })21 .add('with some emoji', () => (22 <button onClick={action('clicked')}>23 .add('with some emoji and with a background', () => (24 <button onClick={action('clicked')}>25 .add('with some emoji and with a background', () => (26 <button onClick={action('clicked')}>27 .add('with some emoji and with a background', () => (28 <button onClick={action('clicked')}>29 .add('with some emoji and with a background', () => (30 <button onClick={action('clicked')}>
Using AI Code Generation
1next: function() {2 if (this.current < this.pages.length - 1) {3 this.current++;4 }5},6previous: function() {7 if (this.current > 0) {8 this.current--;9 }10},11next: function() {12 if (this.current < this.pages.length - 1) {13 this.current++;14 }15},16previous: function() {17 if (this.current > 0) {18 this.current--;19 }20},21next: function() {22 if (this.current < this.pages.length - 1) {23 this.current++;24 }25},26previous: function() {27 if (this.current > 0) {28 this.current--;29 }30},
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!