started with typescript

This commit is contained in:
Ulf Gebhardt 2023-04-09 23:35:37 +02:00
parent 5e228126ce
commit dbfc7fb6f6
Signed by: ulfgebhardt
GPG Key ID: DA6B843E748679C9
4 changed files with 380 additions and 29 deletions

253
package-lock.json generated Normal file
View File

@ -0,0 +1,253 @@
{
"name": "wow-addon-toc",
"version": "0.1.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "wow-addon-toc",
"version": "0.1.0",
"license": "Apache2.0",
"devDependencies": {
"@types/node": "^18.15.11",
"mocha": "^1.21.4",
"should": "^4.0.4",
"typescript": "^5.0.4"
}
},
"node_modules/@types/node": {
"version": "18.15.11",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.15.11.tgz",
"integrity": "sha512-E5Kwq2n4SbMzQOn6wnmBjuK9ouqlURrcZDVfbo9ftDDTFt3nk7ZKK4GMOzoYgnpQJKcxwQw+lGaBvvlMo0qN/Q==",
"dev": true
},
"node_modules/commander": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.3.0.tgz",
"integrity": "sha512-CD452fnk0jQyk3NfnK+KkR/hUPoHt5pVaKHogtyyv3N0U4QfAal9W0/rXLOg/vVZgQKa7jdtXypKs1YAip11uQ==",
"dev": true,
"engines": {
"node": ">= 0.6.x"
}
},
"node_modules/diff": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/diff/-/diff-1.0.8.tgz",
"integrity": "sha512-1zEb73vemXFpUmfh3fsta4YHz3lwebxXvaWmPbFv9apujQBWDnkrPDLXLQs1gZo4RCWMDsT89r0Pf/z8/02TGA==",
"dev": true,
"engines": {
"node": ">=0.3.1"
}
},
"node_modules/escape-string-regexp": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.2.tgz",
"integrity": "sha512-cQpUid7bdTUnFin8S7BnNdOk+/eDqQmKgCANSyd/jAhrKEvxUvr9VQ8XZzXiOtest8NLfk3FSBZzwvemZNQ6Vg==",
"dev": true,
"engines": {
"node": ">=0.8.0"
}
},
"node_modules/glob": {
"version": "3.2.3",
"resolved": "https://registry.npmjs.org/glob/-/glob-3.2.3.tgz",
"integrity": "sha512-WPaLsMHD1lYEqAmIQI6VOJSPwuBdGShDWnj1yUo0vQqEO809R8W3LM9OVU13CnnDhyv/EiNwOtxEW74SmrzS6w==",
"dev": true,
"dependencies": {
"graceful-fs": "~2.0.0",
"inherits": "2",
"minimatch": "~0.2.11"
},
"engines": {
"node": "*"
}
},
"node_modules/graceful-fs": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-2.0.3.tgz",
"integrity": "sha512-hcj/NTUWv+C3MbqrVb9F+aH6lvTwEHJdx2foBxlrVq5h6zE8Bfu4pv4CAAqbDcZrw/9Ak5lsRXlY9Ao8/F0Tuw==",
"deprecated": "please upgrade to graceful-fs 4 for compatibility with current and future versions of Node.js",
"dev": true,
"engines": {
"node": ">=0.4.0"
}
},
"node_modules/growl": {
"version": "1.8.1",
"resolved": "https://registry.npmjs.org/growl/-/growl-1.8.1.tgz",
"integrity": "sha512-Hq61svqhXHBTY80KsuLrItJ9A0YP1PSeiS4hhi77NcPQf+F+yagOSkhuhZdND7NfAcpHm495FKUTmRcygzF0OA==",
"dev": true
},
"node_modules/inherits": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
"dev": true
},
"node_modules/jade": {
"version": "0.26.3",
"resolved": "https://registry.npmjs.org/jade/-/jade-0.26.3.tgz",
"integrity": "sha512-mkk3vzUHFjzKjpCXeu+IjXeZD+QOTjUUdubgmHtHTDwvAO2ZTkMTTVrapts5CWz3JvJryh/4KWZpjeZrCepZ3A==",
"deprecated": "Jade has been renamed to pug, please install the latest version of pug instead of jade",
"dev": true,
"dependencies": {
"commander": "0.6.1",
"mkdirp": "0.3.0"
},
"bin": {
"jade": "bin/jade"
}
},
"node_modules/jade/node_modules/commander": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/commander/-/commander-0.6.1.tgz",
"integrity": "sha512-0fLycpl1UMTGX257hRsu/arL/cUbcvQM4zMKwvLvzXtfdezIV4yotPS2dYtknF+NmEfWSoCEF6+hj9XLm/6hEw==",
"dev": true,
"engines": {
"node": ">= 0.4.x"
}
},
"node_modules/jade/node_modules/mkdirp": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.3.0.tgz",
"integrity": "sha512-OHsdUcVAQ6pOtg5JYWpCBo9W/GySVuwvP9hueRMW7UqshC0tbfzLv8wjySTPm3tfUZ/21CE9E1pJagOA91Pxew==",
"deprecated": "Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)",
"dev": true,
"engines": {
"node": "*"
}
},
"node_modules/lru-cache": {
"version": "2.7.3",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-2.7.3.tgz",
"integrity": "sha512-WpibWJ60c3AgAz8a2iYErDrcT2C7OmKnsWhIcHOjkUHFjkXncJhtLxNSqUmxRxRunpb5I8Vprd7aNSd2NtksJQ==",
"dev": true
},
"node_modules/minimatch": {
"version": "0.2.14",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-0.2.14.tgz",
"integrity": "sha512-zZ+Jy8lVWlvqqeM8iZB7w7KmQkoJn8djM585z88rywrEbzoqawVa9FR5p2hwD+y74nfuKOjmNvi9gtWJNLqHvA==",
"deprecated": "Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue",
"dev": true,
"dependencies": {
"lru-cache": "2",
"sigmund": "~1.0.0"
},
"engines": {
"node": "*"
}
},
"node_modules/minimist": {
"version": "0.0.8",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
"integrity": "sha512-miQKw5Hv4NS1Psg2517mV4e4dYNaO3++hjAvLOAzKqZ61rH8NS1SK+vbfBWZ5PY/Me/bEWhUwqMghEW5Fb9T7Q==",
"dev": true
},
"node_modules/mkdirp": {
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.0.tgz",
"integrity": "sha512-xjjNGy+ry1lhtIKcr2PT6ok3aszhQfgrUDp4OZLHacgRgFmF6XR9XCOJVcXlVGQonIqXcK1DvqgKKQOPWYGSfw==",
"deprecated": "Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)",
"dev": true,
"dependencies": {
"minimist": "0.0.8"
},
"bin": {
"mkdirp": "bin/cmd.js"
}
},
"node_modules/mocha": {
"version": "1.21.5",
"resolved": "https://registry.npmjs.org/mocha/-/mocha-1.21.5.tgz",
"integrity": "sha512-ng2r0YrLCHtmp8W7HyLzSmbdidt3g1I63HhCmOqZH4vzFhmtHcYwcoAmpsJKL142He9NA2HJpmsz9amYDxoZ1Q==",
"deprecated": "Mocha v1.x is no longer supported.",
"dev": true,
"dependencies": {
"commander": "2.3.0",
"debug": "2.0.0",
"diff": "1.0.8",
"escape-string-regexp": "1.0.2",
"glob": "3.2.3",
"growl": "1.8.1",
"jade": "0.26.3",
"mkdirp": "0.5.0"
},
"bin": {
"_mocha": "bin/_mocha",
"mocha": "bin/mocha"
},
"engines": {
"node": ">= 0.4.x"
}
},
"node_modules/mocha/node_modules/debug": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.0.0.tgz",
"integrity": "sha512-jRxFR0Fb657ikmm6IjHY32v/Nqp9Ndcx4LBISXPfpguNaHh5JJnb+x37qalKPTu4fxMFnVBIyEGi72mmvl0BCw==",
"dev": true,
"dependencies": {
"ms": "0.6.2"
}
},
"node_modules/mocha/node_modules/ms": {
"version": "0.6.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-0.6.2.tgz",
"integrity": "sha512-/pc3eh7TWorTtbvXg8je4GvrvEqCfH7PA3P7iW01yL2E53FKixzgMBaQi0NOPbMJqY34cBSvR0tZtmlTkdUG4A==",
"dev": true
},
"node_modules/should": {
"version": "4.6.5",
"resolved": "https://registry.npmjs.org/should/-/should-4.6.5.tgz",
"integrity": "sha512-k6+QDvVxph/xH9mVAEZjFF5iw0G17x59PiiRxdMvWMFuj0+gXlKdDMzODBlbsIyzfLk/2XigJlaI6qj1hFMlHg==",
"dev": true,
"dependencies": {
"should-equal": "0.3.1",
"should-format": "0.0.7",
"should-type": "0.0.4"
}
},
"node_modules/should-equal": {
"version": "0.3.1",
"resolved": "https://registry.npmjs.org/should-equal/-/should-equal-0.3.1.tgz",
"integrity": "sha512-/Q/o9EL9CJlCsy817ZkcQVlyUzyeWUxS9HkXUrqv4tTg+aOXEwvOpR1odT0K9DwcMA0gCy452K71YJA1E6K1mQ==",
"dev": true,
"dependencies": {
"should-type": "0.0.4"
}
},
"node_modules/should-format": {
"version": "0.0.7",
"resolved": "https://registry.npmjs.org/should-format/-/should-format-0.0.7.tgz",
"integrity": "sha512-8oNurKotJEQy+HboLxAHkgKQ+dRfV9TmVAvcY3He1RdnE994M39JTmkCt67cWaygVLKUfBcLRITkpHy2Hsgwcg==",
"dev": true,
"dependencies": {
"should-type": "0.0.4"
}
},
"node_modules/should-type": {
"version": "0.0.4",
"resolved": "https://registry.npmjs.org/should-type/-/should-type-0.0.4.tgz",
"integrity": "sha512-ve9tkv/i29COtupPlu2g4SXGefgSTjDTBI8d5UgSmT52T9T5VBpZY9/Ygn5Pb3dcCaiMyEzBAxBkpUGxEbbMDw==",
"dev": true
},
"node_modules/sigmund": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/sigmund/-/sigmund-1.0.1.tgz",
"integrity": "sha512-fCvEXfh6NWpm+YSuY2bpXb/VIihqWA6hLsgboC+0nl71Q7N7o2eaCW8mJa/NLvQhs6jpd3VZV4UiUQlV6+lc8g==",
"dev": true
},
"node_modules/typescript": {
"version": "5.0.4",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.4.tgz",
"integrity": "sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==",
"dev": true,
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
},
"engines": {
"node": ">=12.20"
}
}
}
}

View File

@ -1,10 +1,11 @@
{
"name": "wow-toc",
"name": "wow-addon-toc",
"version": "0.1.0",
"description": "World Of Warcraft addon toc file parser",
"main": "lib/index.js",
"scripts": {
"test": "node node_modules/mocha/bin/_mocha -R spec"
"test": "node node_modules/mocha/bin/_mocha -R spec",
"build": "tsc"
},
"repository": {
"type": "git",
@ -12,20 +13,20 @@
},
"keywords": [
"wow",
"addon",
"toc",
"parser"
],
"author": "Zeke Sonxx <github.com/zekesonxx>",
"license": "MIT",
"author": "Ulf Gebhardt",
"license": "Apache2.0",
"bugs": {
"url": "https://github.com/zekesonxx/wow-toc/issues"
},
"homepage": "https://github.com/zekesonxx/wow-toc",
"dependencies": {
"debug": "^2.0.0"
},
"devDependencies": {
"@types/node": "^18.15.11",
"mocha": "^1.21.4",
"should": "^4.0.4"
"should": "^4.0.4",
"typescript": "^5.0.4"
}
}

View File

@ -1,19 +1,7 @@
/**
* World Of Warcraft Addon .toc file parser
* Based on the documentation at http://wowpedia.org/TOC_format
* @author Zeke Sonxx <github.com/zekesonxx>
* @license MIT
*/
'use strict';
var debug = require('debug')('wow-toc');
exports.parse = function(input) {
if (typeof input !== 'string') {
throw new Error('wowtoc.parse input must be a string, got '+typeof input);
}
// TODO file handle?
export const parse = function(input: string) {
var lines = input.split(/\r*\n/); //allow Windows newlines
debug('Got input, '+lines.length+' lines');
console.log('Got input, '+lines.length+' lines');
var out = {
tags: {},
files: []
@ -21,21 +9,21 @@ exports.parse = function(input) {
lines.forEach(function(line) {
if (line.length > 1024) {
//WoW only reads the first 1024 lines
debug('Line is longer than 1024 characters, trunicating to be like WoW');
console.log('Line is longer than 1024 characters, trunicating to be like WoW');
line = line.substr(0, 1024);
}
if (line.substr(0, 2) === '##') { //## Title: Recount
debug('Line is tag: '+line);
console.log('Line is tag: '+line);
var tag = line.substr(2, line.indexOf(':')).trim().replace(':', '');
var value = line.substr(line.indexOf(':')+1, line.length).trim();
debug('`'+tag+'` : `'+value+'`');
console.log('`'+tag+'` : `'+value+'`');
out.tags[tag] = value;
} else if (line.substr(0, 1) === '#') { //#bug not feature
debug('Line is comment: '+line);
console.log('Line is comment: '+line);
} else { // recount.lua
//file loading
debug('Line is file: '+line);
console.log('Line is file: '+line);
if (line.trim() !== '') {
out.files.push(line.trim());
}
@ -44,7 +32,7 @@ exports.parse = function(input) {
return out;
};
exports.stringify = function(input) {
export const stringify = function(input) {
if (typeof input !== 'object') {
throw new TypeError('wowtoc.stringify input must be an object, got '+typeof input);
}

109
tsconfig.json Normal file
View File

@ -0,0 +1,109 @@
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig to read more about this file */
/* Projects */
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
/* Language and Environment */
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
// "jsx": "preserve", /* Specify what JSX code is generated. */
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
/* Modules */
"module": "commonjs", /* Specify what module code is generated. */
// "rootDir": "./", /* Specify the root folder within your source files. */
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
// "resolveJsonModule": true, /* Enable importing .json files. */
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
/* JavaScript Support */
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
/* Emit */
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
"outDir": "./build/", /* Specify an output folder for all emitted files. */
// "removeComments": true, /* Disable emitting comments. */
// "noEmit": true, /* Disable emitting files from a compilation. */
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
// "newLine": "crlf", /* Set the newline character for emitting files. */
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
/* Interop Constraints */
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
/* Type Checking */
"strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
/* Completeness */
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
}
}