pf2e-sage-stats 0.2.10 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/app.d.ts CHANGED
@@ -604,5 +604,4 @@ export declare const sortFolder: () => Promise<{
604
604
  oldname: string;
605
605
  newname: string;
606
606
  }[]>;
607
- export declare const screenPlay: (htmlContent: string) => string;
608
607
  export {};
package/dist/app.js CHANGED
@@ -1,26 +1,16 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
14
5
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.screenPlay = exports.sortFolder = exports.formatTracker = exports.newtracker = exports.formatHP = exports.formatTable = exports.formatCommand = exports.formatTSV = exports.flatten = exports.parseStatblock = exports.parseTracker = exports.parseJSON = exports.formatJSON = exports.fromatMap = exports.diceMap = exports.flatMap = exports.charSchema = exports.stub = void 0;
6
+ exports.sortFolder = exports.formatTracker = exports.newtracker = exports.formatHP = exports.formatTable = exports.formatCommand = exports.formatTSV = exports.flatten = exports.parseStatblock = exports.parseTracker = exports.parseJSON = exports.formatJSON = exports.fromatMap = exports.diceMap = exports.flatMap = exports.charSchema = exports.stub = void 0;
16
7
  const zod_1 = __importDefault(require("zod"));
17
8
  const tsv_1 = require("tsv");
9
+ const promises_1 = require("fs/promises");
18
10
  const lodash_1 = require("lodash");
19
11
  const dedent_js_1 = __importDefault(require("dedent-js"));
20
12
  const abbreviate_1 = __importDefault(require("abbreviate"));
21
13
  const pluralize_1 = __importDefault(require("pluralize"));
22
- const jsdom_1 = require("jsdom");
23
- const promises_1 = require("fs/promises");
24
14
  const schema = zod_1.default.object({
25
15
  name: zod_1.default.string(),
26
16
  alias: zod_1.default.string().optional(),
@@ -208,10 +198,34 @@ exports.charSchema = zod_1.default.object({
208
198
  conditions: zod_1.default.string().default(''),
209
199
  children: zod_1.default.array(childSchema).default([]),
210
200
  });
211
- exports.flatMap = Object.assign(Object.assign({}, ([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20].map((v) => ([`${v}`, `d20 >= ${v} flat;`])).reduce((p, [k, v]) => { p[k] = v; return p; }, {}))), { c: 'd20 >= 5 flat;', concealed: 'd20 >= 5 flat;', h: 'd20 >= 11 flat;', hidden: 'd20 >= 11 flat;' });
212
- exports.diceMap = Object.assign(Object.assign({}, ([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20].map((v) => ([`${v}`, `(${v})`])).reduce((p, [k, v]) => { p[k] = v; return p; }, {}))), { a: '+2', adv: '+2', advantage: '+2', d: '-2', dis: '-2', disadvantage: '-2', f: '+2', for: '+2', fort: '+2', fortune: '+2', m: '-2', mis: '-2', misfortune: '-2' });
201
+ exports.flatMap = {
202
+ ...([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20].map((v) => ([`${v}`, `d20 >= ${v} flat;`])).reduce((p, [k, v]) => { p[k] = v; return p; }, {})),
203
+ c: 'd20 >= 5 flat;',
204
+ concealed: 'd20 >= 5 flat;',
205
+ h: 'd20 >= 11 flat;',
206
+ hidden: 'd20 >= 11 flat;',
207
+ };
208
+ exports.diceMap = {
209
+ ...([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20].map((v) => ([`${v}`, `(${v})`])).reduce((p, [k, v]) => { p[k] = v; return p; }, {})),
210
+ a: '+2',
211
+ adv: '+2',
212
+ advantage: '+2',
213
+ d: '-2',
214
+ dis: '-2',
215
+ disadvantage: '-2',
216
+ f: '+2',
217
+ for: '+2',
218
+ fort: '+2',
219
+ fortune: '+2',
220
+ m: '-2',
221
+ mis: '-2',
222
+ misfortune: '-2',
223
+ };
213
224
  const fromatMap = (name, map) => {
214
- return tsv_1.TSV.stringify([Object.assign({ name }, map)]);
225
+ return tsv_1.TSV.stringify([{
226
+ name,
227
+ ...map,
228
+ }]);
215
229
  };
216
230
  exports.fromatMap = fromatMap;
217
231
  const dcByLevel = [13, 14, 15, 16, 18, 19, 20, 22, 23, 24, 26, 27, 28, 30, 31, 32, 34, 35, 36, 38, 39, 40, 42, 44, 46, 48, 50];
@@ -237,7 +251,7 @@ const locateInt = (name, statblock, section = null, signed = true, alias) => {
237
251
  return null;
238
252
  };
239
253
  const locateInts = (statblock, section, alias, signed = true) => {
240
- const regex = new RegExp(`(${section}|,)([^,]*?)${alias}\\s+(${signed ? '[+-]' : '-?'}\\d+)`, 'g');
254
+ const regex = new RegExp(`(${section}|,)((?:(?!${section})[^,])*?)${alias}\\s+(${signed ? '[+-]' : '-?'}\\d+)`, 'g');
241
255
  let matches = null;
242
256
  const output = [];
243
257
  // eslint-disable-next-line no-cond-assign
@@ -271,7 +285,7 @@ const locateIntsAfter = (statblock, alias, signed = true) => {
271
285
  return output.reduce((p, [key, name, value]) => { p[key] = { mod: value, name: name, info: [] }; return p; }, {});
272
286
  };
273
287
  const locateStrikes = (statblock, alias) => {
274
- const regex = new RegExp(`${alias}(\\s+\\[.+\\])?\\s+(.+?)\\s+(\\(x\\d+\\)\\s+)?([+-]\\d+)\\s*([\\S\\s]*?),\\s+(Damage|Effect)\\s+(\\S+\\s+\\S+.*?)(?=$|\\s+Melee|\\s+Ranged)`, 'gm');
288
+ const regex = new RegExp(`${alias}(\\s+\\[.+\\])?\\s+(.+?)\\s+(\\(x\\d+\\)\\s+)?([+-]\\d+)\\s*([\\S\\s]*?)[,;]?\\s+(Damage|Effect)\\s+(\\S+\\s+\\S+.*?)(?=$|\\s+Melee|\\s+Ranged)`, 'gm');
275
289
  let matches = null;
276
290
  const output = [];
277
291
  // eslint-disable-next-line no-cond-assign
@@ -343,7 +357,10 @@ const locateStrikes = (statblock, alias) => {
343
357
  const locateSpells = (statblock) => {
344
358
  const match = statblock.match(new RegExp(/Spells\s+DC\s+(\d+)(,\s+[Aa]ttack\s+([+-]\d+))?/));
345
359
  if (match && match[1]) {
346
- return Object.assign({ dc: parseInt(match[1]) }, (match[3] ? { attack: parseInt(match[3]) } : null));
360
+ return {
361
+ dc: parseInt(match[1]),
362
+ ...(match[3] ? { attack: parseInt(match[3]) } : null)
363
+ };
347
364
  }
348
365
  return null;
349
366
  };
@@ -357,7 +374,71 @@ const parseStatblock = (name, _statblock, alias) => {
357
374
  .replace('', '')
358
375
  .replace(/–/g, '-') + '\n';
359
376
  const basic = locateName(statblock);
360
- const result = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, defaults), basic), (name && { name: name })), { alias: alias !== null && alias !== void 0 ? alias : (0, abbreviate_1.default)((_a = name !== null && name !== void 0 ? name : basic === null || basic === void 0 ? void 0 : basic.name) !== null && _a !== void 0 ? _a : defaults.name, { length: 3 }).toLowerCase() }), locateInt('perception', statblock)), locateInt('ac', statblock, null, false, 'AC')), locateInt('maxhp', statblock, null, false, 'HP')), { attributes: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, defaults.attributes), locateInt('strength', statblock, null, true, 'Str')), locateInt('dexterity', statblock, null, true, 'Dex')), locateInt('constitution', statblock, null, true, 'Con')), locateInt('intelligence', statblock, null, true, 'Int')), locateInt('wisdom', statblock, null, true, 'Wis')), locateInt('charisma', statblock, null, true, 'Cha')), saves: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, defaults.saves), locateInt('fortitude', statblock, null, true, 'Fortitude')), locateInt('reflex', statblock, null, true, 'Reflex')), locateInt('fortitude', statblock, null, true, 'Fort')), locateInt('reflex', statblock, null, true, 'Ref')), locateInt('will', statblock, null, true, 'Will')), skills: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, defaults.skills), locateInt('acrobatics', statblock, 'Skills')), locateInt('arcana', statblock, 'Skills')), locateInt('athletics', statblock, 'Skills')), locateInt('crafting', statblock, 'Skills')), locateInt('deception', statblock, 'Skills')), locateInt('diplomacy', statblock, 'Skills')), locateInt('intimidation', statblock, 'Skills')), locateInt('medicine', statblock, 'Skills')), locateInt('nature', statblock, 'Skills')), locateInt('occultism', statblock, 'Skills')), locateInt('performance', statblock, 'Skills')), locateInt('religion', statblock, 'Skills')), locateInt('society', statblock, 'Skills')), locateInt('stealth', statblock, 'Skills')), locateInt('survival', statblock, 'Skills')), locateInt('thievery', statblock, 'Skills')), locateInt('piloting', statblock, 'Skills')), locateInt('computers', statblock, 'Skills')), lores: Object.assign(Object.assign({}, locateInts(statblock, 'Skills', 'Lore')), locateIntsAfter(statblock, 'Lore:')), melee: Object.assign({}, locateStrikes(statblock, 'Melee')), ranged: Object.assign({}, locateStrikes(statblock, 'Ranged')), spells: Object.assign({}, locateSpells(statblock)), extra: {}, extraDCs: Object.assign({}, locateInt('stealth', statblock, null, false, 'Stealth DC')), extraDice: {} });
377
+ const result = {
378
+ ...defaults,
379
+ ...basic,
380
+ ...(name && { name: name }),
381
+ ...{ alias: alias !== null && alias !== void 0 ? alias : (0, abbreviate_1.default)((_a = name !== null && name !== void 0 ? name : basic === null || basic === void 0 ? void 0 : basic.name) !== null && _a !== void 0 ? _a : defaults.name, { length: 3 }).toLowerCase() },
382
+ ...locateInt('perception', statblock),
383
+ ...locateInt('ac', statblock, null, false, 'AC'),
384
+ ...locateInt('maxhp', statblock, null, false, 'HP'),
385
+ attributes: {
386
+ ...defaults.attributes,
387
+ ...locateInt('strength', statblock, null, true, 'Str'),
388
+ ...locateInt('dexterity', statblock, null, true, 'Dex'),
389
+ ...locateInt('constitution', statblock, null, true, 'Con'),
390
+ ...locateInt('intelligence', statblock, null, true, 'Int'),
391
+ ...locateInt('wisdom', statblock, null, true, 'Wis'),
392
+ ...locateInt('charisma', statblock, null, true, 'Cha'),
393
+ },
394
+ saves: {
395
+ ...defaults.saves,
396
+ ...locateInt('fortitude', statblock, null, true, 'Fortitude'),
397
+ ...locateInt('reflex', statblock, null, true, 'Reflex'),
398
+ ...locateInt('fortitude', statblock, null, true, 'Fort'),
399
+ ...locateInt('reflex', statblock, null, true, 'Ref'),
400
+ ...locateInt('will', statblock, null, true, 'Will'),
401
+ },
402
+ skills: {
403
+ ...defaults.skills,
404
+ ...locateInt('acrobatics', statblock, 'Skills'),
405
+ ...locateInt('arcana', statblock, 'Skills'),
406
+ ...locateInt('athletics', statblock, 'Skills'),
407
+ ...locateInt('crafting', statblock, 'Skills'),
408
+ ...locateInt('deception', statblock, 'Skills'),
409
+ ...locateInt('diplomacy', statblock, 'Skills'),
410
+ ...locateInt('intimidation', statblock, 'Skills'),
411
+ ...locateInt('medicine', statblock, 'Skills'),
412
+ ...locateInt('nature', statblock, 'Skills'),
413
+ ...locateInt('occultism', statblock, 'Skills'),
414
+ ...locateInt('performance', statblock, 'Skills'),
415
+ ...locateInt('religion', statblock, 'Skills'),
416
+ ...locateInt('society', statblock, 'Skills'),
417
+ ...locateInt('stealth', statblock, 'Skills'),
418
+ ...locateInt('survival', statblock, 'Skills'),
419
+ ...locateInt('thievery', statblock, 'Skills'),
420
+ ...locateInt('piloting', statblock, 'Skills'),
421
+ ...locateInt('computers', statblock, 'Skills'),
422
+ },
423
+ lores: {
424
+ ...locateInts(statblock, 'Skills', 'Lore'),
425
+ ...locateIntsAfter(statblock, 'Lore:')
426
+ },
427
+ melee: {
428
+ ...locateStrikes(statblock, 'Melee'),
429
+ },
430
+ ranged: {
431
+ ...locateStrikes(statblock, 'Ranged'),
432
+ },
433
+ spells: {
434
+ ...locateSpells(statblock),
435
+ },
436
+ extra: {},
437
+ extraDCs: {
438
+ ...locateInt('stealth', statblock, null, false, 'Stealth DC'),
439
+ },
440
+ extraDice: {},
441
+ };
361
442
  result.untrained = improvisation ? (result.level >= 7 ? result.level : result.level >= 5 ? result.level - 1 : result.level - 2) : 0;
362
443
  result.bullwark = plate ? Math.max(3 - result.attributes.dexterity, 0) : 0;
363
444
  return result;
@@ -381,12 +462,35 @@ const toRanged = ([key, value]) => [
381
462
  const flatten = (stats, secretDC = false, defaultSkills = false) => {
382
463
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
383
464
  const untrained = stats.untrained;
384
- const skills = defaultSkills ? Object.assign({ acrobatics: untrained + stats.attributes.dexterity, arcana: untrained + stats.attributes.intelligence, athletics: untrained + stats.attributes.strength, crafting: untrained + stats.attributes.intelligence, deception: untrained + stats.attributes.charisma, diplomacy: untrained + stats.attributes.charisma, intimidation: untrained + stats.attributes.charisma, medicine: untrained + stats.attributes.wisdom, nature: untrained + stats.attributes.wisdom, occultism: untrained + stats.attributes.intelligence, performance: untrained + stats.attributes.charisma, religion: untrained + stats.attributes.wisdom, society: untrained + stats.attributes.intelligence, stealth: untrained + stats.attributes.dexterity, survival: untrained + stats.attributes.wisdom, thievery: untrained + stats.attributes.dexterity, piloting: untrained + stats.attributes.dexterity, computers: untrained + stats.attributes.intelligence }, stats.skills) : stats.skills;
385
- const lores = defaultSkills ? Object.assign(Object.assign({}, stats.lores), { other: {
465
+ const skills = defaultSkills ? {
466
+ acrobatics: untrained + stats.attributes.dexterity,
467
+ arcana: untrained + stats.attributes.intelligence,
468
+ athletics: untrained + stats.attributes.strength,
469
+ crafting: untrained + stats.attributes.intelligence,
470
+ deception: untrained + stats.attributes.charisma,
471
+ diplomacy: untrained + stats.attributes.charisma,
472
+ intimidation: untrained + stats.attributes.charisma,
473
+ medicine: untrained + stats.attributes.wisdom,
474
+ nature: untrained + stats.attributes.wisdom,
475
+ occultism: untrained + stats.attributes.intelligence,
476
+ performance: untrained + stats.attributes.charisma,
477
+ religion: untrained + stats.attributes.wisdom,
478
+ society: untrained + stats.attributes.intelligence,
479
+ stealth: untrained + stats.attributes.dexterity,
480
+ survival: untrained + stats.attributes.wisdom,
481
+ thievery: untrained + stats.attributes.dexterity,
482
+ piloting: untrained + stats.attributes.dexterity,
483
+ computers: untrained + stats.attributes.intelligence,
484
+ ...stats.skills,
485
+ } : stats.skills;
486
+ const lores = defaultSkills ? {
487
+ ...stats.lores,
488
+ other: {
386
489
  mod: untrained + stats.attributes.intelligence,
387
490
  name: "Other",
388
491
  info: ['untrained']
389
- } }) : stats.lores;
492
+ }
493
+ } : stats.lores;
390
494
  let melee = (0, lodash_1.entries)(stats.melee).map(([k, v]) => {
391
495
  var _a;
392
496
  return [k, {
@@ -416,7 +520,10 @@ const flatten = (stats, secretDC = false, defaultSkills = false) => {
416
520
  ];
417
521
  }
418
522
  const maxhp = stats.bump.default > 0 ? (stats.bump.hp ? (stats.bump.hp + stats.maxhp) : Math.max(Math.floor(stats.maxhp * 1.1), stats.maxhp + 10)) : stats.maxhp;
419
- const saveInfo = Object.assign(Object.assign({}, stats.saveInfo), { reflex: stats.bullwark > 0 ? [...stats.saveInfo.reflex, `+${stats.bullwark} more vs damage`] : stats.saveInfo.reflex });
523
+ const saveInfo = {
524
+ ...stats.saveInfo,
525
+ reflex: stats.bullwark > 0 ? [...stats.saveInfo.reflex, `+${stats.bullwark} more vs damage`] : stats.saveInfo.reflex,
526
+ };
420
527
  const untrainedSkillInfo = (0, lodash_1.entries)((0, lodash_1.mapValues)((0, lodash_1.groupBy)((0, lodash_1.difference)((0, lodash_1.keys)(skills), (0, lodash_1.keys)(stats.skills)), (k) => k), () => ['untrained']));
421
528
  const specifiedSkillInfo = (0, lodash_1.entries)(stats.skillInfo);
422
529
  const skillInfo = (0, lodash_1.mapValues)((0, lodash_1.groupBy)([...untrainedSkillInfo, ...specifiedSkillInfo], ([k]) => k), (list) => list.reduce((p, [, v]) => [...p, ...v], []));
@@ -435,7 +542,7 @@ const flatten = (stats, secretDC = false, defaultSkills = false) => {
435
542
  ['fort', stats.saves.fortitude + ((_c = stats.bump.saves) !== null && _c !== void 0 ? _c : stats.bump.default)],
436
543
  ['ref', stats.saves.reflex + ((_d = stats.bump.saves) !== null && _d !== void 0 ? _d : stats.bump.default)],
437
544
  ['perception', stats.perception + ((_e = stats.bump.perception) !== null && _e !== void 0 ? _e : stats.bump.default)],
438
- ...(0, lodash_1.entries)(skills.performance ? Object.assign(Object.assign({}, skills), { perfomance: skills.performance }) : skills).map(([k, v]) => { var _a; return [k, v + ((_a = stats.bump.skills) !== null && _a !== void 0 ? _a : stats.bump.default)]; }),
545
+ ...(0, lodash_1.entries)(skills.performance ? { ...skills, perfomance: skills.performance } : skills).map(([k, v]) => { var _a; return [k, v + ((_a = stats.bump.skills) !== null && _a !== void 0 ? _a : stats.bump.default)]; }),
439
546
  ...(0, lodash_1.entries)(lores).map(toLoreMod).map(([k, v]) => { var _a; return [k, v + ((_a = stats.bump.skills) !== null && _a !== void 0 ? _a : stats.bump.default)]; }),
440
547
  ...(0, lodash_1.entries)(lores).map(toLoreName),
441
548
  ...(0, lodash_1.entries)(lores).filter(([, v]) => v.info.length > 0).map(toLoreInfo),
@@ -587,56 +694,19 @@ const formatTracker = (tracker) => {
587
694
  return lines.join('\n');
588
695
  };
589
696
  exports.formatTracker = formatTracker;
590
- const sortFolder = () => __awaiter(void 0, void 0, void 0, function* () {
591
- const dir = yield (0, promises_1.readdir)('.');
592
- const summary = yield Promise.all(dir.map((file) => __awaiter(void 0, void 0, void 0, function* () {
593
- const stats = yield (0, promises_1.stat)(file);
697
+ const sortFolder = async () => {
698
+ const dir = await (0, promises_1.readdir)('.');
699
+ const summary = await Promise.all(dir.map(async (file) => {
700
+ const stats = await (0, promises_1.stat)(file);
594
701
  const timestamp = parseInt(stats.birthtimeMs.toFixed(0));
595
702
  return { file, timestamp };
596
- })));
703
+ }));
597
704
  const transformed = summary.sort((a, b) => a.timestamp - b.timestamp).map((s, index) => {
598
705
  const prefix = String(index + 1).padStart(3, '0');
599
706
  const name = s.file.replace('RU PFS Online - ', '').replace(/\s\[.+\]/, '');
600
707
  return { oldname: s.file, newname: name.startsWith('ooc') ? name : `${prefix} ${name}` };
601
708
  });
602
- yield Promise.all(transformed.map((t) => __awaiter(void 0, void 0, void 0, function* () { return (0, promises_1.rename)(t.oldname, t.newname); })));
709
+ await Promise.all(transformed.map(async (t) => (0, promises_1.rename)(t.oldname, t.newname)));
603
710
  return transformed;
604
- });
605
- exports.sortFolder = sortFolder;
606
- const screenPlay = (htmlContent) => {
607
- const dom = new jsdom_1.JSDOM(htmlContent);
608
- const document = dom.window.document;
609
- const outputLines = [];
610
- const preambleEntry = document.querySelector('.preamble__entry');
611
- if (preambleEntry) {
612
- outputLines.push(`SCENE: ${preambleEntry.textContent}`);
613
- outputLines.push('');
614
- }
615
- // Process all chatlog messages
616
- const messages = document.querySelectorAll('.chatlog__message');
617
- messages.forEach(message => {
618
- var _a, _b, _c, _d;
619
- const authorElement = message.querySelector('.chatlog__author');
620
- const contentElement = message.querySelector('.chatlog__content');
621
- if (!authorElement || !contentElement)
622
- return;
623
- const author = (_b = (_a = authorElement.textContent) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : '';
624
- const content = (_d = (_c = contentElement.textContent) === null || _c === void 0 ? void 0 : _c.trim()) !== null && _d !== void 0 ? _d : '';
625
- // Skip bot tags in character names
626
- const characterName = author.replace(/\s*BOT$/, '');
627
- // Add character line
628
- outputLines.push(`${characterName.toUpperCase()}`);
629
- // Add dialogue/content (wrap long lines)
630
- const lines = content.split('\n').map((c) => (c
631
- .replace(/(—|--)/g, '-')
632
- // eslint-disable-next-line no-irregular-whitespace
633
- .replace(/(​|​)/g, '')
634
- .trim())).filter((c) => c.length);
635
- for (const line of lines) {
636
- outputLines.push(` ${line}`);
637
- }
638
- outputLines.push('');
639
- });
640
- return outputLines.join('\n');
641
711
  };
642
- exports.screenPlay = screenPlay;
712
+ exports.sortFolder = sortFolder;
package/dist/index.js CHANGED
@@ -1,21 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
- return new (P || (P = Promise))(function (resolve, reject) {
6
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
- step((generator = generator.apply(thisArg, _arguments || [])).next());
10
- });
11
- };
12
- var __asyncValues = (this && this.__asyncValues) || function (o) {
13
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
14
- var m = o[Symbol.asyncIterator], i;
15
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
16
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
17
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
18
- };
19
3
  var __importDefault = (this && this.__importDefault) || function (mod) {
20
4
  return (mod && mod.__esModule) ? mod : { "default": mod };
21
5
  };
@@ -35,14 +19,14 @@ program
35
19
  program.command('stub')
36
20
  .description('Generte a stat JSON template')
37
21
  .option('-o, --output <file>', 'output json')
38
- .action((option) => __awaiter(void 0, void 0, void 0, function* () {
22
+ .action(async (option) => {
39
23
  if (option.output) {
40
- yield promises_1.default.writeFile(option.output, (0, app_1.formatJSON)(app_1.stub), { encoding: 'utf-8' });
24
+ await promises_1.default.writeFile(option.output, (0, app_1.formatJSON)(app_1.stub), { encoding: 'utf-8' });
41
25
  }
42
26
  else {
43
27
  console.log((0, app_1.formatJSON)(app_1.stub));
44
28
  }
45
- }));
29
+ });
46
30
  program.command('table')
47
31
  .description('Generte a table configuration string')
48
32
  .argument('<string>', 'table name')
@@ -52,65 +36,52 @@ program.command('table')
52
36
  .option('-c, --scenario <string>', 'scenario')
53
37
  .option('-g, --gm <string>', 'gm')
54
38
  .option('-p, --players <string>', 'players')
55
- .action((argument, option) => __awaiter(void 0, void 0, void 0, function* () {
39
+ .action(async (argument, option) => {
56
40
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
57
41
  if (option.output) {
58
- yield promises_1.default.writeFile(option.output, (0, app_1.formatTable)((_a = option.table) !== null && _a !== void 0 ? _a : '1', (_b = option.season) !== null && _b !== void 0 ? _b : '1', (_c = option.scenario) !== null && _c !== void 0 ? _c : '1', argument, (_d = option.gm) !== null && _d !== void 0 ? _d : '@lammonaaf', (_e = option.players) !== null && _e !== void 0 ? _e : '<players>'), { encoding: 'utf-8' });
42
+ await promises_1.default.writeFile(option.output, (0, app_1.formatTable)((_a = option.table) !== null && _a !== void 0 ? _a : '1', (_b = option.season) !== null && _b !== void 0 ? _b : '1', (_c = option.scenario) !== null && _c !== void 0 ? _c : '1', argument, (_d = option.gm) !== null && _d !== void 0 ? _d : '@lammonaaf', (_e = option.players) !== null && _e !== void 0 ? _e : '<players>'), { encoding: 'utf-8' });
59
43
  }
60
44
  else {
61
45
  console.log((0, app_1.formatTable)((_f = option.table) !== null && _f !== void 0 ? _f : '1', (_g = option.season) !== null && _g !== void 0 ? _g : '1', (_h = option.scenario) !== null && _h !== void 0 ? _h : '1', argument, (_j = option.gm) !== null && _j !== void 0 ? _j : '@lammonaaf', (_k = option.players) !== null && _k !== void 0 ? _k : '<players>'));
62
46
  }
63
- }));
47
+ });
64
48
  program.command('hp')
65
49
  .description('Generte an hp bar')
66
50
  .argument('<string>', 'hp/maxhp')
67
- .action((argument) => __awaiter(void 0, void 0, void 0, function* () {
51
+ .action(async (argument) => {
68
52
  console.log((0, app_1.formatHP)(argument));
69
- }));
53
+ });
70
54
  program.command('sort')
71
55
  .description('Sorts log file folder and renames files')
72
- .action(() => __awaiter(void 0, void 0, void 0, function* () {
73
- console.log(yield (0, app_1.sortFolder)());
74
- }));
75
- program.command('convert')
76
- .description('Convert a discord export file into a txt log')
77
- .argument('<file>', 'input file')
78
- .option('-o, --output <file>', 'output file')
79
- .action((argument, option) => __awaiter(void 0, void 0, void 0, function* () {
80
- const file = yield promises_1.default.readFile(argument, { encoding: 'utf-8' });
81
- if (option.output) {
82
- yield promises_1.default.writeFile(option.output, (0, app_1.screenPlay)(file), { encoding: 'utf-8' });
83
- }
84
- else {
85
- console.log((0, app_1.screenPlay)(file));
86
- }
87
- }));
56
+ .action(async () => {
57
+ console.log(await (0, app_1.sortFolder)());
58
+ });
88
59
  program.command('flat')
89
60
  .description('Generte a special flat npc tsv')
90
61
  .option('-n, --name <string>', 'npc name')
91
62
  .option('-o, --output <file>', 'output json')
92
- .action((option) => __awaiter(void 0, void 0, void 0, function* () {
63
+ .action(async (option) => {
93
64
  var _a, _b;
94
65
  if (option.output) {
95
- yield promises_1.default.writeFile(option.output, (0, app_1.fromatMap)((_a = option.name) !== null && _a !== void 0 ? _a : 'flat', app_1.flatMap), { encoding: 'utf-8' });
66
+ await promises_1.default.writeFile(option.output, (0, app_1.fromatMap)((_a = option.name) !== null && _a !== void 0 ? _a : 'flat', app_1.flatMap), { encoding: 'utf-8' });
96
67
  }
97
68
  else {
98
69
  console.log((0, app_1.fromatMap)((_b = option.name) !== null && _b !== void 0 ? _b : 'flat', app_1.flatMap));
99
70
  }
100
- }));
71
+ });
101
72
  program.command('dice')
102
73
  .description('Generte a special dice npc tsv')
103
74
  .option('-n, --name <string>', 'npc name')
104
75
  .option('-o, --output <file>', 'output json')
105
- .action((option) => __awaiter(void 0, void 0, void 0, function* () {
76
+ .action(async (option) => {
106
77
  var _a, _b;
107
78
  if (option.output) {
108
- yield promises_1.default.writeFile(option.output, (0, app_1.fromatMap)((_a = option.name) !== null && _a !== void 0 ? _a : 'dice', app_1.diceMap), { encoding: 'utf-8' });
79
+ await promises_1.default.writeFile(option.output, (0, app_1.fromatMap)((_a = option.name) !== null && _a !== void 0 ? _a : 'dice', app_1.diceMap), { encoding: 'utf-8' });
109
80
  }
110
81
  else {
111
82
  console.log((0, app_1.fromatMap)((_b = option.name) !== null && _b !== void 0 ? _b : 'dice', app_1.diceMap));
112
83
  }
113
- }));
84
+ });
114
85
  program.command('statblock')
115
86
  .description('Generte a stat JSON from Paizo creature statblock')
116
87
  .argument('<file>', 'input text file')
@@ -122,84 +93,84 @@ program.command('statblock')
122
93
  .option('-s, --secretDC', 'produce secret DCs (tsv only)')
123
94
  .option('-d, --defaultSkills', 'produce values for untrained skills (tsv only)')
124
95
  .option('-o, --output <file>', 'output file name')
125
- .action((argument, option) => __awaiter(void 0, void 0, void 0, function* () {
96
+ .action(async (argument, option) => {
126
97
  var _a, _b;
127
- const file = yield promises_1.default.readFile(argument, { encoding: 'utf-8' });
98
+ const file = await promises_1.default.readFile(argument, { encoding: 'utf-8' });
128
99
  const alias = (_a = option.alias) !== null && _a !== void 0 ? _a : (option.abbreviate ? null : (option.output ? path_1.default.parse(option.output).name : path_1.default.parse(argument).name));
129
100
  const stats = (0, app_1.parseStatblock)((_b = option.name) !== null && _b !== void 0 ? _b : null, file, alias);
130
101
  if (option.tsv) {
131
102
  const output = option.output ? option.output : path_1.default.join(path_1.default.parse(argument).dir, stats.alias + '.tsv');
132
- yield promises_1.default.writeFile(output, (0, app_1.formatTSV)(stats, option.secretDC, option.defaultSkills), { encoding: 'utf-8' });
103
+ await promises_1.default.writeFile(output, (0, app_1.formatTSV)(stats, option.secretDC, option.defaultSkills), { encoding: 'utf-8' });
133
104
  }
134
105
  else if (option.command) {
135
106
  const output = option.output ? option.output : path_1.default.join(path_1.default.parse(argument).dir, stats.alias + '-command.txt');
136
- yield promises_1.default.writeFile(output, (0, app_1.formatCommand)(stats, option.secretDC, option.defaultSkills), { encoding: 'utf-8' });
107
+ await promises_1.default.writeFile(output, (0, app_1.formatCommand)(stats, option.secretDC, option.defaultSkills), { encoding: 'utf-8' });
137
108
  }
138
109
  else {
139
110
  const output = option.output ? option.output : path_1.default.join(path_1.default.parse(argument).dir, stats.alias + '.json');
140
- yield promises_1.default.writeFile(output, (0, app_1.formatJSON)(stats), { encoding: 'utf-8' });
111
+ await promises_1.default.writeFile(output, (0, app_1.formatJSON)(stats), { encoding: 'utf-8' });
141
112
  }
142
- }));
113
+ });
143
114
  program.command('tsv')
144
115
  .description('Generte a tsv file from JSON')
145
116
  .argument('<file>', 'input json')
146
117
  .option('-o, --output <file>', 'output tsv')
147
118
  .option('-s, --secretDC', 'produce secret DCs')
148
119
  .option('-d, --defaultSkills', 'produce values for untrained skills')
149
- .action((argument, option) => __awaiter(void 0, void 0, void 0, function* () {
150
- const file = yield promises_1.default.readFile(argument, { encoding: 'utf-8' });
120
+ .action(async (argument, option) => {
121
+ const file = await promises_1.default.readFile(argument, { encoding: 'utf-8' });
151
122
  const stats = (0, app_1.parseJSON)(file);
152
123
  const output = option.output ? option.output : path_1.default.join(path_1.default.parse(argument).dir, path_1.default.parse(argument).name + '.tsv');
153
- yield promises_1.default.writeFile(output, (0, app_1.formatTSV)(stats, option.secretDC, option.defaultSkills), { encoding: 'utf-8' });
154
- }));
124
+ await promises_1.default.writeFile(output, (0, app_1.formatTSV)(stats, option.secretDC, option.defaultSkills), { encoding: 'utf-8' });
125
+ });
155
126
  program.command('command')
156
127
  .description('Generte a creation command file from JSON')
157
128
  .argument('<file>', 'input json')
158
129
  .option('-o, --output <file>', 'output txt')
159
130
  .option('-s, --secretDC', 'produce secret DCs')
160
131
  .option('-d, --defaultSkills', 'produce values for untrained skills')
161
- .action((argument, option) => __awaiter(void 0, void 0, void 0, function* () {
162
- const file = yield promises_1.default.readFile(argument, { encoding: 'utf-8' });
132
+ .action(async (argument, option) => {
133
+ const file = await promises_1.default.readFile(argument, { encoding: 'utf-8' });
163
134
  const stats = (0, app_1.parseJSON)(file);
164
135
  const output = option.output ? option.output : path_1.default.join(path_1.default.parse(argument).dir, path_1.default.parse(argument).name + '-command.txt');
165
- yield promises_1.default.writeFile(output, (0, app_1.formatCommand)(stats, option.secretDC, option.defaultSkills), { encoding: 'utf-8' });
166
- }));
136
+ await promises_1.default.writeFile(output, (0, app_1.formatCommand)(stats, option.secretDC, option.defaultSkills), { encoding: 'utf-8' });
137
+ });
167
138
  program.command('newtracker')
168
139
  .argument('<file>', 'input text file')
169
140
  .option('-o, --output <file>', 'output file name')
170
- .action((argument, option) => __awaiter(void 0, void 0, void 0, function* () {
171
- const file = yield promises_1.default.readFile(argument, { encoding: 'utf-8' });
141
+ .action(async (argument, option) => {
142
+ const file = await promises_1.default.readFile(argument, { encoding: 'utf-8' });
172
143
  const tracker = (0, app_1.newtracker)(file);
173
144
  if (option.output) {
174
- yield promises_1.default.writeFile(option.output, JSON.stringify(tracker, undefined, 2), { encoding: 'utf-8' });
145
+ await promises_1.default.writeFile(option.output, JSON.stringify(tracker, undefined, 2), { encoding: 'utf-8' });
175
146
  }
176
147
  else {
177
148
  console.log(JSON.stringify(tracker, undefined, 2));
178
149
  }
179
- }));
150
+ });
180
151
  program.command('tracker')
181
152
  .argument('<file>', 'input text file')
182
153
  .option('-o, --output <file>', 'output file name')
183
- .action((argument, option) => __awaiter(void 0, void 0, void 0, function* () {
184
- const file = yield promises_1.default.readFile(argument, { encoding: 'utf-8' });
154
+ .action(async (argument, option) => {
155
+ const file = await promises_1.default.readFile(argument, { encoding: 'utf-8' });
185
156
  const tracker = (0, app_1.parseTracker)(file);
186
157
  if (option.output) {
187
- yield promises_1.default.writeFile(option.output, (0, app_1.formatTracker)(tracker), { encoding: 'utf-8' });
158
+ await promises_1.default.writeFile(option.output, (0, app_1.formatTracker)(tracker), { encoding: 'utf-8' });
188
159
  }
189
160
  else {
190
161
  console.log((0, app_1.formatTracker)(tracker));
191
162
  }
192
- }));
163
+ });
193
164
  program.command('track')
194
165
  .argument('<file>', 'input text file')
195
166
  .option('-o, --output <file>', 'output file name')
196
- .action((argument, option) => __awaiter(void 0, void 0, void 0, function* () {
167
+ .action(async (argument, option) => {
197
168
  const iterator = promises_1.default.watch(argument);
198
- const invoke = (filename) => __awaiter(void 0, void 0, void 0, function* () {
199
- const file = yield promises_1.default.readFile(filename, { encoding: 'utf-8' });
169
+ const invoke = async (filename) => {
170
+ const file = await promises_1.default.readFile(filename, { encoding: 'utf-8' });
200
171
  const tracker = (0, app_1.parseTracker)(file);
201
172
  if (option.output) {
202
- yield promises_1.default.writeFile(option.output, (0, app_1.formatTracker)(tracker), { encoding: 'utf-8' });
173
+ await promises_1.default.writeFile(option.output, (0, app_1.formatTracker)(tracker), { encoding: 'utf-8' });
203
174
  }
204
175
  else {
205
176
  console.clear();
@@ -207,37 +178,24 @@ program.command('track')
207
178
  clipboardy_1.default.writeSync(track);
208
179
  console.log(track);
209
180
  }
210
- });
211
- yield invoke(argument);
212
- yield Promise.all([
213
- (() => __awaiter(void 0, void 0, void 0, function* () {
214
- var _a, e_1, _b, _c;
215
- var _d;
216
- try {
217
- for (var _e = true, iterator_1 = __asyncValues(iterator), iterator_1_1; iterator_1_1 = yield iterator_1.next(), _a = iterator_1_1.done, !_a; _e = true) {
218
- _c = iterator_1_1.value;
219
- _e = false;
220
- const value = _c;
221
- yield invoke((_d = value.filename) !== null && _d !== void 0 ? _d : argument);
222
- }
223
- }
224
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
225
- finally {
226
- try {
227
- if (!_e && !_a && (_b = iterator_1.return)) yield _b.call(iterator_1);
228
- }
229
- finally { if (e_1) throw e_1.error; }
181
+ };
182
+ await invoke(argument);
183
+ await Promise.all([
184
+ (async () => {
185
+ var _a;
186
+ for await (const value of iterator) {
187
+ await invoke((_a = value.filename) !== null && _a !== void 0 ? _a : argument);
230
188
  }
231
- }))(),
232
- (() => __awaiter(void 0, void 0, void 0, function* () {
189
+ })(),
190
+ (async () => {
233
191
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
234
192
  const rl = readline_1.default.createInterface({
235
193
  input: process.stdin,
236
194
  output: process.stdout
237
195
  });
238
196
  while (true) {
239
- yield new Promise((resolve) => setTimeout(resolve, 500));
240
- let input = yield new Promise((resolve) => (rl.question('> ', resolve)));
197
+ await new Promise((resolve) => setTimeout(resolve, 500));
198
+ let input = await new Promise((resolve) => (rl.question('> ', resolve)));
241
199
  const commands = [{
242
200
  regex: /^\s*[bB]\s*(\d+)/,
243
201
  map: (match) => ({ command: 'block', index: parseInt(match[1], 10) })
@@ -372,7 +330,7 @@ program.command('track')
372
330
  input = input.slice(match[0].length);
373
331
  actions.push(action);
374
332
  }
375
- const file = yield promises_1.default.readFile(argument, { encoding: 'utf-8' });
333
+ const file = await promises_1.default.readFile(argument, { encoding: 'utf-8' });
376
334
  let tracker = (0, app_1.parseTracker)(file);
377
335
  for (const action of actions) {
378
336
  if (action.command === 'block') {
@@ -441,7 +399,10 @@ program.command('track')
441
399
  }
442
400
  }
443
401
  else if (action.command === 'delete') {
444
- tracker = tracker.filter((c) => !(c.id === action.tag || c.alias === action.tag || c.name == action.tag)).map((p) => (Object.assign(Object.assign({}, p), { children: p.children.filter((c) => !(c.id === action.tag || c.alias === action.tag || c.name == action.tag)) })));
402
+ tracker = tracker.filter((c) => !(c.id === action.tag || c.alias === action.tag || c.name == action.tag)).map((p) => ({
403
+ ...p,
404
+ children: p.children.filter((c) => !(c.id === action.tag || c.alias === action.tag || c.name == action.tag)),
405
+ }));
445
406
  }
446
407
  else if (action.command === 'purge') {
447
408
  tracker = tracker.filter((c) => !c.foe);
@@ -575,9 +536,9 @@ program.command('track')
575
536
  tracker.push(app_1.charSchema.parse({ foe: true, name: action.name, alias: action.alias, maxhp: action.hp, hp: action.hp }));
576
537
  }
577
538
  }
578
- yield promises_1.default.writeFile(argument, JSON.stringify(tracker, undefined, 2), { encoding: 'utf-8' });
539
+ await promises_1.default.writeFile(argument, JSON.stringify(tracker, undefined, 2), { encoding: 'utf-8' });
579
540
  }
580
- }))(),
541
+ })(),
581
542
  ]);
582
- }));
543
+ });
583
544
  program.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pf2e-sage-stats",
3
- "version": "0.2.10",
3
+ "version": "0.3.0",
4
4
  "description": "An RPG Sage's .tsv stat generation tool",
5
5
  "author": "ikariott@gmail.com",
6
6
  "license": "MIT",
@@ -21,12 +21,14 @@
21
21
  "default": "./dist/app.js"
22
22
  }
23
23
  },
24
- "files": ["dist"],
24
+ "files": [
25
+ "dist"
26
+ ],
25
27
  "devDependencies": {
26
28
  "@eslint/js": "^9.17.0",
27
29
  "@types/jest": "^29.5.14",
28
- "@types/jsdom": "^27.0.0",
29
30
  "@types/lodash": "^4.17.13",
31
+ "@types/node": "^26.6.6",
30
32
  "@types/pluralize": "^0.0.33",
31
33
  "@types/tsv": "^0.2.4",
32
34
  "eslint": "^9.17.0",
@@ -42,7 +44,6 @@
42
44
  "clipboardy": "^5.1.0",
43
45
  "commander": "^12.1.0",
44
46
  "dedent-js": "^1.0.1",
45
- "jsdom": "^28.0.0",
46
47
  "lodash": "^4.17.21",
47
48
  "pluralize": "^8.0.0",
48
49
  "tsv": "^0.2.0",