Initial commit

This commit is contained in:
Florine W. Dekker 2021-11-28 18:25:16 +01:00
commit 1a71de0b92
Signed by untrusted user: FWDekker
GPG Key ID: D3DCFAA8A4560BE0
11 changed files with 466987 additions and 0 deletions

11
.editorconfig Normal file
View File

@ -0,0 +1,11 @@
root = true
[*]
charset = utf-8
trim_trailing_whitespace = true
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4

1
.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
package-lock.json binary

116
.gitignore vendored Normal file
View File

@ -0,0 +1,116 @@
## Node
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.pnp.*

115
Gruntfile.js Normal file
View File

@ -0,0 +1,115 @@
const path = require("path");
module.exports = grunt => {
grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),
clean: {
default: ["dist/"],
},
copy: {
html: {
files: [{expand: true, cwd: "src/main/", src: "**/*.html", dest: "dist/", flatten: true}]
},
txt: {
files: [{expand: true, cwd: "src/main/", src: "**/*.txt", dest: "dist/", flatten: true}]
},
},
focus: {
dev: {
include: ["html", "js"],
},
},
replace: {
dev: {
src: ["./dist/*.html", "./dist/*.js"],
replacements: [
{
from: "%%VERSION_NUMBER%%",
to: "<%= pkg.version %>+" + new Date().toISOString().slice(0, 19).replace(/[-:T]/g, "")
}
],
overwrite: true
},
deploy: {
src: ["./dist/*.html", "./dist/*.js"],
replacements: [
{
from: "%%VERSION_NUMBER%%",
to: "<%= pkg.version %>"
}
],
overwrite: true
},
},
webpack: {
options: {
entry: "./src/main/js/main.js",
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
},
],
},
resolve: {
extensions: [".js"],
},
output: {
filename: "bundle.js",
path: path.resolve(__dirname, "dist/"),
},
},
dev: {
mode: "development",
devtool: "inline-source-map",
},
deploy: {
mode: "production",
},
},
watch: {
html: {
files: ["src/main/**/*.html"],
tasks: ["copy:html"],
},
js: {
files: ["src/main/**/*.js"],
tasks: ["webpack:dev", "replace:dev"],
},
},
});
grunt.loadNpmTasks("grunt-contrib-clean");
grunt.loadNpmTasks("grunt-contrib-copy");
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.loadNpmTasks("grunt-focus");
grunt.loadNpmTasks("grunt-text-replace");
grunt.loadNpmTasks("grunt-webpack");
grunt.registerTask("dev", [
// Pre
"clean",
// Copy files
"copy:html",
"copy:txt",
// Compile
"webpack:dev",
// Post
"replace:dev"
]);
grunt.registerTask("dev:server", ["dev", "focus:dev"]);
grunt.registerTask("deploy", [
// Pre
"clean",
// Copy files
"copy:html",
"copy:txt",
// Compile JS
"webpack:deploy",
// Post
"replace:deploy"
]);
grunt.registerTask("default", ["dev"]);
};

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2021 F.W. Dekker
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

30
README.md Normal file
View File

@ -0,0 +1,30 @@
# Debreviator
Creates meaning by undoing your abbreviation.
## Development
### Requirements
* [npm](https://www.npmjs.com/)
### Setting up
```shell script
# Install dependencies (only needed once)
$> npm ci
```
### Building
```shell script
# Build the tool in `dist/` for development
$> npm run dev
# Same as above, but automatically rerun it whenever files are changed
$> npm run dev:server
# Build the tool in `dist/` for deployment
$> npm run deploy
```
### Publishing
```shell script
# Log in to npm
$> npm login
# Push to npm
$> npm publish --access public
```

BIN
package-lock.json generated Normal file

Binary file not shown.

30
package.json Normal file
View File

@ -0,0 +1,30 @@
{
"name": "debreviator",
"version": "0.0.1",
"description": "Creates meaning by undoing your abbreviation.",
"author": "F.W. Dekker",
"browser": "dist/bundle.js",
"repository": {
"type": "git",
"url": "git@git.fwdekker.com:FWDekker/debreviator.git"
},
"private": true,
"scripts": {
"clean": "grunt clean",
"dev": "grunt dev",
"dev:server": "grunt dev:server",
"deploy": "grunt deploy"
},
"devDependencies": {
"grunt": "^1.4.1",
"grunt-cli": "^1.4.3",
"grunt-contrib-clean": "^2.0.0",
"grunt-contrib-copy": "^1.0.0",
"grunt-contrib-watch": "^1.1.0",
"grunt-focus": "^1.0.0",
"grunt-text-replace": "^0.4.0",
"grunt-webpack": "^5.0.0",
"webpack": "^5.64.4",
"webpack-cli": "^4.9.1"
}
}

54
src/main/index.html Normal file
View File

@ -0,0 +1,54 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="author" content="F.W. Dekker" />
<meta name="application-name" content="Debreviator" />
<meta name="description" content="Creates meaning by undoing your abbreviation." />
<meta name="theme-color" content="#0033cc" />
<title>Debreviator | FWDekker</title>
<link rel="stylesheet" href="https://static.fwdekker.com/fonts/roboto/roboto.css" />
<link rel="stylesheet" href="https://static.fwdekker.com/lib/template/2.x.x/template.css" />
<script async src="https://stats.fwdekker.com/count.js"
data-goatcounter="https://stats.fwdekker.com/count"></script>
</head>
<body>
<noscript>
<img src="https://stats.fwdekker.com/count?p=/tools/debreviator/" alt="Counting pixel" />
<p>
This website does not function if JavaScript is disabled.
Please check the <a href="https://www.enable-javascript.com/">
instructions on how to enable JavaScript in your web browser</a>.
</p>
</noscript>
<main class="hidden">
<div id="nav"></div>
<div id="contents">
<div id="header"></div>
<section class="container">
<div class="row">
<div class="column">
<label for="abbreviation">Abbreviation</label>
<input id="abbreviation" type="text" autofocus />
<button id="debreviate" type="button">Debreviate</button>
<label for="debreviations">Debreviations</label>
<textarea id="debreviations" readonly></textarea>
</div>
</div>
</section>
</div>
<div id="footer"></div>
</main>
<script src="https://static.fwdekker.com/lib/template/2.x.x/template.js"></script>
<!--suppress HtmlUnknownTarget -->
<script src="bundle.js?v=%%VERSION_NUMBER%%"></script>
</body>
</html>

58
src/main/js/main.js Normal file
View File

@ -0,0 +1,58 @@
// noinspection JSUnresolvedVariable
const {$, doAfterLoad, footer, header, nav} = window.fwdekker;
function toUppercaseAt(string, index) {
return string.slice(0, index) + string.charAt(index).toUpperCase() + string.slice(index + 1);
}
doAfterLoad(() => {
$("#nav").appendChild(nav("/Tools/Debreviator/"));
$("#header").appendChild(header({
title: "Debreviator",
description: "Creates meaning by undoing your abbreviation"
}));
$("#footer").appendChild(footer({
vcsURL: "https://git.fwdekker.com/FWDekker/debreviator/",
version: "v%%VERSION_NUMBER%%"
}));
$("main").classList.remove("hidden");
$("[autofocus]").focus();
});
doAfterLoad(() => {
const debreviate = () => {
const abbreviation = $("#abbreviation").value.trim();
if (abbreviation === "") return;
const regex = new RegExp(abbreviation.split("").join(".*"));
fetch("words.txt")
.then(it => it.text())
.then(text => text.split("\n").filter(it => !it.startsWith("#")).map(it => it.toLowerCase()))
.then(words => words.filter(it => regex.test(it)))
.then(matches =>
matches.map(match =>
abbreviation
.split("")
.reduce(
(acc, letter) => {
const letterIndex = acc[0].indexOf(letter, acc[1]);
return [toUppercaseAt(acc[0], letterIndex), letterIndex];
},
[match, 0]
)[0]
)
)
.then(matches => $("#debreviations").value = matches.join("\n"));
};
$("#debreviate").addEventListener("click", debreviate);
$("#abbreviation").addEventListener("keypress", event => {
if (event.key === "Enter") {
debreviate();
event.preventDefault();
}
});
});

466551
src/main/words.txt Normal file

File diff suppressed because it is too large Load Diff