Commit inicial: fuentes MBS ERP (Genero 6) + .gitignore + docs/SETUP_PC_MBS.md
This commit is contained in:
+21
@@ -0,0 +1,21 @@
|
||||
# MIT License
|
||||
|
||||
Copyright (c) 2023 Chris Barth
|
||||
|
||||
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.
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
# is-dom-node
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
## Description
|
||||
|
||||
`@xmldom/is-dom-node` is a versatile TypeScript library designed to provide robust utility functions for working with DOM nodes. Whether you're developing for the browser or dealing with XML in NodeJS, this library offers a comprehensive set of functions for checking and asserting various types of DOM nodes. It's particularly useful when working with NodeJS libraries like [xpath](https://www.npmjs.com/package/xpath) and [@xmldom/xmldom](https://www.npmjs.com/package/@xmldom/xmldom), as it can validate the objects returned by these libraries.
|
||||
|
||||
## Installation
|
||||
|
||||
```shell
|
||||
npm install @xmldom/is-dom-node
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Import the library and use it as follows:
|
||||
|
||||
```javascript
|
||||
import * as isDomNode from "@xmldom/is-dom-node";
|
||||
|
||||
const element = document.createElement("div");
|
||||
const result = isDomNode.isElementNode(element); // Output: true
|
||||
```
|
||||
|
||||
### TypeScript Example
|
||||
|
||||
```typescript
|
||||
import * as isDomNode from "@xmldom/is-dom-node";
|
||||
|
||||
function handleNode(node: Node) {
|
||||
if (isDomNode.isElementNode(node)) {
|
||||
// TypeScript now knows `node` is an Element
|
||||
console.log(node.tagName);
|
||||
} else if (isDomNode.isTextNode(node)) {
|
||||
// TypeScript now knows `node` is a Text node
|
||||
console.log(node.wholeText);
|
||||
} else {
|
||||
try {
|
||||
// Assert that the node is a Comment node
|
||||
isDomNode.assertIsCommentNode(node);
|
||||
// TypeScript now knows `node` is a Comment node
|
||||
console.log(node.nodeValue);
|
||||
} catch (error) {
|
||||
console.error("Node is not a Comment node:", error);
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## API Overview
|
||||
|
||||
The API consists of two main types of functions:
|
||||
|
||||
### `is...` Functions
|
||||
|
||||
These functions return a boolean value indicating whether the given object meets certain criteria:
|
||||
|
||||
- `isNodeLike`: Checks if a given value resembles a DOM node.
|
||||
- `isArrayOfNodes`: Checks if the given value is an array of DOM nodes.
|
||||
- `isElementNode`, `isAttributeNode`, `isTextNode`, etc.: Check for specific types of DOM nodes.
|
||||
|
||||
### `assertIs...` Functions
|
||||
|
||||
These functions assert that a given object meets certain criteria and throw an error if it doesn't:
|
||||
|
||||
- `assertIsNodeLike`: Asserts that a given value is a DOM node.
|
||||
- `assertIsArrayOfNodes`: Asserts that the given value is an array of DOM nodes.
|
||||
- `assertIsElementNode`, `assertIsAttributeNode`, `assertIsTextNode`, etc.: Assert for specific types of DOM nodes.
|
||||
|
||||
### TypeScript Type Narrowing
|
||||
|
||||
Both the `is...` and `assertIs...` functions can be used for TypeScript type narrowing. After a successful check or assertion, TypeScript will recognize the specific type of the DOM node, allowing for more robust and error-free code.
|
||||
|
||||
## Features
|
||||
|
||||
- Lightweight
|
||||
- Written in TypeScript
|
||||
- Comprehensive tests
|
||||
- Compatible with NodeJS XML libraries like `xpath` and `@xmldom/xmldom`
|
||||
|
||||
## Contributing
|
||||
|
||||
Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests.
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details.
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
export declare enum NodeTypes {
|
||||
ELEMENT_NODE = 1,
|
||||
ATTRIBUTE_NODE = 2,
|
||||
TEXT_NODE = 3,
|
||||
CDATA_SECTION_NODE = 4,
|
||||
PROCESSING_INSTRUCTION_NODE = 7,
|
||||
COMMENT_NODE = 8,
|
||||
DOCUMENT_NODE = 9,
|
||||
DOCUMENT_TYPE_NODE = 10,
|
||||
DOCUMENT_FRAGMENT_NODE = 11
|
||||
}
|
||||
export declare function isNodeLike(value: any): value is Node;
|
||||
export declare function assertIsNodeLike(value: unknown): asserts value is Node;
|
||||
export declare function isArrayOfNodes(value: unknown): value is Node[];
|
||||
export declare function assertIsArrayOfNodes(value: unknown): asserts value is Node[];
|
||||
export declare const isElementNode: (value: unknown) => value is Element;
|
||||
export declare const isAttributeNode: (value: unknown) => value is Attr;
|
||||
export declare const isTextNode: (value: unknown) => value is Text;
|
||||
export declare const isCDATASectionNode: (value: unknown) => value is CDATASection;
|
||||
export declare const isProcessingInstructionNode: (value: unknown) => value is ProcessingInstruction;
|
||||
export declare const isCommentNode: (value: unknown) => value is Comment;
|
||||
export declare const isDocumentNode: (value: unknown) => value is Document;
|
||||
export declare const isDocumentTypeNode: (value: unknown) => value is DocumentType;
|
||||
export declare const isDocumentFragmentNode: (value: unknown) => value is DocumentFragment;
|
||||
export declare const assertIsElementNode: (value: unknown) => asserts value is Element;
|
||||
export declare const assertIsAttributeNode: (value: unknown) => asserts value is Attr;
|
||||
export declare const assertIsTextNode: (value: unknown) => asserts value is Text;
|
||||
export declare const assertIsCDATASectionNode: (value: unknown) => asserts value is CDATASection;
|
||||
export declare const assertIsProcessingInstructionNode: (value: unknown) => asserts value is ProcessingInstruction;
|
||||
export declare const assertIsCommentNode: (value: unknown) => asserts value is Comment;
|
||||
export declare const assertIsDocumentNode: (value: unknown) => asserts value is Document;
|
||||
export declare const assertIsDocumentTypeNode: (value: unknown) => asserts value is DocumentType;
|
||||
export declare const assertIsDocumentFragmentNode: (value: unknown) => asserts value is DocumentFragment;
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.assertIsDocumentFragmentNode = exports.assertIsDocumentTypeNode = exports.assertIsDocumentNode = exports.assertIsCommentNode = exports.assertIsProcessingInstructionNode = exports.assertIsCDATASectionNode = exports.assertIsTextNode = exports.assertIsAttributeNode = exports.assertIsElementNode = exports.isDocumentFragmentNode = exports.isDocumentTypeNode = exports.isDocumentNode = exports.isCommentNode = exports.isProcessingInstructionNode = exports.isCDATASectionNode = exports.isTextNode = exports.isAttributeNode = exports.isElementNode = exports.assertIsArrayOfNodes = exports.isArrayOfNodes = exports.assertIsNodeLike = exports.isNodeLike = exports.NodeTypes = void 0;
|
||||
var NodeTypes;
|
||||
(function (NodeTypes) {
|
||||
NodeTypes[NodeTypes["ELEMENT_NODE"] = 1] = "ELEMENT_NODE";
|
||||
NodeTypes[NodeTypes["ATTRIBUTE_NODE"] = 2] = "ATTRIBUTE_NODE";
|
||||
NodeTypes[NodeTypes["TEXT_NODE"] = 3] = "TEXT_NODE";
|
||||
NodeTypes[NodeTypes["CDATA_SECTION_NODE"] = 4] = "CDATA_SECTION_NODE";
|
||||
NodeTypes[NodeTypes["PROCESSING_INSTRUCTION_NODE"] = 7] = "PROCESSING_INSTRUCTION_NODE";
|
||||
NodeTypes[NodeTypes["COMMENT_NODE"] = 8] = "COMMENT_NODE";
|
||||
NodeTypes[NodeTypes["DOCUMENT_NODE"] = 9] = "DOCUMENT_NODE";
|
||||
NodeTypes[NodeTypes["DOCUMENT_TYPE_NODE"] = 10] = "DOCUMENT_TYPE_NODE";
|
||||
NodeTypes[NodeTypes["DOCUMENT_FRAGMENT_NODE"] = 11] = "DOCUMENT_FRAGMENT_NODE";
|
||||
})(NodeTypes || (exports.NodeTypes = NodeTypes = {}));
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function isNodeLike(value) {
|
||||
return (value &&
|
||||
typeof value === "object" &&
|
||||
Number.isInteger(value.nodeType) &&
|
||||
value.nodeType >= 1 &&
|
||||
value.nodeType <= 11 &&
|
||||
typeof value.nodeName === "string" &&
|
||||
typeof value.appendChild === "function" &&
|
||||
typeof value.removeChild === "function");
|
||||
}
|
||||
exports.isNodeLike = isNodeLike;
|
||||
function assertIsNodeLike(value) {
|
||||
if (!isNodeLike(value)) {
|
||||
throw new Error(`Value is not a Node-like object. Received: ${value}`);
|
||||
}
|
||||
}
|
||||
exports.assertIsNodeLike = assertIsNodeLike;
|
||||
function isArrayOfNodes(value) {
|
||||
return Array.isArray(value) && value.every(isNodeLike);
|
||||
}
|
||||
exports.isArrayOfNodes = isArrayOfNodes;
|
||||
function assertIsArrayOfNodes(value) {
|
||||
if (!isArrayOfNodes(value)) {
|
||||
throw new Error("Value is not an array of Nodes");
|
||||
}
|
||||
}
|
||||
exports.assertIsArrayOfNodes = assertIsArrayOfNodes;
|
||||
function isNodeOfType(type, value) {
|
||||
return isNodeLike(value) && value.nodeType === type;
|
||||
}
|
||||
function assertIsNodeOfType(type, value) {
|
||||
const typeName = Object.keys(NodeTypes).find((key) => NodeTypes[key] === type);
|
||||
if (!isNodeOfType(type, value)) {
|
||||
throw new Error(`Value is not of type ${typeName}`);
|
||||
}
|
||||
}
|
||||
const isElementNode = (value) => isNodeOfType(NodeTypes.ELEMENT_NODE, value);
|
||||
exports.isElementNode = isElementNode;
|
||||
const isAttributeNode = (value) => isNodeOfType(NodeTypes.ATTRIBUTE_NODE, value);
|
||||
exports.isAttributeNode = isAttributeNode;
|
||||
const isTextNode = (value) => isNodeOfType(NodeTypes.TEXT_NODE, value);
|
||||
exports.isTextNode = isTextNode;
|
||||
const isCDATASectionNode = (value) => isNodeOfType(NodeTypes.CDATA_SECTION_NODE, value);
|
||||
exports.isCDATASectionNode = isCDATASectionNode;
|
||||
const isProcessingInstructionNode = (value) => isNodeOfType(NodeTypes.PROCESSING_INSTRUCTION_NODE, value);
|
||||
exports.isProcessingInstructionNode = isProcessingInstructionNode;
|
||||
const isCommentNode = (value) => isNodeOfType(NodeTypes.COMMENT_NODE, value);
|
||||
exports.isCommentNode = isCommentNode;
|
||||
const isDocumentNode = (value) => isNodeOfType(NodeTypes.DOCUMENT_NODE, value);
|
||||
exports.isDocumentNode = isDocumentNode;
|
||||
const isDocumentTypeNode = (value) => isNodeOfType(NodeTypes.DOCUMENT_TYPE_NODE, value);
|
||||
exports.isDocumentTypeNode = isDocumentTypeNode;
|
||||
const isDocumentFragmentNode = (value) => isNodeOfType(NodeTypes.DOCUMENT_FRAGMENT_NODE, value);
|
||||
exports.isDocumentFragmentNode = isDocumentFragmentNode;
|
||||
const assertIsElementNode = (value) => {
|
||||
assertIsNodeOfType(NodeTypes.ELEMENT_NODE, value);
|
||||
};
|
||||
exports.assertIsElementNode = assertIsElementNode;
|
||||
const assertIsAttributeNode = (value) => assertIsNodeOfType(NodeTypes.ATTRIBUTE_NODE, value);
|
||||
exports.assertIsAttributeNode = assertIsAttributeNode;
|
||||
const assertIsTextNode = (value) => assertIsNodeOfType(NodeTypes.TEXT_NODE, value);
|
||||
exports.assertIsTextNode = assertIsTextNode;
|
||||
const assertIsCDATASectionNode = (value) => assertIsNodeOfType(NodeTypes.CDATA_SECTION_NODE, value);
|
||||
exports.assertIsCDATASectionNode = assertIsCDATASectionNode;
|
||||
const assertIsProcessingInstructionNode = (value) => assertIsNodeOfType(NodeTypes.PROCESSING_INSTRUCTION_NODE, value);
|
||||
exports.assertIsProcessingInstructionNode = assertIsProcessingInstructionNode;
|
||||
const assertIsCommentNode = (value) => assertIsNodeOfType(NodeTypes.COMMENT_NODE, value);
|
||||
exports.assertIsCommentNode = assertIsCommentNode;
|
||||
const assertIsDocumentNode = (value) => assertIsNodeOfType(NodeTypes.DOCUMENT_NODE, value);
|
||||
exports.assertIsDocumentNode = assertIsDocumentNode;
|
||||
const assertIsDocumentTypeNode = (value) => assertIsNodeOfType(NodeTypes.DOCUMENT_TYPE_NODE, value);
|
||||
exports.assertIsDocumentTypeNode = assertIsDocumentTypeNode;
|
||||
const assertIsDocumentFragmentNode = (value) => assertIsNodeOfType(NodeTypes.DOCUMENT_FRAGMENT_NODE, value);
|
||||
exports.assertIsDocumentFragmentNode = assertIsDocumentFragmentNode;
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
+69
@@ -0,0 +1,69 @@
|
||||
{
|
||||
"name": "@xmldom/is-dom-node",
|
||||
"version": "1.0.1",
|
||||
"description": "TypeScript helper functions to narrow the type of object to a Node descendant",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"changelog": "gren changelog --override --generate --head main",
|
||||
"lint": "eslint \"{src,test}/*.ts\" --cache && npm run prettier-check",
|
||||
"lint:fix": "eslint --fix \"{src,test}/*.ts\" && npm run prettier-format",
|
||||
"prepare": "tsc",
|
||||
"prettier-check": "prettier --config .prettierrc.json --check .",
|
||||
"prettier-format": "prettier --config .prettierrc.json --write .",
|
||||
"prerelease": "git clean -xfd && npm ci && npm run lint && npm test && npm run build",
|
||||
"release": "release-it",
|
||||
"update:major": "npx npm-check-updates -i",
|
||||
"tsc": "tsc",
|
||||
"update:minor": "npx npm-check-updates -i -t minor",
|
||||
"test": "npm run tsc && nyc mocha"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/xmldom/is-dom-node.git"
|
||||
},
|
||||
"keywords": [
|
||||
"dom",
|
||||
"node",
|
||||
"typescript",
|
||||
"narrow",
|
||||
"guard"
|
||||
],
|
||||
"author": "Chris Barth <chrisjbarth@hotmail.com>",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/xmldom/is-dom-node/issues"
|
||||
},
|
||||
"homepage": "https://github.com/xmldom/is-dom-node#readme",
|
||||
"files": [
|
||||
"dist/"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@cjbarth/github-release-notes": "^4.2.0",
|
||||
"@istanbuljs/nyc-config-typescript": "^1.0.2",
|
||||
"@types/jsdom": "^21.1.2",
|
||||
"@types/mocha": "^10.0.2",
|
||||
"@types/node": "^16.18.58",
|
||||
"@typescript-eslint/eslint-plugin": "^6.7.5",
|
||||
"@typescript-eslint/parser": "^6.7.5",
|
||||
"@xmldom/xmldom": "^0.8.10",
|
||||
"choma": "^1.2.1",
|
||||
"eslint": "^8.51.0",
|
||||
"eslint-config-prettier": "^9.0.0",
|
||||
"eslint-plugin-deprecation": "^2.0.0",
|
||||
"jsdom": "^22.1.0",
|
||||
"mocha": "^10.2.0",
|
||||
"nyc": "^15.1.0",
|
||||
"prettier": "^3.0.3",
|
||||
"prettier-plugin-packagejson": "^2.4.6",
|
||||
"release-it": "^16.2.1",
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "^5.2.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 16"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user