@opndev/html 0.0.1
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/Changes +5 -0
- package/README.md +48 -0
- package/README.md.license +3 -0
- package/lib/index.mjs +15 -0
- package/lib/xhr.mjs +44 -0
- package/package.json +35 -0
package/Changes
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Welcome to @opndev/html
|
|
2
|
+
|
|
3
|
+
This is a utility function package for HTML based actions. It is an ESM package.
|
|
4
|
+
|
|
5
|
+
[If you want to know more, have a look at our documenation](https://opndev.gitlab.io/javascript/opndev-js-util/)
|
|
6
|
+
|
|
7
|
+
## Development
|
|
8
|
+
|
|
9
|
+
Try to keep functions small and try not to depend on any outside functions. We
|
|
10
|
+
aim to keep the dependency graph as small as possible. The use of `esm` is
|
|
11
|
+
welcomed and writing tests is encouraged.
|
|
12
|
+
|
|
13
|
+
### jsdoc
|
|
14
|
+
|
|
15
|
+
You can build the documentation by running `npm run jsdoc`.
|
|
16
|
+
|
|
17
|
+
### eslint
|
|
18
|
+
|
|
19
|
+
The ES Linting profile is flexible and does not try to enforce much. There is
|
|
20
|
+
more than one way to do it ([TIMTOWTDI](https://en.wikipedia.org/wiki/There%27s_more_than_one_way_to_do_it)).
|
|
21
|
+
|
|
22
|
+
Try to stay constistent, but forcing a programming style upon others is bad.
|
|
23
|
+
|
|
24
|
+
### gitignore
|
|
25
|
+
|
|
26
|
+
Please educate yourself and use a global gitignore file. Somes files will
|
|
27
|
+
always be there. I'm looking at you `node_modules`.
|
|
28
|
+
|
|
29
|
+
### The lockfiles
|
|
30
|
+
You'll also see that `package-lock.json` and/or `yarn.lock` are ignored. I
|
|
31
|
+
strongly believe that pinning packages lead to bit rot, as you never update
|
|
32
|
+
packages. When a downstream module breaks its API you should know and update
|
|
33
|
+
your code accordingly. The same goes for possible upstream modules. If you want
|
|
34
|
+
a specific version, pin it to that version, otherwise use the latest and
|
|
35
|
+
greatest when possible.
|
|
36
|
+
|
|
37
|
+
### Code of conduct
|
|
38
|
+
|
|
39
|
+
There is none, stay human, communicate and accept that some people have
|
|
40
|
+
different opinions.
|
|
41
|
+
|
|
42
|
+
### Pull requests
|
|
43
|
+
|
|
44
|
+
I'm happy to accept pull requests, just make sure your change has tests.
|
|
45
|
+
Add a good commit message and commit with a sign-off `git commit -s`.
|
|
46
|
+
|
|
47
|
+
A good commit message isn't just `issue(feat): added foo to bar` but also
|
|
48
|
+
explain the why in the commit.
|
package/lib/index.mjs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2024 Wesley Schwengle
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: MIT
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @module module:@opndev/html
|
|
8
|
+
*
|
|
9
|
+
* @exports xhr
|
|
10
|
+
*
|
|
11
|
+
* Export all the useful functions. Unfortunatly, without webpack's
|
|
12
|
+
* require.context we cannot automaticly load everything. So we just keep
|
|
13
|
+
* typing. ES6 requires strict syntax on import and exports :/
|
|
14
|
+
*/
|
|
15
|
+
export { isInfo, isSuccess, isError, isServerError, isClientError } from './xhr.mjs'
|
package/lib/xhr.mjs
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2024 Wesley Schwengle
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: MIT
|
|
4
|
+
|
|
5
|
+
export {
|
|
6
|
+
isSuccess,
|
|
7
|
+
isError,
|
|
8
|
+
isClientError,
|
|
9
|
+
isServerError,
|
|
10
|
+
isRedirect,
|
|
11
|
+
isInfo
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function isInStatusRange(xhr, code) {
|
|
15
|
+
if (xhr.status >= code && xhr.status < code+100)
|
|
16
|
+
return true;
|
|
17
|
+
return false
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function isInfo(xhr) {
|
|
21
|
+
return isInStatusRange(xhr, 100);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function isSuccess(xhr) {
|
|
25
|
+
return isInStatusRange(xhr, 200);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function isRedirect(xhr) {
|
|
29
|
+
return isInStatusRange(xhr, 300);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function isClientError(xhr) {
|
|
33
|
+
return isInStatusRange(xhr, 400);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function isServerError(xhr) {
|
|
37
|
+
return isInStatusRange(xhr, 500);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function isError(xhr) {
|
|
41
|
+
if (isClientError(xhr) || isServerError(xhr))
|
|
42
|
+
return true;
|
|
43
|
+
return false
|
|
44
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@opndev/html",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "HTML utility functions for OPN Development",
|
|
5
|
+
"main": "lib/index.mjs",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"mode": "auto",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"homepage": "https://opndev.gitlab.io/javascript/opndev-js-html/",
|
|
10
|
+
"repository": {
|
|
11
|
+
"url": "git+https://gitlab.com/opndev/javascript/opndev-js-html.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://gitlab.com/opndev/javascript/opndev-js-html/issues"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"test": "tap",
|
|
18
|
+
"jsdoc" : "jsdoc -c jsdoc.json"
|
|
19
|
+
},
|
|
20
|
+
"author": {
|
|
21
|
+
"name": "Wesley Schwengle",
|
|
22
|
+
"email": "wesley@opndev.io",
|
|
23
|
+
"url": "https://opndev.io"
|
|
24
|
+
},
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"jsdoc" : "latest",
|
|
28
|
+
"tap": "latest"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"lib/*.mjs",
|
|
32
|
+
"README.md",
|
|
33
|
+
"Changes"
|
|
34
|
+
]
|
|
35
|
+
}
|