Overview
Comment: | [njs] Move check for loading dictionary in api |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | nodejs |
Files: | files | file ages | folders |
SHA3-256: |
c03dede353c8de6c86f03b2b06357c88 |
User & Date: | IllusionPerdu on 2018-10-22 11:15:03 |
Other Links: | branch diff | manifest | tags |
Context
2018-10-22
| ||
11:22 | [njs] Update doc check-in: b52fc4588c user: IllusionPerdu tags: nodejs | |
11:15 | [njs] Move check for loading dictionary in api check-in: c03dede353 user: IllusionPerdu tags: nodejs | |
2018-10-21
| ||
22:10 | [njs] cli possibility to change main and personal dictionary check-in: e22e75159b user: IllusionPerdu tags: nodejs | |
Changes
Modified gc_lang/fr/nodejs/cli/bin/gramma-cli.js from [facfd09481] to [05ea2921ae].
︙ | ︙ | |||
12 13 14 15 16 17 18 | Doc : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment https://stackoverflow.com/questions/41058569/what-is-the-difference-between-const-and-const-in-javascript */ const argCmd = require("../lib/minimist.js")(process.argv.slice(2)); const { performance } = require("perf_hooks"); | < < | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | Doc : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment https://stackoverflow.com/questions/41058569/what-is-the-difference-between-const-and-const-in-javascript */ const argCmd = require("../lib/minimist.js")(process.argv.slice(2)); const { performance } = require("perf_hooks"); //Initialisation des messages const msgStart = "\x1b[31mBienvenue sur Grammalecte pour NodeJS!!!\x1b[0m\n"; const msgPrompt = "\x1b[36mGrammaJS\x1b[33m>\x1b[0m "; const msgSuite = "\x1b[33m…\x1b[0m "; const msgEnd = "\x1b[31m\x1b[5m\x1b[5mBye bye!\x1b[0m"; |
︙ | ︙ | |||
415 416 417 418 419 420 421 | if (getArg(aArg, [action])) { repPreference[action] = getArgVal(aArg, [action]); repAction[action] = repPreference[action] ? "ON" : "OFF"; } } if (getArg(aArg, ["dicomain"])) { | < | < < < < | < < < | 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 | if (getArg(aArg, [action])) { repPreference[action] = getArgVal(aArg, [action]); repAction[action] = repPreference[action] ? "ON" : "OFF"; } } if (getArg(aArg, ["dicomain"])) { repAction["dicomain"] = "Chargement du dictionnaire principal " + (oGrammarChecker.setMainDictionary(sText) ? "OK" : "Pas OK"); } if (getArg(aArg, ["dicoperso"])) { repAction["dicoperso"] = "Chargement du dictionnaire personnel " + (oGrammarChecker.setPersonalDictionary(sText) ? "OK" : "Pas OK"); } for (const action of ["gceoption", "tfoption", "gcerule"]) { if (getArg(aArg, [action])) { let sFonction = action == "gceoption" ? "GceOption" : action == "tfoption" ? "TfOption" : "GceIgnoreRule"; let sOpt = sText.split(" "); if (sOpt[0] == "reset") { |
︙ | ︙ |
Modified gc_lang/fr/nodejs/core/api.js from [df78933803] to [af514e995f].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | /* ! Grammalecte, grammar checker ! API pour faciliter l'utilisation de Grammalecte. */ /* jshint esversion:6, -W097 */ /* jslint esversion:6 */ /* global require, exports, console */ "use strict"; class GrammarChecker { constructor(aInit, sLangCode = "fr", sContext = "Javascript") { this.sLangCode = sLangCode; this.sContext = sContext; //Importation des fichiers nécessaire this.sPathRoot = __dirname + "/grammalecte"; | > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | /* ! Grammalecte, grammar checker ! API pour faciliter l'utilisation de Grammalecte. */ /* jshint esversion:6, -W097 */ /* jslint esversion:6 */ /* global require, exports, console */ "use strict"; const path = require("path"); const fs = require("fs"); class GrammarChecker { constructor(aInit, sLangCode = "fr", sContext = "Javascript") { this.sLangCode = sLangCode; this.sContext = sContext; //Importation des fichiers nécessaire this.sPathRoot = __dirname + "/grammalecte"; |
︙ | ︙ | |||
193 194 195 196 197 198 199 | getGraphspell() { if (!this.isInit.Graphspell) { this.load(["Graphspell"]); } return this.oSpellChecker; } | | > > > > > > > > > | | > | > > > > > > > | > > > > > > > > > > > > | > > | 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | getGraphspell() { if (!this.isInit.Graphspell) { this.load(["Graphspell"]); } return this.oSpellChecker; } setMainDictionary(dictionary) { if (typeof dictionary == "string") { let pathnormalized = path.normalize(dictionary); if (pathnormalized == "fr-allvars" || pathnormalized == "fr-classic" || pathnormalized == "fr-reform") { pathnormalized = path.normalize(this.sPathRoot + "/graphspell/_dictionaries/" + pathnormalized); } pathnormalized = !pathnormalized.endsWith(".json") ? pathnormalized + ".json" : pathnormalized; if (fs.existsSync(pathnormalized)) { let filename = path.basename(pathnormalized); let dirname = path.dirname(pathnormalized); return this.oSpellChecker.setMainDictionary(filename, dirname); } return false; } //It's a valid json? if (typeof dictionary !== "undefined" && dictionary.sHeader && dictionary.sHeader.startsWith("/grammalecte-fsa/")) { return this.oSpellChecker.setMainDictionary(dictionary); } return false; } setPersonalDictionary(dictionary, bActivate = true) { if (typeof dictionary == "string") { let pathnormalized = path.normalize(dictionary); pathnormalized = !pathnormalized.endsWith(".json") ? pathnormalized + ".json" : pathnormalized; if (fs.existsSync(pathnormalized)) { let filename = path.basename(pathnormalized); let dirname = path.dirname(pathnormalized); return this.oSpellChecker.setPersonalDictionary(filename, dirname, bActivate); } return false; } //It's a valid json? if (typeof dictionary !== "undefined" && dictionary.sHeader && dictionary.sHeader.startsWith("/grammalecte-fsa/")) { return this.oSpellChecker.setPersonalDictionary(dictionary, bActivate); } return false; } spellParagraph(sText, bSuggest = true) { if (!this.isInit.Graphspell) { this.load(["Graphspell"]); } if (bSuggest) { |
︙ | ︙ |