Update node modules
This commit is contained in:
parent
9e7ce49a73
commit
dc257a3a4f
|
@ -6,10 +6,10 @@ case `uname` in
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [ -x "$basedir/node" ]; then
|
if [ -x "$basedir/node" ]; then
|
||||||
"$basedir/node" "$basedir/../semver/bin/semver" "$@"
|
"$basedir/node" "$basedir/../semver/bin/semver.js" "$@"
|
||||||
ret=$?
|
ret=$?
|
||||||
else
|
else
|
||||||
node "$basedir/../semver/bin/semver" "$@"
|
node "$basedir/../semver/bin/semver.js" "$@"
|
||||||
ret=$?
|
ret=$?
|
||||||
fi
|
fi
|
||||||
exit $ret
|
exit $ret
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
@IF EXIST "%~dp0\node.exe" (
|
@IF EXIST "%~dp0\node.exe" (
|
||||||
"%~dp0\node.exe" "%~dp0\..\semver\bin\semver" %*
|
"%~dp0\node.exe" "%~dp0\..\semver\bin\semver.js" %*
|
||||||
) ELSE (
|
) ELSE (
|
||||||
@SETLOCAL
|
@SETLOCAL
|
||||||
@SET PATHEXT=%PATHEXT:;.JS;=;%
|
@SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||||
node "%~dp0\..\semver\bin\semver" %*
|
node "%~dp0\..\semver\bin\semver.js" %*
|
||||||
)
|
)
|
|
@ -1,7 +0,0 @@
|
||||||
Copyright 2019 GitHub
|
|
||||||
|
|
||||||
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.
|
|
|
@ -4,48 +4,55 @@
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
#### Inputs/Outputs
|
### Import the package
|
||||||
|
|
||||||
You can use this library to get inputs or set outputs:
|
```js
|
||||||
|
// javascript
|
||||||
```
|
|
||||||
const core = require('@actions/core');
|
const core = require('@actions/core');
|
||||||
|
|
||||||
const myInput = core.getInput('inputName', { required: true });
|
// typescript
|
||||||
|
import * as core from '@actions/core';
|
||||||
|
```
|
||||||
|
|
||||||
// Do stuff
|
#### Inputs/Outputs
|
||||||
|
|
||||||
|
Action inputs can be read with `getInput`. Outputs can be set with `setOutput` which makes them available to be mapped into inputs of other actions to ensure they are decoupled.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const myInput = core.getInput('inputName', { required: true });
|
||||||
|
|
||||||
core.setOutput('outputKey', 'outputVal');
|
core.setOutput('outputKey', 'outputVal');
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Exporting variables/secrets
|
#### Exporting variables
|
||||||
|
|
||||||
You can also export variables and secrets for future steps. Variables get set in the environment automatically, while secrets must be scoped into the environment from a workflow using `{{ secret.FOO }}`. Secrets will also be masked from the logs:
|
Since each step runs in a separate process, you can use `exportVariable` to add it to this step and future steps environment blocks.
|
||||||
|
|
||||||
```
|
|
||||||
const core = require('@actions/core');
|
|
||||||
|
|
||||||
// Do stuff
|
|
||||||
|
|
||||||
|
```js
|
||||||
core.exportVariable('envVar', 'Val');
|
core.exportVariable('envVar', 'Val');
|
||||||
core.exportSecret('secretVar', variableWithSecretValue);
|
```
|
||||||
|
|
||||||
|
#### Setting a secret
|
||||||
|
|
||||||
|
Setting a secret registers the secret with the runner to ensure it is masked in logs.
|
||||||
|
|
||||||
|
```js
|
||||||
|
core.setSecret('myPassword');
|
||||||
```
|
```
|
||||||
|
|
||||||
#### PATH Manipulation
|
#### PATH Manipulation
|
||||||
|
|
||||||
You can explicitly add items to the path for all remaining steps in a workflow:
|
To make a tool's path available in the path for the remainder of the job (without altering the machine or containers state), use `addPath`. The runner will prepend the path given to the jobs PATH.
|
||||||
|
|
||||||
```
|
```js
|
||||||
const core = require('@actions/core');
|
core.addPath('/path/to/mytool');
|
||||||
|
|
||||||
core.addPath('pathToTool');
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Exit codes
|
#### Exit codes
|
||||||
|
|
||||||
You should use this library to set the failing exit code for your action:
|
You should use this library to set the failing exit code for your action. If status is not set and the script runs to completion, that will lead to a success.
|
||||||
|
|
||||||
```
|
```js
|
||||||
const core = require('@actions/core');
|
const core = require('@actions/core');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -56,13 +63,15 @@ catch (err) {
|
||||||
core.setFailed(`Action failed with error ${err}`);
|
core.setFailed(`Action failed with error ${err}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Note that `setNeutral` is not yet implemented in actions V2 but equivalent functionality is being planned.
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Logging
|
#### Logging
|
||||||
|
|
||||||
Finally, this library provides some utilities for logging:
|
Finally, this library provides some utilities for logging. Note that debug logging is hidden from the logs by default. This behavior can be toggled by enabling the [Step Debug Logs](../../docs/action-debugging.md#step-debug-logs).
|
||||||
|
|
||||||
```
|
```js
|
||||||
const core = require('@actions/core');
|
const core = require('@actions/core');
|
||||||
|
|
||||||
const myInput = core.getInput('input');
|
const myInput = core.getInput('input');
|
||||||
|
@ -70,12 +79,62 @@ try {
|
||||||
core.debug('Inside try block');
|
core.debug('Inside try block');
|
||||||
|
|
||||||
if (!myInput) {
|
if (!myInput) {
|
||||||
core.warning('myInput wasnt set');
|
core.warning('myInput was not set');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do stuff
|
// Do stuff
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
core.error('Error ${err}, action may still succeed though');
|
core.error(`Error ${err}, action may still succeed though`);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
This library can also wrap chunks of output in foldable groups.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const core = require('@actions/core')
|
||||||
|
|
||||||
|
// Manually wrap output
|
||||||
|
core.startGroup('Do some function')
|
||||||
|
doSomeFunction()
|
||||||
|
core.endGroup()
|
||||||
|
|
||||||
|
// Wrap an asynchronous function call
|
||||||
|
const result = await core.group('Do something async', async () => {
|
||||||
|
const response = await doSomeHTTPRequest()
|
||||||
|
return response
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Action state
|
||||||
|
|
||||||
|
You can use this library to save state and get state for sharing information between a given wrapper action:
|
||||||
|
|
||||||
|
**action.yml**
|
||||||
|
```yaml
|
||||||
|
name: 'Wrapper action sample'
|
||||||
|
inputs:
|
||||||
|
name:
|
||||||
|
default: 'GitHub'
|
||||||
|
runs:
|
||||||
|
using: 'node12'
|
||||||
|
main: 'main.js'
|
||||||
|
post: 'cleanup.js'
|
||||||
|
```
|
||||||
|
|
||||||
|
In action's `main.js`:
|
||||||
|
|
||||||
|
```js
|
||||||
|
const core = require('@actions/core');
|
||||||
|
|
||||||
|
core.saveState("pidToKill", 12345);
|
||||||
|
```
|
||||||
|
|
||||||
|
In action's `cleanup.js`:
|
||||||
|
```js
|
||||||
|
const core = require('@actions/core');
|
||||||
|
|
||||||
|
var pid = core.getState("pidToKill");
|
||||||
|
|
||||||
|
process.kill(pid);
|
||||||
|
```
|
|
@ -9,8 +9,8 @@ interface CommandProperties {
|
||||||
*
|
*
|
||||||
* Examples:
|
* Examples:
|
||||||
* ##[warning]This is the user warning message
|
* ##[warning]This is the user warning message
|
||||||
* ##[set-secret name=mypassword]definatelyNotAPassword!
|
* ##[set-secret name=mypassword]definitelyNotAPassword!
|
||||||
*/
|
*/
|
||||||
export declare function issueCommand(command: string, properties: CommandProperties, message: string): void;
|
export declare function issueCommand(command: string, properties: CommandProperties, message: string): void;
|
||||||
export declare function issue(name: string, message: string): void;
|
export declare function issue(name: string, message?: string): void;
|
||||||
export {};
|
export {};
|
||||||
|
|
|
@ -9,18 +9,18 @@ const os = require("os");
|
||||||
*
|
*
|
||||||
* Examples:
|
* Examples:
|
||||||
* ##[warning]This is the user warning message
|
* ##[warning]This is the user warning message
|
||||||
* ##[set-secret name=mypassword]definatelyNotAPassword!
|
* ##[set-secret name=mypassword]definitelyNotAPassword!
|
||||||
*/
|
*/
|
||||||
function issueCommand(command, properties, message) {
|
function issueCommand(command, properties, message) {
|
||||||
const cmd = new Command(command, properties, message);
|
const cmd = new Command(command, properties, message);
|
||||||
process.stdout.write(cmd.toString() + os.EOL);
|
process.stdout.write(cmd.toString() + os.EOL);
|
||||||
}
|
}
|
||||||
exports.issueCommand = issueCommand;
|
exports.issueCommand = issueCommand;
|
||||||
function issue(name, message) {
|
function issue(name, message = '') {
|
||||||
issueCommand(name, {}, message);
|
issueCommand(name, {}, message);
|
||||||
}
|
}
|
||||||
exports.issue = issue;
|
exports.issue = issue;
|
||||||
const CMD_PREFIX = '##[';
|
const CMD_STRING = '::';
|
||||||
class Command {
|
class Command {
|
||||||
constructor(command, properties, message) {
|
constructor(command, properties, message) {
|
||||||
if (!command) {
|
if (!command) {
|
||||||
|
@ -31,7 +31,7 @@ class Command {
|
||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
toString() {
|
toString() {
|
||||||
let cmdStr = CMD_PREFIX + this.command;
|
let cmdStr = CMD_STRING + this.command;
|
||||||
if (this.properties && Object.keys(this.properties).length > 0) {
|
if (this.properties && Object.keys(this.properties).length > 0) {
|
||||||
cmdStr += ' ';
|
cmdStr += ' ';
|
||||||
for (const key in this.properties) {
|
for (const key in this.properties) {
|
||||||
|
@ -40,12 +40,12 @@ class Command {
|
||||||
if (val) {
|
if (val) {
|
||||||
// safely append the val - avoid blowing up when attempting to
|
// safely append the val - avoid blowing up when attempting to
|
||||||
// call .replace() if message is not a string for some reason
|
// call .replace() if message is not a string for some reason
|
||||||
cmdStr += `${key}=${escape(`${val || ''}`)};`;
|
cmdStr += `${key}=${escape(`${val || ''}`)},`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cmdStr += ']';
|
cmdStr += CMD_STRING;
|
||||||
// safely append the message - avoid blowing up when attempting to
|
// safely append the message - avoid blowing up when attempting to
|
||||||
// call .replace() if message is not a string for some reason
|
// call .replace() if message is not a string for some reason
|
||||||
const message = `${this.message || ''}`;
|
const message = `${this.message || ''}`;
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{"version":3,"file":"command.js","sourceRoot":"","sources":["../src/command.ts"],"names":[],"mappings":";;AAAA,yBAAwB;AAQxB;;;;;;;;;GASG;AACH,SAAgB,YAAY,CAC1B,OAAe,EACf,UAA6B,EAC7B,OAAe;IAEf,MAAM,GAAG,GAAG,IAAI,OAAO,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,CAAC,CAAA;IACrD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAA;AAC/C,CAAC;AAPD,oCAOC;AAED,SAAgB,KAAK,CAAC,IAAY,EAAE,OAAe;IACjD,YAAY,CAAC,IAAI,EAAE,EAAE,EAAE,OAAO,CAAC,CAAA;AACjC,CAAC;AAFD,sBAEC;AAED,MAAM,UAAU,GAAG,KAAK,CAAA;AAExB,MAAM,OAAO;IAKX,YAAY,OAAe,EAAE,UAA6B,EAAE,OAAe;QACzE,IAAI,CAAC,OAAO,EAAE;YACZ,OAAO,GAAG,iBAAiB,CAAA;SAC5B;QAED,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;Q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AAC,UAAU,CAAC,GAAG,CAAC,CAAA;oBAChC,IAAI,GAAG,EAAE;wBACP,8DAA8D;wBAC9D,6DAA6D;wBAC7D,MAAM,IAAI,GAAG,GAAG,IAAI,MAAM,CAAC,GAAG,GAAG,IAAI,EAAE,EAAE,CAAC,GAAG,CAAA;qBAC9C;iBACF;aACF;SACF;QAED,MAAM,IAAI,UAAU,CAAA;QAEpB,kEAAkE;QAClE,6DAA6D;QAC7D,MAAM,OAAO,GAAG,GAAG,IAAI,CAAC,OAAO,IAAI,EAAE,EAAE,CAAA;QACvC,MAAM,IAAI,UAAU,CAAC,OAAO,CAAC,CAAA;QAE7B,OAAO,MAAM,CAAA;IACf,CAAC;CACF;AAED,SAAS,UAAU,CAAC,CAAS;IAC3B,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;AACtD,CAAC;AAED,SAAS,MAAM,CAAC,CAAS;IACvB,OAAO,CAAC;SACL,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;SACrB,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC;SACpB,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;AACzB,CAAC"}
|
|
@ -19,17 +19,16 @@ export declare enum ExitCode {
|
||||||
Failure = 1
|
Failure = 1
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* sets env variable for this action and future actions in the job
|
* Sets env variable for this action and future actions in the job
|
||||||
* @param name the name of the variable to set
|
* @param name the name of the variable to set
|
||||||
* @param val the value of the variable
|
* @param val the value of the variable
|
||||||
*/
|
*/
|
||||||
export declare function exportVariable(name: string, val: string): void;
|
export declare function exportVariable(name: string, val: string): void;
|
||||||
/**
|
/**
|
||||||
* exports the variable and registers a secret which will get masked from logs
|
* Registers a secret which will get masked from logs
|
||||||
* @param name the name of the variable to set
|
* @param secret value of the secret
|
||||||
* @param val value of the secret
|
|
||||||
*/
|
*/
|
||||||
export declare function exportSecret(name: string, val: string): void;
|
export declare function setSecret(secret: string): void;
|
||||||
/**
|
/**
|
||||||
* Prepends inputPath to the PATH (for this action and future actions)
|
* Prepends inputPath to the PATH (for this action and future actions)
|
||||||
* @param inputPath
|
* @param inputPath
|
||||||
|
@ -71,3 +70,43 @@ export declare function error(message: string): void;
|
||||||
* @param message warning issue message
|
* @param message warning issue message
|
||||||
*/
|
*/
|
||||||
export declare function warning(message: string): void;
|
export declare function warning(message: string): void;
|
||||||
|
/**
|
||||||
|
* Writes info to log with console.log.
|
||||||
|
* @param message info message
|
||||||
|
*/
|
||||||
|
export declare function info(message: string): void;
|
||||||
|
/**
|
||||||
|
* Begin an output group.
|
||||||
|
*
|
||||||
|
* Output until the next `groupEnd` will be foldable in this group
|
||||||
|
*
|
||||||
|
* @param name The name of the output group
|
||||||
|
*/
|
||||||
|
export declare function startGroup(name: string): void;
|
||||||
|
/**
|
||||||
|
* End an output group.
|
||||||
|
*/
|
||||||
|
export declare function endGroup(): void;
|
||||||
|
/**
|
||||||
|
* Wrap an asynchronous function call in a group.
|
||||||
|
*
|
||||||
|
* Returns the same type as the function itself.
|
||||||
|
*
|
||||||
|
* @param name The name of the group
|
||||||
|
* @param fn The function to wrap in the group
|
||||||
|
*/
|
||||||
|
export declare function group<T>(name: string, fn: () => Promise<T>): Promise<T>;
|
||||||
|
/**
|
||||||
|
* Saves state for current action, the state can only be retrieved by this action's post job execution.
|
||||||
|
*
|
||||||
|
* @param name name of the state to store
|
||||||
|
* @param value value to store
|
||||||
|
*/
|
||||||
|
export declare function saveState(name: string, value: string): void;
|
||||||
|
/**
|
||||||
|
* Gets the value of an state set by this action's main execution.
|
||||||
|
*
|
||||||
|
* @param name name of the state to get
|
||||||
|
* @returns string
|
||||||
|
*/
|
||||||
|
export declare function getState(name: string): string;
|
||||||
|
|
|
@ -1,6 +1,16 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
|
});
|
||||||
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const command_1 = require("./command");
|
const command_1 = require("./command");
|
||||||
|
const os = require("os");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
/**
|
/**
|
||||||
* The code to exit an action
|
* The code to exit an action
|
||||||
|
@ -20,7 +30,7 @@ var ExitCode;
|
||||||
// Variables
|
// Variables
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* sets env variable for this action and future actions in the job
|
* Sets env variable for this action and future actions in the job
|
||||||
* @param name the name of the variable to set
|
* @param name the name of the variable to set
|
||||||
* @param val the value of the variable
|
* @param val the value of the variable
|
||||||
*/
|
*/
|
||||||
|
@ -30,15 +40,13 @@ function exportVariable(name, val) {
|
||||||
}
|
}
|
||||||
exports.exportVariable = exportVariable;
|
exports.exportVariable = exportVariable;
|
||||||
/**
|
/**
|
||||||
* exports the variable and registers a secret which will get masked from logs
|
* Registers a secret which will get masked from logs
|
||||||
* @param name the name of the variable to set
|
* @param secret value of the secret
|
||||||
* @param val value of the secret
|
|
||||||
*/
|
*/
|
||||||
function exportSecret(name, val) {
|
function setSecret(secret) {
|
||||||
exportVariable(name, val);
|
command_1.issueCommand('add-mask', {}, secret);
|
||||||
command_1.issueCommand('set-secret', {}, val);
|
|
||||||
}
|
}
|
||||||
exports.exportSecret = exportSecret;
|
exports.setSecret = setSecret;
|
||||||
/**
|
/**
|
||||||
* Prepends inputPath to the PATH (for this action and future actions)
|
* Prepends inputPath to the PATH (for this action and future actions)
|
||||||
* @param inputPath
|
* @param inputPath
|
||||||
|
@ -56,7 +64,7 @@ exports.addPath = addPath;
|
||||||
* @returns string
|
* @returns string
|
||||||
*/
|
*/
|
||||||
function getInput(name, options) {
|
function getInput(name, options) {
|
||||||
const val = process.env[`INPUT_${name.replace(' ', '_').toUpperCase()}`] || '';
|
const val = process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`] || '';
|
||||||
if (options && options.required && !val) {
|
if (options && options.required && !val) {
|
||||||
throw new Error(`Input required and not supplied: ${name}`);
|
throw new Error(`Input required and not supplied: ${name}`);
|
||||||
}
|
}
|
||||||
|
@ -113,4 +121,75 @@ function warning(message) {
|
||||||
command_1.issue('warning', message);
|
command_1.issue('warning', message);
|
||||||
}
|
}
|
||||||
exports.warning = warning;
|
exports.warning = warning;
|
||||||
|
/**
|
||||||
|
* Writes info to log with console.log.
|
||||||
|
* @param message info message
|
||||||
|
*/
|
||||||
|
function info(message) {
|
||||||
|
process.stdout.write(message + os.EOL);
|
||||||
|
}
|
||||||
|
exports.info = info;
|
||||||
|
/**
|
||||||
|
* Begin an output group.
|
||||||
|
*
|
||||||
|
* Output until the next `groupEnd` will be foldable in this group
|
||||||
|
*
|
||||||
|
* @param name The name of the output group
|
||||||
|
*/
|
||||||
|
function startGroup(name) {
|
||||||
|
command_1.issue('group', name);
|
||||||
|
}
|
||||||
|
exports.startGroup = startGroup;
|
||||||
|
/**
|
||||||
|
* End an output group.
|
||||||
|
*/
|
||||||
|
function endGroup() {
|
||||||
|
command_1.issue('endgroup');
|
||||||
|
}
|
||||||
|
exports.endGroup = endGroup;
|
||||||
|
/**
|
||||||
|
* Wrap an asynchronous function call in a group.
|
||||||
|
*
|
||||||
|
* Returns the same type as the function itself.
|
||||||
|
*
|
||||||
|
* @param name The name of the group
|
||||||
|
* @param fn The function to wrap in the group
|
||||||
|
*/
|
||||||
|
function group(name, fn) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
startGroup(name);
|
||||||
|
let result;
|
||||||
|
try {
|
||||||
|
result = yield fn();
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
endGroup();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.group = group;
|
||||||
|
//-----------------------------------------------------------------------
|
||||||
|
// Wrapper action state
|
||||||
|
//-----------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* Saves state for current action, the state can only be retrieved by this action's post job execution.
|
||||||
|
*
|
||||||
|
* @param name name of the state to store
|
||||||
|
* @param value value to store
|
||||||
|
*/
|
||||||
|
function saveState(name, value) {
|
||||||
|
command_1.issueCommand('save-state', { name }, value);
|
||||||
|
}
|
||||||
|
exports.saveState = saveState;
|
||||||
|
/**
|
||||||
|
* Gets the value of an state set by this action's main execution.
|
||||||
|
*
|
||||||
|
* @param name name of the state to get
|
||||||
|
* @returns string
|
||||||
|
*/
|
||||||
|
function getState(name) {
|
||||||
|
return process.env[`STATE_${name}`] || '';
|
||||||
|
}
|
||||||
|
exports.getState = getState;
|
||||||
//# sourceMappingURL=core.js.map
|
//# sourceMappingURL=core.js.map
|
|
@ -1 +1 @@
|
||||||
{"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":";;AAAA,uCAA6C;AAE7C,6BAA4B;AAU5B;;GAEG;AACH,IAAY,QAUX;AAVD,WAAY,QAAQ;IAClB;;OAEG;IACH,6CAAW,CAAA;IAEX;;OAEG;IACH,6CAAW,CAAA;AACb,CAAC,EAVW,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAUnB;AAED,yEAAyE;AACzE,YAAY;AACZ,yEAAyE;AAEzE;;;;GAIG;AACH,SAAgB,cAAc,CAAC,IAAY,EAAE,GAAW;IACtD,OAAO,CAAC,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+1,35 @@
|
||||||
{
|
{
|
||||||
"_args": [
|
"_from": "@actions/core@1.2.0",
|
||||||
[
|
"_id": "@actions/core@1.2.0",
|
||||||
"@actions/core@1.0.0",
|
|
||||||
"C:\\dev\\repos\\actions\\setup-dotnet"
|
|
||||||
]
|
|
||||||
],
|
|
||||||
"_from": "@actions/core@1.0.0",
|
|
||||||
"_id": "@actions/core@1.0.0",
|
|
||||||
"_inBundle": false,
|
"_inBundle": false,
|
||||||
"_integrity": "sha512-aMIlkx96XH4E/2YZtEOeyrYQfhlas9jIRkfGPqMwXD095Rdkzo4lB6ZmbxPQSzD+e1M+Xsm98ZhuSMYGv/AlqA==",
|
"_integrity": "sha512-ZKdyhlSlyz38S6YFfPnyNgCDZuAF2T0Qv5eHflNWytPS8Qjvz39bZFMry9Bb/dpSnqWcNeav5yM2CTYpJeY+Dw==",
|
||||||
"_location": "/@actions/core",
|
"_location": "/@actions/core",
|
||||||
"_phantomChildren": {},
|
"_phantomChildren": {},
|
||||||
"_requested": {
|
"_requested": {
|
||||||
"type": "version",
|
"type": "version",
|
||||||
"registry": true,
|
"registry": true,
|
||||||
"raw": "@actions/core@1.0.0",
|
"raw": "@actions/core@1.2.0",
|
||||||
"name": "@actions/core",
|
"name": "@actions/core",
|
||||||
"escapedName": "@actions%2fcore",
|
"escapedName": "@actions%2fcore",
|
||||||
"scope": "@actions",
|
"scope": "@actions",
|
||||||
"rawSpec": "1.0.0",
|
"rawSpec": "1.2.0",
|
||||||
"saveSpec": null,
|
"saveSpec": null,
|
||||||
"fetchSpec": "1.0.0"
|
"fetchSpec": "1.2.0"
|
||||||
},
|
},
|
||||||
"_requiredBy": [
|
"_requiredBy": [
|
||||||
|
"#USER",
|
||||||
"/",
|
"/",
|
||||||
"/@actions/tool-cache"
|
"/@actions/tool-cache"
|
||||||
],
|
],
|
||||||
"_resolved": "https://registry.npmjs.org/@actions/core/-/core-1.0.0.tgz",
|
"_resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.0.tgz",
|
||||||
"_spec": "1.0.0",
|
"_shasum": "aa5f52b26c362c821d41557e599371a42f6c0b3d",
|
||||||
"_where": "C:\\dev\\repos\\actions\\setup-dotnet",
|
"_spec": "@actions/core@1.2.0",
|
||||||
|
"_where": "C:\\Users\\Stanley\\Projects\\GitHub\\setup-dotnet",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/actions/toolkit/issues"
|
"url": "https://github.com/actions/toolkit/issues"
|
||||||
},
|
},
|
||||||
|
"bundleDependencies": false,
|
||||||
|
"deprecated": false,
|
||||||
"description": "Actions core lib",
|
"description": "Actions core lib",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^12.0.2"
|
"@types/node": "^12.0.2"
|
||||||
|
@ -43,11 +41,11 @@
|
||||||
"files": [
|
"files": [
|
||||||
"lib"
|
"lib"
|
||||||
],
|
],
|
||||||
"gitHead": "a40bce7c8d382aa3dbadaa327acbc696e9390e55",
|
|
||||||
"homepage": "https://github.com/actions/toolkit/tree/master/packages/core",
|
"homepage": "https://github.com/actions/toolkit/tree/master/packages/core",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"core",
|
"github",
|
||||||
"actions"
|
"actions",
|
||||||
|
"core"
|
||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "lib/core.js",
|
"main": "lib/core.js",
|
||||||
|
@ -57,11 +55,12 @@
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/actions/toolkit.git"
|
"url": "git+https://github.com/actions/toolkit.git",
|
||||||
|
"directory": "packages/core"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1",
|
"test": "echo \"Error: run tests from root\" && exit 1",
|
||||||
"tsc": "tsc"
|
"tsc": "tsc"
|
||||||
},
|
},
|
||||||
"version": "1.0.0"
|
"version": "1.2.0"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
Copyright 2019 GitHub
|
|
||||||
|
|
||||||
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.
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
You can use this package to execute your tools on the command line in a cross platform way:
|
You can use this package to execute your tools on the command line in a cross platform way:
|
||||||
|
|
||||||
```
|
```js
|
||||||
const exec = require('@actions/exec');
|
const exec = require('@actions/exec');
|
||||||
|
|
||||||
await exec.exec('node index.js');
|
await exec.exec('node index.js');
|
||||||
|
@ -16,7 +16,7 @@ await exec.exec('node index.js');
|
||||||
|
|
||||||
You can also pass in arg arrays:
|
You can also pass in arg arrays:
|
||||||
|
|
||||||
```
|
```js
|
||||||
const exec = require('@actions/exec');
|
const exec = require('@actions/exec');
|
||||||
|
|
||||||
await exec.exec('node', ['index.js', 'foo=bar']);
|
await exec.exec('node', ['index.js', 'foo=bar']);
|
||||||
|
@ -26,11 +26,11 @@ await exec.exec('node', ['index.js', 'foo=bar']);
|
||||||
|
|
||||||
Capture output or specify [other options](https://github.com/actions/toolkit/blob/d9347d4ab99fd507c0b9104b2cf79fb44fcc827d/packages/exec/src/interfaces.ts#L5):
|
Capture output or specify [other options](https://github.com/actions/toolkit/blob/d9347d4ab99fd507c0b9104b2cf79fb44fcc827d/packages/exec/src/interfaces.ts#L5):
|
||||||
|
|
||||||
```
|
```js
|
||||||
const exec = require('@actions/exec');
|
const exec = require('@actions/exec');
|
||||||
|
|
||||||
const myOutput = '';
|
let myOutput = '';
|
||||||
const myError = '';
|
let myError = '';
|
||||||
|
|
||||||
const options = {};
|
const options = {};
|
||||||
options.listeners = {
|
options.listeners = {
|
||||||
|
@ -48,13 +48,10 @@ await exec.exec('node', ['index.js', 'foo=bar'], options);
|
||||||
|
|
||||||
#### Exec tools not in the PATH
|
#### Exec tools not in the PATH
|
||||||
|
|
||||||
You can use it in conjunction with the `which` function from `@actions/io` to execute tools that are not in the PATH:
|
You can specify the full path for tools not in the PATH:
|
||||||
|
|
||||||
```
|
```js
|
||||||
const exec = require('@actions/exec');
|
const exec = require('@actions/exec');
|
||||||
const io = require('@actions/io');
|
|
||||||
|
|
||||||
const pythonPath: string = await io.which('python', true)
|
await exec.exec('"/path/to/my-tool"', ['arg1']);
|
||||||
|
|
||||||
await exec.exec(`"${pythonPath}"`, ['main.py']);
|
|
||||||
```
|
```
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
return new (P || (P = Promise))(function (resolve, reject) {
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{"version":3,"file":"exec.js","sourceRoot":"","sources":["../src/exec.ts"],"names":[],"mappings":";;;;;;;;;;AACA,mCAAkC;AAElC;;;;;;;;;GASG;AACH,SAAsB,IAAI,CACxB,WAAmB,EACnB,IAAe,EACf,OAAwB;;QAExB,MAAM,WAAW,GAAG,EAAE,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAA;QACpD,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE;YAC5B,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAA;SACpE;QACD,8CAA8C;QAC9C,MAAM,QAAQ,GAAG,WAAW,CAAC,CAAC,CAAC,CAAA;QAC/B,IAAI,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC,CAAA;QAC9C,MAAM,MAAM,GAAkB,IAAI,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;QACxE,OAAO,MAAM,CAAC,IAAI,EAAE,CAAA;IACtB,CAAC;CAAA;AAdD,oBAcC"}
|
{"version":3,"file":"exec.js","sourceRoot":"","sources":["../src/exec.ts"],"names":[],"mappings":";;;;;;;;;;;AACA,mCAAkC;AAElC;;;;;;;;;GASG;AACH,SAAsB,IAAI,CACxB,WAAmB,EACnB,IAAe,EACf,OAAwB;;QAExB,MAAM,WAAW,GAAG,EAAE,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAA;QACpD,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE;YAC5B,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAA;SACpE;QACD,8CAA8C;QAC9C,MAAM,QAAQ,GAAG,WAAW,CAAC,CAAC,CAAC,CAAA;QAC/B,IAAI,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC,CAAA;QAC9C,MAAM,MAAM,GAAkB,IAAI,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;QACxE,OAAO,MAAM,CAAC,IAAI,EAAE,CAAA;IACtB,CAAC;CAAA;AAdD,oBAcC"}
|
|
@ -1,9 +1,10 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
return new (P || (P = Promise))(function (resolve, reject) {
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -11,6 +12,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const os = require("os");
|
const os = require("os");
|
||||||
const events = require("events");
|
const events = require("events");
|
||||||
const child = require("child_process");
|
const child = require("child_process");
|
||||||
|
const path = require("path");
|
||||||
|
const io = require("@actions/io");
|
||||||
|
const ioUtil = require("@actions/io/lib/io-util");
|
||||||
/* eslint-disable @typescript-eslint/unbound-method */
|
/* eslint-disable @typescript-eslint/unbound-method */
|
||||||
const IS_WINDOWS = process.platform === 'win32';
|
const IS_WINDOWS = process.platform === 'win32';
|
||||||
/*
|
/*
|
||||||
|
@ -188,7 +192,7 @@ class ToolRunner extends events.EventEmitter {
|
||||||
// command line from libuv quoting rules would look like:
|
// command line from libuv quoting rules would look like:
|
||||||
// foo.exe "myarg:\"my val\""
|
// foo.exe "myarg:\"my val\""
|
||||||
//
|
//
|
||||||
// 3) double-up slashes that preceed a quote,
|
// 3) double-up slashes that precede a quote,
|
||||||
// e.g. hello \world => "hello \world"
|
// e.g. hello \world => "hello \world"
|
||||||
// hello\"world => "hello\\""world"
|
// hello\"world => "hello\\""world"
|
||||||
// hello\\"world => "hello\\\\""world"
|
// hello\\"world => "hello\\\\""world"
|
||||||
|
@ -356,6 +360,16 @@ class ToolRunner extends events.EventEmitter {
|
||||||
*/
|
*/
|
||||||
exec() {
|
exec() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
// root the tool path if it is unrooted and contains relative pathing
|
||||||
|
if (!ioUtil.isRooted(this.toolPath) &&
|
||||||
|
(this.toolPath.includes('/') ||
|
||||||
|
(IS_WINDOWS && this.toolPath.includes('\\')))) {
|
||||||
|
// prefer options.cwd if it is specified, however options.cwd may also need to be rooted
|
||||||
|
this.toolPath = path.resolve(process.cwd(), this.options.cwd || process.cwd(), this.toolPath);
|
||||||
|
}
|
||||||
|
// if the tool is only a file name, then resolve it from the PATH
|
||||||
|
// otherwise verify it exists (add extension on Windows if necessary)
|
||||||
|
this.toolPath = yield io.which(this.toolPath, true);
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this._debug(`exec tool: ${this.toolPath}`);
|
this._debug(`exec tool: ${this.toolPath}`);
|
||||||
this._debug('arguments:');
|
this._debug('arguments:');
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,41 +1,39 @@
|
||||||
{
|
{
|
||||||
"_args": [
|
"_from": "@actions/exec@1.0.2",
|
||||||
[
|
"_id": "@actions/exec@1.0.2",
|
||||||
"@actions/exec@1.0.0",
|
|
||||||
"C:\\dev\\repos\\actions\\setup-dotnet"
|
|
||||||
]
|
|
||||||
],
|
|
||||||
"_from": "@actions/exec@1.0.0",
|
|
||||||
"_id": "@actions/exec@1.0.0",
|
|
||||||
"_inBundle": false,
|
"_inBundle": false,
|
||||||
"_integrity": "sha512-nquH0+XKng+Ll7rZfCojN7NWSbnGh+ltwUJhzfbLkmOJgxocGX2/yXcZLMyT9fa7+tByEow/NSTrBExNlEj9fw==",
|
"_integrity": "sha512-Yo/wfcFuxbVjAaAfvx3aGLhMEuonOahas2jf8BwyA52IkXTAmLi7YVZTpGAQG/lTxuGoNLg9slTWQD4rr7rMDQ==",
|
||||||
"_location": "/@actions/exec",
|
"_location": "/@actions/exec",
|
||||||
"_phantomChildren": {},
|
"_phantomChildren": {},
|
||||||
"_requested": {
|
"_requested": {
|
||||||
"type": "version",
|
"type": "version",
|
||||||
"registry": true,
|
"registry": true,
|
||||||
"raw": "@actions/exec@1.0.0",
|
"raw": "@actions/exec@1.0.2",
|
||||||
"name": "@actions/exec",
|
"name": "@actions/exec",
|
||||||
"escapedName": "@actions%2fexec",
|
"escapedName": "@actions%2fexec",
|
||||||
"scope": "@actions",
|
"scope": "@actions",
|
||||||
"rawSpec": "1.0.0",
|
"rawSpec": "1.0.2",
|
||||||
"saveSpec": null,
|
"saveSpec": null,
|
||||||
"fetchSpec": "1.0.0"
|
"fetchSpec": "1.0.2"
|
||||||
},
|
},
|
||||||
"_requiredBy": [
|
"_requiredBy": [
|
||||||
|
"#USER",
|
||||||
"/",
|
"/",
|
||||||
"/@actions/tool-cache"
|
"/@actions/tool-cache"
|
||||||
],
|
],
|
||||||
"_resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.0.0.tgz",
|
"_resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.0.2.tgz",
|
||||||
"_spec": "1.0.0",
|
"_shasum": "80ae9c2ea0bf5d0046a9f73d2a1b15bddfff0311",
|
||||||
"_where": "C:\\dev\\repos\\actions\\setup-dotnet",
|
"_spec": "@actions/exec@1.0.2",
|
||||||
|
"_where": "C:\\Users\\Stanley\\Projects\\GitHub\\setup-dotnet",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/actions/toolkit/issues"
|
"url": "https://github.com/actions/toolkit/issues"
|
||||||
},
|
},
|
||||||
"description": "Actions exec lib",
|
"bundleDependencies": false,
|
||||||
"devDependencies": {
|
"dependencies": {
|
||||||
"@actions/io": "^1.0.0"
|
"@actions/io": "^1.0.1"
|
||||||
},
|
},
|
||||||
|
"deprecated": false,
|
||||||
|
"description": "Actions exec lib",
|
||||||
"directories": {
|
"directories": {
|
||||||
"lib": "lib",
|
"lib": "lib",
|
||||||
"test": "__tests__"
|
"test": "__tests__"
|
||||||
|
@ -43,11 +41,11 @@
|
||||||
"files": [
|
"files": [
|
||||||
"lib"
|
"lib"
|
||||||
],
|
],
|
||||||
"gitHead": "a40bce7c8d382aa3dbadaa327acbc696e9390e55",
|
|
||||||
"homepage": "https://github.com/actions/toolkit/tree/master/packages/exec",
|
"homepage": "https://github.com/actions/toolkit/tree/master/packages/exec",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"exec",
|
"github",
|
||||||
"actions"
|
"actions",
|
||||||
|
"exec"
|
||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "lib/exec.js",
|
"main": "lib/exec.js",
|
||||||
|
@ -57,11 +55,12 @@
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/actions/toolkit.git"
|
"url": "git+https://github.com/actions/toolkit.git",
|
||||||
|
"directory": "packages/exec"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1",
|
"test": "echo \"Error: run tests from root\" && exit 1",
|
||||||
"tsc": "tsc"
|
"tsc": "tsc"
|
||||||
},
|
},
|
||||||
"version": "1.0.0"
|
"version": "1.0.2"
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
Recursively make a directory. Follows rules specified in [man mkdir](https://linux.die.net/man/1/mkdir) with the `-p` option specified:
|
Recursively make a directory. Follows rules specified in [man mkdir](https://linux.die.net/man/1/mkdir) with the `-p` option specified:
|
||||||
|
|
||||||
```
|
```js
|
||||||
const io = require('@actions/io');
|
const io = require('@actions/io');
|
||||||
|
|
||||||
await io.mkdirP('path/to/make');
|
await io.mkdirP('path/to/make');
|
||||||
|
@ -18,7 +18,7 @@ await io.mkdirP('path/to/make');
|
||||||
|
|
||||||
Copy or move files or folders. Follows rules specified in [man cp](https://linux.die.net/man/1/cp) and [man mv](https://linux.die.net/man/1/mv):
|
Copy or move files or folders. Follows rules specified in [man cp](https://linux.die.net/man/1/cp) and [man mv](https://linux.die.net/man/1/mv):
|
||||||
|
|
||||||
```
|
```js
|
||||||
const io = require('@actions/io');
|
const io = require('@actions/io');
|
||||||
|
|
||||||
// Recursive must be true for directories
|
// Recursive must be true for directories
|
||||||
|
@ -32,7 +32,7 @@ await io.mv('path/to/file', 'path/to/dest');
|
||||||
|
|
||||||
Remove a file or folder recursively. Follows rules specified in [man rm](https://linux.die.net/man/1/rm) with the `-r` and `-f` rules specified.
|
Remove a file or folder recursively. Follows rules specified in [man rm](https://linux.die.net/man/1/rm) with the `-r` and `-f` rules specified.
|
||||||
|
|
||||||
```
|
```js
|
||||||
const io = require('@actions/io');
|
const io = require('@actions/io');
|
||||||
|
|
||||||
await io.rmRF('path/to/directory');
|
await io.rmRF('path/to/directory');
|
||||||
|
@ -43,7 +43,7 @@ await io.rmRF('path/to/file');
|
||||||
|
|
||||||
Get the path to a tool and resolves via paths. Follows the rules specified in [man which](https://linux.die.net/man/1/which).
|
Get the path to a tool and resolves via paths. Follows the rules specified in [man which](https://linux.die.net/man/1/which).
|
||||||
|
|
||||||
```
|
```js
|
||||||
const exec = require('@actions/exec');
|
const exec = require('@actions/exec');
|
||||||
const io = require('@actions/io');
|
const io = require('@actions/io');
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
return new (P || (P = Promise))(function (resolve, reject) {
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{"version":3,"file":"io-util.js","sourceRoot":"","sources":["../src/io-util.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,mCAAyB;AACzB,yBAAwB;AACxB,6BAA4B;AAEf,gBAYE,qTAAA;AAEF,QAAA,UAA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AAG,EAAE,CAC7F,CAAA;qBACF;oBAED,OAAO,QAAQ,CAAA;iBAChB;qBAAM;oBACL,IAAI,gBAAgB,CAAC,KAAK,CAAC,EAAE;wBAC3B,OAAO,QAAQ,CAAA;qBAChB;iBACF;aACF;SACF;QAED,OAAO,EAAE,CAAA;IACX,CAAC;CAAA;AA5ED,oDA4EC;AAED,SAAS,mBAAmB,CAAC,CAAS;IACpC,CAAC,GAAG,CAAC,IAAI,EAAE,CAAA;IACX,IAAI,kBAAU,EAAE;QACd,6BAA6B;QAC7B,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;QAE1B,2BAA2B;QAC3B,OAAO,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;KACjC;IAED,2BAA2B;IAC3B,OAAO,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAA;AACjC,CAAC;AAED,qCAAqC;AACrC,6BAA6B;AAC7B,6BAA6B;AAC7B,SAAS,gBAAgB,CAAC,KAAe;IACvC,OAAO,CACL,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC;QACpB,CAAC,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,GAAG,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC;QACxD,CAAC,CAAC,KAAK,CAAC,IAAI,GAAG,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,GAAG,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,CAC1D,CAAA;AACH,CAAC"}
|
|
@ -1,9 +1,10 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
return new (P || (P = Promise))(function (resolve, reject) {
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -204,9 +205,9 @@ function which(tool, check) {
|
||||||
}
|
}
|
||||||
// build the list of directories
|
// build the list of directories
|
||||||
//
|
//
|
||||||
// Note, technically "where" checks the current directory on Windows. From a task lib perspective,
|
// Note, technically "where" checks the current directory on Windows. From a toolkit perspective,
|
||||||
// it feels like we should not do this. Checking the current directory seems like more of a use
|
// it feels like we should not do this. Checking the current directory seems like more of a use
|
||||||
// case of a shell, and the which() function exposed by the task lib should strive for consistency
|
// case of a shell, and the which() function exposed by the toolkit should strive for consistency
|
||||||
// across platforms.
|
// across platforms.
|
||||||
const directories = [];
|
const directories = [];
|
||||||
if (process.env.PATH) {
|
if (process.env.PATH) {
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,37 +1,36 @@
|
||||||
{
|
{
|
||||||
"_args": [
|
"_from": "@actions/io@1.0.1",
|
||||||
[
|
"_id": "@actions/io@1.0.1",
|
||||||
"@actions/io@1.0.0",
|
|
||||||
"C:\\dev\\repos\\actions\\setup-dotnet"
|
|
||||||
]
|
|
||||||
],
|
|
||||||
"_from": "@actions/io@1.0.0",
|
|
||||||
"_id": "@actions/io@1.0.0",
|
|
||||||
"_inBundle": false,
|
"_inBundle": false,
|
||||||
"_integrity": "sha512-ezrJSRdqtXtdx1WXlfYL85+40F7gB39jCK9P0jZVODW3W6xUYmu6ZOEc/UmmElUwhRyDRm1R4yNZu1Joq2kuQg==",
|
"_integrity": "sha512-rhq+tfZukbtaus7xyUtwKfuiCRXd1hWSfmJNEpFgBQJ4woqPEpsBw04awicjwz9tyG2/MVhAEMfVn664Cri5zA==",
|
||||||
"_location": "/@actions/io",
|
"_location": "/@actions/io",
|
||||||
"_phantomChildren": {},
|
"_phantomChildren": {},
|
||||||
"_requested": {
|
"_requested": {
|
||||||
"type": "version",
|
"type": "version",
|
||||||
"registry": true,
|
"registry": true,
|
||||||
"raw": "@actions/io@1.0.0",
|
"raw": "@actions/io@1.0.1",
|
||||||
"name": "@actions/io",
|
"name": "@actions/io",
|
||||||
"escapedName": "@actions%2fio",
|
"escapedName": "@actions%2fio",
|
||||||
"scope": "@actions",
|
"scope": "@actions",
|
||||||
"rawSpec": "1.0.0",
|
"rawSpec": "1.0.1",
|
||||||
"saveSpec": null,
|
"saveSpec": null,
|
||||||
"fetchSpec": "1.0.0"
|
"fetchSpec": "1.0.1"
|
||||||
},
|
},
|
||||||
"_requiredBy": [
|
"_requiredBy": [
|
||||||
|
"#USER",
|
||||||
"/",
|
"/",
|
||||||
|
"/@actions/exec",
|
||||||
"/@actions/tool-cache"
|
"/@actions/tool-cache"
|
||||||
],
|
],
|
||||||
"_resolved": "https://registry.npmjs.org/@actions/io/-/io-1.0.0.tgz",
|
"_resolved": "https://registry.npmjs.org/@actions/io/-/io-1.0.1.tgz",
|
||||||
"_spec": "1.0.0",
|
"_shasum": "81a9418fe2bbdef2d2717a8e9f85188b9c565aca",
|
||||||
"_where": "C:\\dev\\repos\\actions\\setup-dotnet",
|
"_spec": "@actions/io@1.0.1",
|
||||||
|
"_where": "C:\\Users\\Stanley\\Projects\\GitHub\\setup-dotnet",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/actions/toolkit/issues"
|
"url": "https://github.com/actions/toolkit/issues"
|
||||||
},
|
},
|
||||||
|
"bundleDependencies": false,
|
||||||
|
"deprecated": false,
|
||||||
"description": "Actions io lib",
|
"description": "Actions io lib",
|
||||||
"directories": {
|
"directories": {
|
||||||
"lib": "lib",
|
"lib": "lib",
|
||||||
|
@ -40,11 +39,12 @@
|
||||||
"files": [
|
"files": [
|
||||||
"lib"
|
"lib"
|
||||||
],
|
],
|
||||||
"gitHead": "a40bce7c8d382aa3dbadaa327acbc696e9390e55",
|
"gitHead": "a2ab4bcf78e4f7080f0d45856e6eeba16f0bbc52",
|
||||||
"homepage": "https://github.com/actions/toolkit/tree/master/packages/io",
|
"homepage": "https://github.com/actions/toolkit/tree/master/packages/io",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"io",
|
"github",
|
||||||
"actions"
|
"actions",
|
||||||
|
"io"
|
||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "lib/io.js",
|
"main": "lib/io.js",
|
||||||
|
@ -60,5 +60,5 @@
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1",
|
"test": "echo \"Error: run tests from root\" && exit 1",
|
||||||
"tsc": "tsc"
|
"tsc": "tsc"
|
||||||
},
|
},
|
||||||
"version": "1.0.0"
|
"version": "1.0.1"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
Copyright 2019 GitHub
|
|
||||||
|
|
||||||
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.
|
|
|
@ -8,29 +8,29 @@
|
||||||
|
|
||||||
You can use this to download tools (or other files) from a download URL:
|
You can use this to download tools (or other files) from a download URL:
|
||||||
|
|
||||||
```
|
```js
|
||||||
const tc = require('@actions/tool-cache');
|
const tc = require('@actions/tool-cache');
|
||||||
|
|
||||||
const node12Path = await tc.downloadTool('http://nodejs.org/dist/v12.7.0/node-v12.7.0-linux-x64.tar.gz');
|
const node12Path = await tc.downloadTool('https://nodejs.org/dist/v12.7.0/node-v12.7.0-linux-x64.tar.gz');
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Extract
|
#### Extract
|
||||||
|
|
||||||
These can then be extracted in platform specific ways:
|
These can then be extracted in platform specific ways:
|
||||||
|
|
||||||
```
|
```js
|
||||||
const tc = require('@actions/tool-cache');
|
const tc = require('@actions/tool-cache');
|
||||||
|
|
||||||
if (process.platform === 'win32') {
|
if (process.platform === 'win32') {
|
||||||
tc.downloadTool('http://nodejs.org/dist/v12.7.0/node-v12.7.0-win-x64.zip');
|
const node12Path = tc.downloadTool('https://nodejs.org/dist/v12.7.0/node-v12.7.0-win-x64.zip');
|
||||||
const node12ExtractedFolder = await tc.extractZip(node12Path, 'path/to/extract/to');
|
const node12ExtractedFolder = await tc.extractZip(node12Path, 'path/to/extract/to');
|
||||||
|
|
||||||
// Or alternately
|
// Or alternately
|
||||||
tc.downloadTool('http://nodejs.org/dist/v12.7.0/node-v12.7.0-win-x64.7z');
|
const node12Path = tc.downloadTool('https://nodejs.org/dist/v12.7.0/node-v12.7.0-win-x64.7z');
|
||||||
const node12ExtractedFolder = await tc.extract7z(node12Path, 'path/to/extract/to');
|
const node12ExtractedFolder = await tc.extract7z(node12Path, 'path/to/extract/to');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const node12Path = await tc.downloadTool('http://nodejs.org/dist/v12.7.0/node-v12.7.0-linux-x64.tar.gz');
|
const node12Path = await tc.downloadTool('https://nodejs.org/dist/v12.7.0/node-v12.7.0-linux-x64.tar.gz');
|
||||||
const node12ExtractedFolder = await tc.extractTar(node12Path, 'path/to/extract/to');
|
const node12ExtractedFolder = await tc.extractTar(node12Path, 'path/to/extract/to');
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -41,11 +41,11 @@ Finally, you can cache these directories in our tool-cache. This is useful if yo
|
||||||
|
|
||||||
You'll often want to add it to the path as part of this step:
|
You'll often want to add it to the path as part of this step:
|
||||||
|
|
||||||
```
|
```js
|
||||||
const tc = require('@actions/tool-cache');
|
const tc = require('@actions/tool-cache');
|
||||||
const core = require('@actions/core');
|
const core = require('@actions/core');
|
||||||
|
|
||||||
const node12Path = await tc.downloadTool('http://nodejs.org/dist/v12.7.0/node-v12.7.0-linux-x64.tar.gz');
|
const node12Path = await tc.downloadTool('https://nodejs.org/dist/v12.7.0/node-v12.7.0-linux-x64.tar.gz');
|
||||||
const node12ExtractedFolder = await tc.extractTar(node12Path, 'path/to/extract/to');
|
const node12ExtractedFolder = await tc.extractTar(node12Path, 'path/to/extract/to');
|
||||||
|
|
||||||
const cachedPath = await tc.cacheDir(node12ExtractedFolder, 'node', '12.7.0');
|
const cachedPath = await tc.cacheDir(node12ExtractedFolder, 'node', '12.7.0');
|
||||||
|
@ -54,7 +54,7 @@ core.addPath(cachedPath);
|
||||||
|
|
||||||
You can also cache files for reuse.
|
You can also cache files for reuse.
|
||||||
|
|
||||||
```
|
```js
|
||||||
const tc = require('@actions/tool-cache');
|
const tc = require('@actions/tool-cache');
|
||||||
|
|
||||||
tc.cacheFile('path/to/exe', 'destFileName.exe', 'myExeName', '1.1.0');
|
tc.cacheFile('path/to/exe', 'destFileName.exe', 'myExeName', '1.1.0');
|
||||||
|
@ -64,7 +64,7 @@ tc.cacheFile('path/to/exe', 'destFileName.exe', 'myExeName', '1.1.0');
|
||||||
|
|
||||||
Finally, you can find directories and files you've previously cached:
|
Finally, you can find directories and files you've previously cached:
|
||||||
|
|
||||||
```
|
```js
|
||||||
const tc = require('@actions/tool-cache');
|
const tc = require('@actions/tool-cache');
|
||||||
const core = require('@actions/core');
|
const core = require('@actions/core');
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ core.addPath(nodeDirectory);
|
||||||
|
|
||||||
You can even find all cached versions of a tool:
|
You can even find all cached versions of a tool:
|
||||||
|
|
||||||
```
|
```js
|
||||||
const tc = require('@actions/tool-cache');
|
const tc = require('@actions/tool-cache');
|
||||||
|
|
||||||
const allNodeVersions = tc.findAllVersions('node');
|
const allNodeVersions = tc.findAllVersions('node');
|
||||||
|
|
|
@ -30,9 +30,10 @@ export declare function extract7z(file: string, dest?: string, _7zPath?: string)
|
||||||
*
|
*
|
||||||
* @param file path to the tar
|
* @param file path to the tar
|
||||||
* @param dest destination directory. Optional.
|
* @param dest destination directory. Optional.
|
||||||
|
* @param flags flags for the tar. Optional.
|
||||||
* @returns path to the destination directory
|
* @returns path to the destination directory
|
||||||
*/
|
*/
|
||||||
export declare function extractTar(file: string, dest?: string): Promise<string>;
|
export declare function extractTar(file: string, dest?: string, flags?: string): Promise<string>;
|
||||||
/**
|
/**
|
||||||
* Extract a zip
|
* Extract a zip
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
return new (P || (P = Promise))(function (resolve, reject) {
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -185,16 +186,17 @@ exports.extract7z = extract7z;
|
||||||
*
|
*
|
||||||
* @param file path to the tar
|
* @param file path to the tar
|
||||||
* @param dest destination directory. Optional.
|
* @param dest destination directory. Optional.
|
||||||
|
* @param flags flags for the tar. Optional.
|
||||||
* @returns path to the destination directory
|
* @returns path to the destination directory
|
||||||
*/
|
*/
|
||||||
function extractTar(file, dest) {
|
function extractTar(file, dest, flags = 'xz') {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
if (!file) {
|
if (!file) {
|
||||||
throw new Error("parameter 'file' is required");
|
throw new Error("parameter 'file' is required");
|
||||||
}
|
}
|
||||||
dest = dest || (yield _createExtractFolder(dest));
|
dest = dest || (yield _createExtractFolder(dest));
|
||||||
const tarPath = yield io.which('tar', true);
|
const tarPath = yield io.which('tar', true);
|
||||||
yield exec_1.exec(`"${tarPath}"`, ['xzC', dest, '-f', file]);
|
yield exec_1.exec(`"${tarPath}"`, [flags, '-C', dest, '-f', file]);
|
||||||
return dest;
|
return dest;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -245,7 +247,7 @@ function extractZipWin(file, dest) {
|
||||||
}
|
}
|
||||||
function extractZipNix(file, dest) {
|
function extractZipNix(file, dest) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const unzipPath = path.join(__dirname, '..', 'scripts', 'externals', 'unzip');
|
const unzipPath = yield io.which('unzip');
|
||||||
yield exec_1.exec(`"${unzipPath}"`, [file], { cwd: dest });
|
yield exec_1.exec(`"${unzipPath}"`, [file], { cwd: dest });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,44 +1,42 @@
|
||||||
{
|
{
|
||||||
"_args": [
|
"_from": "@actions/tool-cache@1.1.2",
|
||||||
[
|
"_id": "@actions/tool-cache@1.1.2",
|
||||||
"@actions/tool-cache@1.0.0",
|
|
||||||
"C:\\dev\\repos\\actions\\setup-dotnet"
|
|
||||||
]
|
|
||||||
],
|
|
||||||
"_from": "@actions/tool-cache@1.0.0",
|
|
||||||
"_id": "@actions/tool-cache@1.0.0",
|
|
||||||
"_inBundle": false,
|
"_inBundle": false,
|
||||||
"_integrity": "sha512-l3zT0IfDfi5Ik5aMpnXqGHGATxN8xa9ls4ue+X/CBXpPhRMRZS4vcuh5Q9T98WAGbkysRCfhpbksTPHIcKnNwQ==",
|
"_integrity": "sha512-IJczPaZr02ECa3Lgws/TJEVco9tjOujiQSZbO3dHuXXjhd5vrUtfOgGwhmz3/f97L910OraPZ8SknofUk6RvOQ==",
|
||||||
"_location": "/@actions/tool-cache",
|
"_location": "/@actions/tool-cache",
|
||||||
"_phantomChildren": {},
|
"_phantomChildren": {},
|
||||||
"_requested": {
|
"_requested": {
|
||||||
"type": "version",
|
"type": "version",
|
||||||
"registry": true,
|
"registry": true,
|
||||||
"raw": "@actions/tool-cache@1.0.0",
|
"raw": "@actions/tool-cache@1.1.2",
|
||||||
"name": "@actions/tool-cache",
|
"name": "@actions/tool-cache",
|
||||||
"escapedName": "@actions%2ftool-cache",
|
"escapedName": "@actions%2ftool-cache",
|
||||||
"scope": "@actions",
|
"scope": "@actions",
|
||||||
"rawSpec": "1.0.0",
|
"rawSpec": "1.1.2",
|
||||||
"saveSpec": null,
|
"saveSpec": null,
|
||||||
"fetchSpec": "1.0.0"
|
"fetchSpec": "1.1.2"
|
||||||
},
|
},
|
||||||
"_requiredBy": [
|
"_requiredBy": [
|
||||||
|
"#USER",
|
||||||
"/"
|
"/"
|
||||||
],
|
],
|
||||||
"_resolved": "https://registry.npmjs.org/@actions/tool-cache/-/tool-cache-1.0.0.tgz",
|
"_resolved": "https://registry.npmjs.org/@actions/tool-cache/-/tool-cache-1.1.2.tgz",
|
||||||
"_spec": "1.0.0",
|
"_shasum": "304d44cecb9547324731e03ca004a3905e6530d2",
|
||||||
"_where": "C:\\dev\\repos\\actions\\setup-dotnet",
|
"_spec": "@actions/tool-cache@1.1.2",
|
||||||
|
"_where": "C:\\Users\\Stanley\\Projects\\GitHub\\setup-dotnet",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/actions/toolkit/issues"
|
"url": "https://github.com/actions/toolkit/issues"
|
||||||
},
|
},
|
||||||
|
"bundleDependencies": false,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.0.0",
|
"@actions/core": "^1.1.0",
|
||||||
"@actions/exec": "^1.0.0",
|
"@actions/exec": "^1.0.1",
|
||||||
"@actions/io": "^1.0.0",
|
"@actions/io": "^1.0.1",
|
||||||
"semver": "^6.1.0",
|
"semver": "^6.1.0",
|
||||||
"typed-rest-client": "^1.4.0",
|
"typed-rest-client": "^1.4.0",
|
||||||
"uuid": "^3.3.2"
|
"uuid": "^3.3.2"
|
||||||
},
|
},
|
||||||
|
"deprecated": false,
|
||||||
"description": "Actions tool-cache lib",
|
"description": "Actions tool-cache lib",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/nock": "^10.0.3",
|
"@types/nock": "^10.0.3",
|
||||||
|
@ -54,11 +52,11 @@
|
||||||
"lib",
|
"lib",
|
||||||
"scripts"
|
"scripts"
|
||||||
],
|
],
|
||||||
"gitHead": "a40bce7c8d382aa3dbadaa327acbc696e9390e55",
|
|
||||||
"homepage": "https://github.com/actions/toolkit/tree/master/packages/exec",
|
"homepage": "https://github.com/actions/toolkit/tree/master/packages/exec",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"exec",
|
"github",
|
||||||
"actions"
|
"actions",
|
||||||
|
"exec"
|
||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "lib/tool-cache.js",
|
"main": "lib/tool-cache.js",
|
||||||
|
@ -74,5 +72,5 @@
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1",
|
"test": "echo \"Error: run tests from root\" && exit 1",
|
||||||
"tsc": "tsc"
|
"tsc": "tsc"
|
||||||
},
|
},
|
||||||
"version": "1.0.0"
|
"version": "1.1.2"
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
|
@ -1 +0,0 @@
|
||||||
|
|
|
@ -1,274 +0,0 @@
|
||||||
3.12.20 / 2019-08-16
|
|
||||||
* Revert: Fix #167: '>' in attribute value as it is causing high performance degrade.
|
|
||||||
3.12.19 / 2019-07-28
|
|
||||||
* Fix js to xml parser should work for date values. (broken: `tagValueProcessor` will receive the original value instead of string always) (breaking change)
|
|
||||||
3.12.18 / 2019-07-27
|
|
||||||
* remove configstore dependency
|
|
||||||
3.12.17 / 2019-07-14
|
|
||||||
* Fix #167: '>' in attribute value
|
|
||||||
3.12.16 / 2019-03-23
|
|
||||||
* Support a new option "stopNodes". (#150)
|
|
||||||
|
|
||||||
Accept the list of tags which are not required to be parsed. Instead, all the nested tag and data will be assigned as string.
|
|
||||||
* Don't show post-install message
|
|
||||||
3.12.12 / 2019-01-11
|
|
||||||
* fix : IE parseInt, parseFloat error
|
|
||||||
3.12.11 / 2018-12-24
|
|
||||||
* fix #132: "/" should not be parsed as boolean attr in case of self closing tags
|
|
||||||
3.12.9 / 2018-11-23
|
|
||||||
* fix #129 : validator should not fail when an atrribute name is 'length'
|
|
||||||
3.12.8 / 2018-11-22
|
|
||||||
* fix #128 : use 'attrValueProcessor' to process attribute value in json2xml parser
|
|
||||||
3.12.6 / 2018-11-10
|
|
||||||
* Fix #126: check for type
|
|
||||||
3.12.4 / 2018-09-12
|
|
||||||
* Fix: include tasks in npm package
|
|
||||||
3.12.3 / 2018-09-12
|
|
||||||
* Fix CLI issue raised in last PR
|
|
||||||
3.12.2 / 2018-09-11
|
|
||||||
* Fix formatting for JSON to XML output
|
|
||||||
* Migrate to webpack (PR merged)
|
|
||||||
* fix cli (PR merged)
|
|
||||||
3.12.0 / 2018-08-06
|
|
||||||
* Support hexadecimal values
|
|
||||||
* Support true number parsing
|
|
||||||
3.11.2 / 2018-07-23
|
|
||||||
* Update Demo for more options
|
|
||||||
* Update license information
|
|
||||||
* Update readme for formatting, users, and spelling mistakes
|
|
||||||
* Add missing typescript definition for j2xParser
|
|
||||||
* refactoring: change filenames
|
|
||||||
3.11.1 / 2018-06-05
|
|
||||||
* fix #93: read the text after self closing tag
|
|
||||||
3.11.0 / 2018-05-20
|
|
||||||
* return defaultOptions if there are not options in buildOptions function
|
|
||||||
* added localeRange declaration in parser.d.ts
|
|
||||||
* Added support of cyrillic characters in validator XML
|
|
||||||
* fixed bug in validator work when XML data with byte order marker
|
|
||||||
3.10.0 / 2018-05-13
|
|
||||||
* Added support of cyrillic characters in parsing XML to JSON
|
|
||||||
3.9.11 / 2018-05-09
|
|
||||||
* fix https://github.com/NaturalIntelligence/fast-xml-parser/issues/80 fix nimn chars
|
|
||||||
* update package information
|
|
||||||
* fix https://github.com/NaturalIntelligence/fast-xml-parser/issues/86: json 2 xml parser : property with null value should be parsed to self closing tag.
|
|
||||||
* update online demo
|
|
||||||
* revert zombiejs to old version to support old version of node
|
|
||||||
* update dependencies
|
|
||||||
3.3.10 / 2018-04-23
|
|
||||||
* fix #77 : parse even if closing tag has space before '>'
|
|
||||||
* include all css & js lib in demo app
|
|
||||||
* remove babel dependencies until needed
|
|
||||||
3.3.9 / 2018-04-18
|
|
||||||
* fix #74 : TS2314 TypeScript compiler error
|
|
||||||
3.3.8 / 2018-04-17
|
|
||||||
* fix #73 : IE doesn't support Object.assign
|
|
||||||
3.3.7 / 2018-04-14
|
|
||||||
* fix: use let insted of const in for loop of validator
|
|
||||||
* Merge pull request
|
|
||||||
https://github.com/NaturalIntelligence/fast-xml-parser/issues/71 from bb/master
|
|
||||||
first draft of typings for typescript
|
|
||||||
https://github.com/NaturalIntelligence/fast-xml-parser/issues/69
|
|
||||||
* Merge pull request
|
|
||||||
https://github.com/NaturalIntelligence/fast-xml-parser/issues/70 from bb/patch-1
|
|
||||||
fix some typos in readme
|
|
||||||
3.3.6 / 2018-03-21
|
|
||||||
* change arrow functions to full notation for IE compatibility
|
|
||||||
3.3.5 / 2018-03-15
|
|
||||||
* fix https://github.com/NaturalIntelligence/fast-xml-parser/issues/67 : attrNodeName invalid behavior
|
|
||||||
* fix: remove decodeHTML char condition
|
|
||||||
3.3.4 / 2018-03-14
|
|
||||||
* remove dependency on "he" package
|
|
||||||
* refactor code to separate methods in separate files.
|
|
||||||
* draft code for transforming XML to json string. It is not officially documented due to performance issue.
|
|
||||||
3.3.0 / 2018-03-05
|
|
||||||
* use common default options for XML parsing for consistency. And add `parseToNimn` method.
|
|
||||||
* update nexttodo
|
|
||||||
* update README about XML to Nimn transformation and remove special notes about 3.x release
|
|
||||||
* update CONTRIBUTING.ms mentioning nexttodo
|
|
||||||
* add negative case for XML PIs
|
|
||||||
* validate xml processing instruction tags https://github.com/NaturalIntelligence/fast-xml-parser/issues/62
|
|
||||||
* nimndata: handle array with object
|
|
||||||
* nimndata: node with nested node and text node
|
|
||||||
* nimndata: handle attributes and text node
|
|
||||||
* nimndata: add options, handle array
|
|
||||||
* add xml to nimn data converter
|
|
||||||
* x2j: direct access property with tagname
|
|
||||||
* update changelog
|
|
||||||
* fix validator when single quote presents in value enclosed with double quotes or vice versa
|
|
||||||
* Revert "remove unneded nimnjs dependency, move opencollective to devDependencies and replace it
|
|
||||||
with more light opencollective-postinstall"
|
|
||||||
This reverts commit d47aa7181075d82db4fee97fd8ea32b056fe3f46.
|
|
||||||
* Merge pull request: https://github.com/NaturalIntelligence/fast-xml-parser/issues/63 from HaroldPutman/suppress-undefined
|
|
||||||
Keep undefined nodes out of the XML output : This is useful when you are deleting nodes from the JSON and rewriting XML.
|
|
||||||
3.2.4 / 2018-03-01
|
|
||||||
* fix #59 fix in validator when open quote presents in attribute value
|
|
||||||
* Create nexttodo.md
|
|
||||||
* exclude static from bitHound tests
|
|
||||||
* add package lock
|
|
||||||
3.2.3 / 2018-02-28
|
|
||||||
* Merge pull request from Delagen/master: fix namespaces can contain the same characters as xml names
|
|
||||||
3.2.2 / 2018-02-22
|
|
||||||
* fix: attribute xmlns should not be removed if ignoreNameSpace is false
|
|
||||||
* create CONTRIBUTING.md
|
|
||||||
3.2.1 / 2018-02-17
|
|
||||||
* fix: empty attribute should be parsed
|
|
||||||
3.2.0 / 2018-02-16
|
|
||||||
* Merge pull request : Dev to Master
|
|
||||||
* Update README and version
|
|
||||||
* j2x:add performance test
|
|
||||||
* j2x: Remove extra empty line before closing tag
|
|
||||||
* j2x: suppress empty nodes to self closing node if configured
|
|
||||||
* j2x: provide option to give indentation depth
|
|
||||||
* j2x: make optional formatting
|
|
||||||
* j2x: encodeHTMLchat
|
|
||||||
* j2x: handle cdata tag
|
|
||||||
* j2x: handle grouped attributes
|
|
||||||
* convert json to xml
|
|
||||||
- nested object
|
|
||||||
- array
|
|
||||||
- attributes
|
|
||||||
- text value
|
|
||||||
* small refactoring
|
|
||||||
* Merge pull request: Update cli.js to let user validate XML file or data
|
|
||||||
* Add option for rendering CDATA as separate property
|
|
||||||
3.0.1 / 2018-02-09
|
|
||||||
* fix CRLF: replace it with single space in attributes value only.
|
|
||||||
3.0.0 / 2018-02-08
|
|
||||||
* change online tool with new changes
|
|
||||||
* update info about new options
|
|
||||||
* separate tag value processing to separate function
|
|
||||||
* make HTML decoding optional
|
|
||||||
* give an option to allow boolean attributes
|
|
||||||
* change cli options as per v3
|
|
||||||
* Correct comparison table format on README
|
|
||||||
* update v3 information
|
|
||||||
* some performance improvement changes
|
|
||||||
* Make regex object local to the method and move some common methods to util
|
|
||||||
* Change parser to
|
|
||||||
- handle multiple instances of CDATA
|
|
||||||
- make triming of value optionals
|
|
||||||
- HTML decode attribute and text value
|
|
||||||
- refactor code to separate files
|
|
||||||
* Ignore newline chars without RE (in validator)
|
|
||||||
* validate for XML prolog
|
|
||||||
* Validate DOCTYPE without RE
|
|
||||||
* Update validator to return error response
|
|
||||||
* Update README to add detail about V3
|
|
||||||
* Separate xmlNode model class
|
|
||||||
* include vscode debug config
|
|
||||||
* fix for repeated object
|
|
||||||
* fix attribute regex for boolean attributes
|
|
||||||
* Fix validator for invalid attributes
|
|
||||||
2.9.4 / 2018-02-02
|
|
||||||
* Merge pull request: Decode HTML characters
|
|
||||||
* refactor source folder name
|
|
||||||
* ignore bundle / browser js to be published to npm
|
|
||||||
2.9.3 / 2018-01-26
|
|
||||||
* Merge pull request: Correctly remove CRLF line breaks
|
|
||||||
* Enable to parse attribute in online editor
|
|
||||||
* Fix testing demo app test
|
|
||||||
* Describe parsing options
|
|
||||||
* Add options for online demo
|
|
||||||
2.9.2 / 2018-01-18
|
|
||||||
* Remove check if tag starting with "XML"
|
|
||||||
* Fix: when there are spaces before / after CDATA
|
|
||||||
|
|
||||||
2.9.1 / 2018-01-16
|
|
||||||
* Fix: newline should be replaced with single space
|
|
||||||
* Fix: for single and multiline comments
|
|
||||||
* validate xml with CDATA
|
|
||||||
* Fix: the issue when there is no space between 2 attributes
|
|
||||||
* Fix: https://github.com/NaturalIntelligence/fast-xml-parser/issues/33: when there is newline char in attr val, it doesn't parse
|
|
||||||
* Merge pull request: fix ignoreNamespace
|
|
||||||
* fix: don't wrap attributes if only namespace attrs
|
|
||||||
* fix: use portfinder for run tests, update deps
|
|
||||||
* fix: don't treat namespaces as attributes when ignoreNamespace enabled
|
|
||||||
|
|
||||||
2.9.0 / 2018-01-10
|
|
||||||
* Rewrite the validator to handle large files.
|
|
||||||
Ignore DOCTYPE validation.
|
|
||||||
* Fix: When attribute value has equal sign
|
|
||||||
|
|
||||||
2.8.3 / 2017-12-15
|
|
||||||
* Fix: when a tag has value along with subtags
|
|
||||||
|
|
||||||
2.8.2 / 2017-12-04
|
|
||||||
* Fix value parsing for IE
|
|
||||||
|
|
||||||
2.8.1 / 2017-12-01
|
|
||||||
* fix: validator should return false instead of err when invalid XML
|
|
||||||
|
|
||||||
2.8.0 / 2017-11-29
|
|
||||||
* Add CLI option to ignore value conversion
|
|
||||||
* Fix variable name when filename is given on CLI
|
|
||||||
* Update CLI help text
|
|
||||||
* Merge pull request: xml2js: Accept standard input
|
|
||||||
* Test Node 8
|
|
||||||
* Update dependencies
|
|
||||||
* Bundle readToEnd
|
|
||||||
* Add ability to read from standard input
|
|
||||||
|
|
||||||
2.7.4 / 2017-09-22
|
|
||||||
* Merge pull request: Allow wrap attributes with subobject to compatible with other parsers output
|
|
||||||
|
|
||||||
2.7.3 / 2017-08-02
|
|
||||||
* fix: handle CDATA with regx
|
|
||||||
|
|
||||||
2.7.2 / 2017-07-30
|
|
||||||
* Change travis config for yarn caching
|
|
||||||
* fix validator: when tag property is same as array property
|
|
||||||
* Merge pull request: Failing test case in validator for valid SVG
|
|
||||||
|
|
||||||
2.7.1 / 2017-07-26
|
|
||||||
* Fix: Handle val 0
|
|
||||||
|
|
||||||
2.7.0 / 2017-07-25
|
|
||||||
* Fix test for arrayMode
|
|
||||||
* Merge pull request: Add arrayMode option to parse any nodes as arrays
|
|
||||||
|
|
||||||
2.6.0 / 2017-07-14
|
|
||||||
* code improvement
|
|
||||||
* Add unit tests for value conversion for attr
|
|
||||||
* Merge pull request: option of an attribute value conversion to a number (textAttrConversion) the same way as the textNodeConversion option does. Default value is false.
|
|
||||||
|
|
||||||
2.5.1 / 2017-07-01
|
|
||||||
* Fix XML element name pattern
|
|
||||||
* Fix XML element name pattern while parsing
|
|
||||||
* Fix validation for xml tag element
|
|
||||||
|
|
||||||
2.5.0 / 2017-06-25
|
|
||||||
* Improve Validator performance
|
|
||||||
* update attr matching regex
|
|
||||||
* Add perf tests
|
|
||||||
* Improve atrr regex to handle all cases
|
|
||||||
|
|
||||||
2.4.4 / 2017-06-08
|
|
||||||
* Bug fix: when an attribute has single or double quote in value
|
|
||||||
|
|
||||||
2.4.3 / 2017-06-05
|
|
||||||
* Bug fix: when multiple CDATA tags are given
|
|
||||||
* Merge pull request: add option "textNodeConversion"
|
|
||||||
* add option "textNodeConversion"
|
|
||||||
|
|
||||||
2.4.1 / 2017-04-14
|
|
||||||
* fix tests
|
|
||||||
* Bug fix: preserve initial space of node value
|
|
||||||
* Handle CDATA
|
|
||||||
|
|
||||||
2.3.1 / 2017-03-15
|
|
||||||
* Bug fix: when single self closing tag
|
|
||||||
* Merge pull request: fix .codeclimate.yml
|
|
||||||
* Update .codeclimate.yml - Fixed config so it does not error anymore.
|
|
||||||
* Update .codeclimate.yml
|
|
||||||
|
|
||||||
2.3.0 / 2017-02-26
|
|
||||||
* Code improvement
|
|
||||||
* add bithound config
|
|
||||||
* Update usage
|
|
||||||
* Update travis to generate bundle js before running tests
|
|
||||||
* 1.Browserify, 2. add more tests for validator
|
|
||||||
* Add validator
|
|
||||||
* Fix CLI default parameter bug
|
|
||||||
|
|
||||||
2.2.1 / 2017-02-05
|
|
||||||
* Bug fix: CLI default option
|
|
|
@ -1,46 +0,0 @@
|
||||||
# Thanks
|
|
||||||
I would like to thank you for your valuable time and effort and applogies if this PR is rejected due to any reason.
|
|
||||||
|
|
||||||
This repository is written with the aim of providing high performance not in terms of speed only but comfortability of the user as well.
|
|
||||||
|
|
||||||
If your change is not a bug fix please check **nexttodo.md** before implementing any new feature.
|
|
||||||
|
|
||||||
## No rights are resserved
|
|
||||||
|
|
||||||
Your contribution is valuable. We try to mention your name on README with the avatar. We can't promise to pay you for your contribution.
|
|
||||||
|
|
||||||
### DoD
|
|
||||||
Here is the check list to publish any change
|
|
||||||
|
|
||||||
* Changes are not half implemented due to the library limitation or any other reason.
|
|
||||||
* Changes are well discussed by raising github issue. So they are well known by other contributers and users
|
|
||||||
* Echoing the above point. The purpose / goal for the PR should be mentioned in the description.
|
|
||||||
* Multiple unrelated changes should not be clubbed in single PR.
|
|
||||||
* Please run perf tests `node benchmark\perfTest3.js` before and after the changes. And mention it in PR description.
|
|
||||||
* If you are adding any dependency (specially if it is not the dev dependency) please check that
|
|
||||||
* it is not dependent on other language packages like c/c++
|
|
||||||
* the package is not very old, very new, discontinued, or has any vulnerability etc.
|
|
||||||
* please check the performance and size of package
|
|
||||||
* please check alternate available options
|
|
||||||
* Please write tests for the new changes
|
|
||||||
* Don't forget to write tests for negative cases
|
|
||||||
* Don't comment existing test case.
|
|
||||||
|
|
||||||
Changes need to do be done by owner
|
|
||||||
* Increase the version number
|
|
||||||
* Update the change log & README if required
|
|
||||||
* Generate the browser bundle
|
|
||||||
* Release in github and publish to npm
|
|
||||||
|
|
||||||
Note that publishing changes or accepting any PR may take time. So please keep patience.
|
|
||||||
|
|
||||||
### Guidelines for first time contributors
|
|
||||||
|
|
||||||
* https://github.com/Roshanjossey/first-contributions
|
|
||||||
* **Don't stretch**. If you complete an issue in long time, there is a possibility that other developers finish their part and you face code conflicts which may increase code complexity for you. So it is always good to complete an issue ASAP.
|
|
||||||
* Please refrain to work on multiple issues marked with "first-timers-only" in the same repo. Ask and help your friends and colleagues to attempt rest issues.
|
|
||||||
* Please claim the issue and clear your doubts before raising PR. So other users will not start working on the same issue.
|
|
||||||
* Mention the issue number either in PR detail or in commit message.
|
|
||||||
* Keep increasing the level of challenge.
|
|
||||||
* Don't hesitate to question on github issue or on twitter.
|
|
||||||
|
|
|
@ -25,32 +25,42 @@ List of some applications/projects using Fast XML Parser. (Raise an issue to sub
|
||||||
<a href="https://www.atomist.com/" title="Atomist" > <img src="https://avatars3.githubusercontent.com/u/19392" width="80px" ></a>
|
<a href="https://www.atomist.com/" title="Atomist" > <img src="https://avatars3.githubusercontent.com/u/19392" width="80px" ></a>
|
||||||
<a href="http://www.opuscapita.com/" title="OpusCapita" > <img src="https://avatars1.githubusercontent.com/u/23256480" width="80px" ></a>
|
<a href="http://www.opuscapita.com/" title="OpusCapita" > <img src="https://avatars1.githubusercontent.com/u/23256480" width="80px" ></a>
|
||||||
<a href="https://nevatrip.ru/" title="nevatrip" > <img src="https://avatars2.githubusercontent.com/u/35730984" width="80px" ></a>
|
<a href="https://nevatrip.ru/" title="nevatrip" > <img src="https://avatars2.githubusercontent.com/u/35730984" width="80px" ></a>
|
||||||
|
<a href="http://www.smartbear.com" title="SmartBear Software" > <img src="https://avatars2.githubusercontent.com/u/1644671" width="80px" ></a>
|
||||||
<a href="http://eosnavigator.com/" title="nevatrip" > <img src="https://avatars1.githubusercontent.com/u/40260563" width="80px" ></a>
|
<a href="http://eosnavigator.com/" title="nevatrip" > <img src="https://avatars1.githubusercontent.com/u/40260563" width="80px" ></a>
|
||||||
<a href="http://pds.nasa.gov/" title="NASA-PDS" > <img src="https://avatars2.githubusercontent.com/u/26313833" width="80px" ></a>
|
<a href="http://nasa.github.io/" title="NASA" > <img src="https://avatars0.githubusercontent.com/u/848102" width="80px" ></a>
|
||||||
<a href="http://qgis.org/" title="QGIS" > <img src="https://avatars2.githubusercontent.com/u/483444" width="80px" ></a>
|
<a href="http://qgis.org/" title="QGIS" > <img src="https://avatars2.githubusercontent.com/u/483444" width="80px" ></a>
|
||||||
<a href="http://www.craft.ai/" title="craft ai" > <img src="https://avatars1.githubusercontent.com/u/12046764" width="80px" ></a>
|
<a href="http://www.craft.ai/" title="craft ai" > <img src="https://avatars1.githubusercontent.com/u/12046764" width="80px" ></a>
|
||||||
<a href="http://brownspace.org/" title="Brown Space Engineering" > <img src="https://avatars2.githubusercontent.com/u/5504507" width="80px" ></a>
|
<a href="http://brownspace.org/" title="Brown Space Engineering" > <img src="https://avatars2.githubusercontent.com/u/5504507" width="80px" ></a>
|
||||||
<a href="http://www.appcelerator.com/" title="Team Appcelerator" > <img src="https://avatars1.githubusercontent.com/u/82188" width="80px" ></a>
|
<a href="http://www.appcelerator.com/" title="Team Appcelerator" > <img src="https://avatars1.githubusercontent.com/u/82188" width="80px" ></a>
|
||||||
|
<a href="https://xmllint.com/" title="XML Lint" > <img src="https://xmllint.com/assets/logo.png" width="80px" ></a>
|
||||||
|
<a href="https://github.com/prettier" title="Prettier" > <img src="https://avatars0.githubusercontent.com/u/25822731" width="80px" ></a>
|
||||||
|
<a href="https://github.com/dolanmiu/docx" title="docx" > <img src="https://i.imgur.com/37uBGhO.gif" width="80px" ></a>
|
||||||
<a href="http://orange-opensource.github.io/" title="Open Source by Orange" > <img src="https://avatars3.githubusercontent.com/u/1506386" width="80px" ></a>
|
<a href="http://orange-opensource.github.io/" title="Open Source by Orange" > <img src="https://avatars3.githubusercontent.com/u/1506386" width="80px" ></a>
|
||||||
<a href="http://www.ybrain.com/" title="YBRAIN Inc." > <img src="https://avatars2.githubusercontent.com/u/38232440" width="80px" ></a>
|
<a href="http://www.ybrain.com/" title="YBRAIN Inc." > <img src="https://avatars2.githubusercontent.com/u/38232440" width="80px" ></a>
|
||||||
<a href="http://99bitcoins.com/" title="99 bitcoins" > <img src="https://avatars0.githubusercontent.com/u/9527779" width="80px" ></a>
|
<a href="http://99bitcoins.com/" title="99 bitcoins" > <img src="https://avatars0.githubusercontent.com/u/9527779" width="80px" ></a>
|
||||||
|
<a href="https://wechaty.github.io/wechaty/" title="Wechaty" > <img src="https://avatars0.githubusercontent.com/u/21285357" width="80px" ></a>
|
||||||
<a href="https://opendatakit.org" title="Open Data Kit" > <img src="https://avatars0.githubusercontent.com/u/6222985" width="80px" ></a>
|
<a href="https://opendatakit.org" title="Open Data Kit" > <img src="https://avatars0.githubusercontent.com/u/6222985" width="80px" ></a>
|
||||||
<a href="https://ridibooks.com" title="RIDI Books" > <img src="https://avatars1.githubusercontent.com/u/24955411" width="80px" ></a>
|
<a href="https://ridibooks.com" title="RIDI Books" > <img src="https://avatars1.githubusercontent.com/u/24955411" width="80px" ></a>
|
||||||
<a href="http://signalk.org" title="Signal K" > <img src="https://avatars1.githubusercontent.com/u/7126740" width="80px" ></a>
|
<a href="http://signalk.org" title="Signal K" > <img src="https://avatars1.githubusercontent.com/u/7126740" width="80px" ></a>
|
||||||
<a href="http://brain.js.org/" title="brain.js" > <img src="https://avatars2.githubusercontent.com/u/23732838" width="80px" ></a>
|
<a href="http://brain.js.org/" title="brain.js" > <img src="https://avatars2.githubusercontent.com/u/23732838" width="80px" ></a>
|
||||||
<a href="https://skygear.io/" title="Skegear" > <img src="https://avatars1.githubusercontent.com/u/15025887" width="80px" ></a>
|
<a href="https://skygear.io/" title="Skegear" > <img src="https://avatars1.githubusercontent.com/u/15025887" width="80px" ></a>
|
||||||
|
<a href="https://npmjs.com/" title="npm" > <img src="https://avatars0.githubusercontent.com/u/6078720" width="80px" ></a>
|
||||||
<a href=" https://www.mindpointgroup.com" title="mindpointgroup" > <img src="https://avatars1.githubusercontent.com/u/6413533" width="80px" ></a>
|
<a href=" https://www.mindpointgroup.com" title="mindpointgroup" > <img src="https://avatars1.githubusercontent.com/u/6413533" width="80px" ></a>
|
||||||
<a href="http://www.acuantcorp.com/" title="Acuant Inc" > <img src="https://avatars3.githubusercontent.com/u/11580319?s=200&v=4" width="80px" ></a>
|
<a href="http://www.acuantcorp.com/" title="Acuant Inc" > <img src="https://avatars3.githubusercontent.com/u/11580319?s=200&v=4" width="80px" ></a>
|
||||||
<a href="https://www.wazuh.com/" title="wazuh" > <img src="https://avatars2.githubusercontent.com/u/13752566" width="80px" ></a>
|
<a href="https://www.wazuh.com/" title="wazuh" > <img src="https://avatars2.githubusercontent.com/u/13752566" width="80px" ></a>
|
||||||
<a href="https://orbs.com/" title="ORBS The Hybrid Blockchain" > <img src="https://avatars1.githubusercontent.com/u/33665977" width="80px" ></a>
|
<a href="https://orbs.com/" title="ORBS The Hybrid Blockchain" > <img src="https://avatars1.githubusercontent.com/u/33665977" width="80px" ></a>
|
||||||
<a href="https://texlab.netlify.com/" title="latex-lsp" > <img src="https://avatars1.githubusercontent.com/u/48360002" width="80px" ></a>
|
<a href="https://texlab.netlify.com/" title="latex-lsp" > <img src="https://avatars1.githubusercontent.com/u/48360002" width="80px" ></a>
|
||||||
<a href="https://frontside.io/" title="The Frontside " > <img src="https://avatars1.githubusercontent.com/u/223096" width="80px" ></a>
|
<a href="https://frontside.io/" title="The Frontside " > <img src="https://avatars1.githubusercontent.com/u/223096" width="80px" ></a>
|
||||||
|
<a href="https://creditsense.com.au/" title="Credit Sense Australia " > <img src="https://avatars0.githubusercontent.com/u/46947118" width="80px" ></a>
|
||||||
<a href="https://www.hustunique.com/" title="UniqueStudio" > <img src="https://avatars1.githubusercontent.com/u/4847684" width="80px" ></a>
|
<a href="https://www.hustunique.com/" title="UniqueStudio" > <img src="https://avatars1.githubusercontent.com/u/4847684" width="80px" ></a>
|
||||||
<a href="http://www.openforis.org/" title="Open Foris" > <img src="https://avatars2.githubusercontent.com/u/1212750" width="80px" ></a>
|
<a href="http://www.openforis.org/" title="Open Foris" > <img src="https://avatars2.githubusercontent.com/u/1212750" width="80px" ></a>
|
||||||
<a href="#" title="NHS Connect" > <img src="https://avatars3.githubusercontent.com/u/20316669" width="80px" ></a>
|
<a href="#" title="NHS Connect" > <img src="https://avatars3.githubusercontent.com/u/20316669" width="80px" ></a>
|
||||||
<a href="https://tradle.io/" title="Tradle" > <img src="https://avatars2.githubusercontent.com/u/9482126" width="80px" ></a>
|
<a href="https://tradle.io/" title="Tradle" > <img src="https://avatars2.githubusercontent.com/u/9482126" width="80px" ></a>
|
||||||
<a href="http://www.anl.gov/" title="Argonne National Laboratory" > <img src="https://avatars0.githubusercontent.com/u/10468712" width="80px" ></a>
|
<a href="http://www.anl.gov/" title="Argonne National Laboratory" > <img src="https://avatars0.githubusercontent.com/u/10468712" width="80px" ></a>
|
||||||
<a href="https://simpleicons.org/" title="Simple Icons" > <img src="https://avatars2.githubusercontent.com/u/29872746" width="80px" ></a>
|
<a href="https://simpleicons.org/" title="Simple Icons" > <img src="https://avatars2.githubusercontent.com/u/29872746" width="80px" ></a>
|
||||||
|
<a href="https://stoplight.io/" title="Stoplight" > <img src="https://avatars1.githubusercontent.com/u/10767217" width="80px" ></a>
|
||||||
|
<a href="http://www.fda.gov/" title="Food and Drug Administration " > <img src="https://avatars2.githubusercontent.com/u/6471964" width="80px" ></a>
|
||||||
|
<a href="http://www.magento.com/" title="Magento" > <img src="https://avatars2.githubusercontent.com/u/168457" width="80px" ></a>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -90,8 +100,6 @@ List of some applications/projects using Fast XML Parser. (Raise an issue to sub
|
||||||
* You can remove namespace from tag or attribute name while parsing
|
* You can remove namespace from tag or attribute name while parsing
|
||||||
* It supports boolean attributes, if configured.
|
* It supports boolean attributes, if configured.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## How to use
|
## How to use
|
||||||
|
|
||||||
To use it in **NPM package** install it first
|
To use it in **NPM package** install it first
|
||||||
|
@ -129,8 +137,10 @@ var options = {
|
||||||
cdataPositionChar: "\\c",
|
cdataPositionChar: "\\c",
|
||||||
localeRange: "", //To support non english character in tag/attribute values.
|
localeRange: "", //To support non english character in tag/attribute values.
|
||||||
parseTrueNumberOnly: false,
|
parseTrueNumberOnly: false,
|
||||||
attrValueProcessor: a => he.decode(a, {isAttributeValue: true}),//default is a=>a
|
arrayMode: false, //"strict"
|
||||||
tagValueProcessor : a => he.decode(a) //default is a=>a
|
attrValueProcessor: (val, attrName) => he.decode(val, {isAttributeValue: true}),//default is a=>a
|
||||||
|
tagValueProcessor : (val, tagName) => he.decode(val), //default is a=>a
|
||||||
|
stopNodes: ["parse-me-as-string"]
|
||||||
};
|
};
|
||||||
|
|
||||||
if( parser.validate(xmlData) === true) { //optional (it'll return an object in case it's not valid)
|
if( parser.validate(xmlData) === true) { //optional (it'll return an object in case it's not valid)
|
||||||
|
@ -142,6 +152,28 @@ var tObj = parser.getTraversalObj(xmlData,options);
|
||||||
var jsonObj = parser.convertToJson(tObj,options);
|
var jsonObj = parser.convertToJson(tObj,options);
|
||||||
|
|
||||||
```
|
```
|
||||||
|
As you can notice in above code, validator is not embeded with in the parser and expected to be called separately. However, you can pass `true` or validation options as 3rd parameter to the parser to trigger validator internally. It is same as above example.
|
||||||
|
|
||||||
|
```js
|
||||||
|
try{
|
||||||
|
var jsonObj = parser.parse(xmlData,options, true);
|
||||||
|
}catch(error){
|
||||||
|
console.log(error.message)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Validator reurns the following object in case of error;
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
err: {
|
||||||
|
code: code,
|
||||||
|
msg: message,
|
||||||
|
line: lineNumber,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
#### Note: [he](https://www.npmjs.com/package/he) library is used in this example
|
#### Note: [he](https://www.npmjs.com/package/he) library is used in this example
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
|
@ -160,6 +192,7 @@ var jsonObj = parser.convertToJson(tObj,options);
|
||||||
* **cdataPositionChar** : It'll help to covert JSON back to XML without losing CDATA position.
|
* **cdataPositionChar** : It'll help to covert JSON back to XML without losing CDATA position.
|
||||||
* **localeRange**: Parser will accept non-English character in tag or attribute name. Check #87 for more detail. Eg `localeRange: "a-zA-Zа-яёА-ЯЁ"`
|
* **localeRange**: Parser will accept non-English character in tag or attribute name. Check #87 for more detail. Eg `localeRange: "a-zA-Zа-яёА-ЯЁ"`
|
||||||
* **parseTrueNumberOnly**: if true then values like "+123", or "0123" will not be parsed as number.
|
* **parseTrueNumberOnly**: if true then values like "+123", or "0123" will not be parsed as number.
|
||||||
|
* **arrayMode** : When `false`, a tag with single occurence is parsed as an object but as an array in case of multiple occurences. When `true`, a tag will be parsed as an array always excluding leaf nodes. When `strict`, all the tags will be parsed as array only.
|
||||||
* **tagValueProcessor** : Process tag value during transformation. Like HTML decoding, word capitalization, etc. Applicable in case of string only.
|
* **tagValueProcessor** : Process tag value during transformation. Like HTML decoding, word capitalization, etc. Applicable in case of string only.
|
||||||
* **attrValueProcessor** : Process attribute value during transformation. Like HTML decoding, word capitalization, etc. Applicable in case of string only.
|
* **attrValueProcessor** : Process attribute value during transformation. Like HTML decoding, word capitalization, etc. Applicable in case of string only.
|
||||||
* **stopNodes** : an array of tag names which are not required to be parsed. Instead their values are parsed as string.
|
* **stopNodes** : an array of tag names which are not required to be parsed. Instead their values are parsed as string.
|
||||||
|
@ -274,11 +307,11 @@ With the correct options, you can get the almost original XML without losing any
|
||||||
|
|
||||||
### Worth to mention
|
### Worth to mention
|
||||||
|
|
||||||
- **[BigBit standard)](https://github.com/amitguptagwl/bigbit)** : A standard to reprent any number in the universe in comparitively less space and without precision loss. A standard to save space to represent any text string in comparision of UTF encoding.
|
- **[BigBit standard)](https://github.com/amitguptagwl/bigbit)** : A standard to represent any number in the universe in comparitively less space and without precision loss. A standard to save memory to represent any text string in comparision of UTF encodings.
|
||||||
- **[imglab](https://github.com/NaturalIntelligence/imglab)** : Speedup and simplify image labeling / annotation. Supports multiple formats, one click annotation, easy interface and much more. There are more than 20k images are annotated every month.
|
- **[imglab](https://github.com/NaturalIntelligence/imglab)** : Speedup and simplify image labeling / annotation. Supports multiple formats, one click annotation, easy interface and much more. There are more than half million images are being annotated every month using this tool.
|
||||||
|
- [stubmatic](https://github.com/NaturalIntelligence/Stubmatic) : Create fake webservices, DynamoDB or S3 servers, Manage fake/mock stub data, Or fake any HTTP(s) call.
|
||||||
- **[अनुमार्गक (anumargak)](https://github.com/NaturalIntelligence/anumargak)** : The fastest and simple router for node js web frameworks with many unique features.
|
- **[अनुमार्गक (anumargak)](https://github.com/NaturalIntelligence/anumargak)** : The fastest and simple router for node js web frameworks with many unique features.
|
||||||
- [stubmatic](https://github.com/NaturalIntelligence/Stubmatic) : A stub server to mock behaviour of HTTP(s) / REST / SOAP services, incuding DynamoDB calls. You can also mock binary formats.
|
- [मुनीम (Muneem)](https://github.com/muneem4node/muneem) : A webframework made for all team members. Fast and Featured.
|
||||||
- [मुनीम (Muneem)](https://github.com/muneem4node/muneem) : A webframework made for all team members. Faster tha fastify, express, koa, hapi and others.
|
|
||||||
- [शब्दावली (shabdawali)](https://github.com/amitguptagwl/shabdawali) : Amazing human like typing effects beyond your imagination.
|
- [शब्दावली (shabdawali)](https://github.com/amitguptagwl/shabdawali) : Amazing human like typing effects beyond your imagination.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
{
|
|
||||||
"tests": "./spec/*_spec.js",
|
|
||||||
"timeout": 10000,
|
|
||||||
"output": "./output",
|
|
||||||
"helpers": {
|
|
||||||
"WebDriverIO": {
|
|
||||||
"url": "http://localhost",
|
|
||||||
"browser": "chrome"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"include": {
|
|
||||||
"I": "./steps_file.js"
|
|
||||||
},
|
|
||||||
"bootstrap": false,
|
|
||||||
"mocha": {},
|
|
||||||
"name": "fxp"
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
* check test coverage and write necessary tests
|
|
||||||
* validate XML stream data
|
|
||||||
* Fix jTox for json array. Not sure if a bug exist.
|
|
||||||
* generate separate and combined browser bundle for xml -> nimn, xml -> json , json -> xml
|
|
||||||
* Es6 to es5 migration without workaround.
|
|
||||||
* Parse JSON string to XML. Currently it transforms JSON object to XML. Partially done. Need to work on performance.
|
|
||||||
* build properties only once
|
|
||||||
* XML to JSON ML : https://en.wikipedia.org/wiki/JsonML
|
|
|
@ -1,32 +1,28 @@
|
||||||
{
|
{
|
||||||
"_args": [
|
"_from": "fast-xml-parser@3.15.1",
|
||||||
[
|
"_id": "fast-xml-parser@3.15.1",
|
||||||
"fast-xml-parser@3.12.20",
|
|
||||||
"C:\\dev\\repos\\actions\\setup-dotnet"
|
|
||||||
]
|
|
||||||
],
|
|
||||||
"_from": "fast-xml-parser@3.12.20",
|
|
||||||
"_id": "fast-xml-parser@3.12.20",
|
|
||||||
"_inBundle": false,
|
"_inBundle": false,
|
||||||
"_integrity": "sha512-viadHdefuuqkyJWUhF2r2Ymb5LJ0T7uQhzSRv4OZzYxpoPQnY05KtaX0pLkolabD7tLzIE8q/OytIAEhqPyYbw==",
|
"_integrity": "sha512-MStlD6aNPZCd9msF5wBh2VJ0jAE2zz85ipk+OIPO+pZi64ckY//oGi5kskcTVRj2bMSmBI5F2SY1IGWHWZzbCA==",
|
||||||
"_location": "/fast-xml-parser",
|
"_location": "/fast-xml-parser",
|
||||||
"_phantomChildren": {},
|
"_phantomChildren": {},
|
||||||
"_requested": {
|
"_requested": {
|
||||||
"type": "version",
|
"type": "version",
|
||||||
"registry": true,
|
"registry": true,
|
||||||
"raw": "fast-xml-parser@3.12.20",
|
"raw": "fast-xml-parser@3.15.1",
|
||||||
"name": "fast-xml-parser",
|
"name": "fast-xml-parser",
|
||||||
"escapedName": "fast-xml-parser",
|
"escapedName": "fast-xml-parser",
|
||||||
"rawSpec": "3.12.20",
|
"rawSpec": "3.15.1",
|
||||||
"saveSpec": null,
|
"saveSpec": null,
|
||||||
"fetchSpec": "3.12.20"
|
"fetchSpec": "3.15.1"
|
||||||
},
|
},
|
||||||
"_requiredBy": [
|
"_requiredBy": [
|
||||||
|
"#USER",
|
||||||
"/"
|
"/"
|
||||||
],
|
],
|
||||||
"_resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-3.12.20.tgz",
|
"_resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-3.15.1.tgz",
|
||||||
"_spec": "3.12.20",
|
"_shasum": "7299ef53b00d5c0f9809599396a26e6d1af20603",
|
||||||
"_where": "C:\\dev\\repos\\actions\\setup-dotnet",
|
"_spec": "fast-xml-parser@3.15.1",
|
||||||
|
"_where": "C:\\Users\\Stanley\\Projects\\GitHub\\setup-dotnet",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "Amit Gupta",
|
"name": "Amit Gupta",
|
||||||
"url": "https://amitkumargupta.work/"
|
"url": "https://amitkumargupta.work/"
|
||||||
|
@ -37,6 +33,7 @@
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/NaturalIntelligence/fast-xml-parser/issues"
|
"url": "https://github.com/NaturalIntelligence/fast-xml-parser/issues"
|
||||||
},
|
},
|
||||||
|
"bundleDependencies": false,
|
||||||
"contributors": [
|
"contributors": [
|
||||||
{
|
{
|
||||||
"name": "Alfonso Muñoz-Pomer Fuentes",
|
"name": "Alfonso Muñoz-Pomer Fuentes",
|
||||||
|
@ -56,28 +53,25 @@
|
||||||
"url": "https://github.com/Tatsh"
|
"url": "https://github.com/Tatsh"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"deprecated": false,
|
||||||
"nimnjs": "^1.3.2"
|
|
||||||
},
|
|
||||||
"description": "Validate XML or Parse XML to JS/JSON very fast without C/C++ based libraries",
|
"description": "Validate XML or Parse XML to JS/JSON very fast without C/C++ based libraries",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.4.0",
|
"@babel/core": "^7.7.5",
|
||||||
"@babel/plugin-transform-runtime": "^7.4.0",
|
"@babel/plugin-transform-runtime": "^7.7.6",
|
||||||
"@babel/preset-env": "^7.4.2",
|
"@babel/preset-env": "^7.7.6",
|
||||||
"@babel/register": "^7.4.0",
|
"@babel/register": "^7.7.4",
|
||||||
"babel-loader": "^8.0.5",
|
"babel-loader": "^8.0.6",
|
||||||
"benchmark": "^2.1.4",
|
"benchmark": "^2.1.4",
|
||||||
"eslint": "^5.15.3",
|
"eslint": "^5.16.0",
|
||||||
"he": "^1.2.0",
|
"he": "^1.2.0",
|
||||||
"http-server": "^0.11.1",
|
"http-server": "^0.11.1",
|
||||||
"istanbul": "^0.4.5",
|
"istanbul": "^0.4.5",
|
||||||
"jasmine": "^3.3.1",
|
"jasmine": "^3.5.0",
|
||||||
"portfinder": "^1.0.20",
|
"nimnjs": "^1.3.2",
|
||||||
"prettier": "^1.15.3",
|
"prettier": "^1.19.1",
|
||||||
"webpack": "^4.29.6",
|
"publish-please": "^5.5.1",
|
||||||
"webpack-cli": "^3.3.0",
|
"webpack": "^4.41.2",
|
||||||
"xml2js": "^0.4.19",
|
"webpack-cli": "^3.3.10"
|
||||||
"zombie": "^5.0.8"
|
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/NaturalIntelligence/fast-xml-parser#readme",
|
"homepage": "https://github.com/NaturalIntelligence/fast-xml-parser#readme",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
@ -119,10 +113,12 @@
|
||||||
"lint": "eslint src/*.js spec/*.js",
|
"lint": "eslint src/*.js spec/*.js",
|
||||||
"perf": "node ./benchmark/perfTest3.js",
|
"perf": "node ./benchmark/perfTest3.js",
|
||||||
"postinstall": "node tasks/postinstall.js || exit 0",
|
"postinstall": "node tasks/postinstall.js || exit 0",
|
||||||
|
"prepublishOnly": "publish-please guard",
|
||||||
"prettier": "prettier --write src/**/*.js",
|
"prettier": "prettier --write src/**/*.js",
|
||||||
|
"publish-please": "publish-please",
|
||||||
"test": "jasmine spec/*spec.js",
|
"test": "jasmine spec/*spec.js",
|
||||||
"unit": "jasmine"
|
"unit": "jasmine"
|
||||||
},
|
},
|
||||||
"typings": "src/parser.d.ts",
|
"typings": "src/parser.d.ts",
|
||||||
"version": "3.12.20"
|
"version": "3.15.1"
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,12 +12,16 @@ const convertToJson = function(node, options) {
|
||||||
//otherwise create a textnode if node has some text
|
//otherwise create a textnode if node has some text
|
||||||
if (util.isExist(node.val)) {
|
if (util.isExist(node.val)) {
|
||||||
if (!(typeof node.val === 'string' && (node.val === '' || node.val === options.cdataPositionChar))) {
|
if (!(typeof node.val === 'string' && (node.val === '' || node.val === options.cdataPositionChar))) {
|
||||||
|
if(options.arrayMode === "strict"){
|
||||||
|
jObj[options.textNodeName] = [ node.val ];
|
||||||
|
}else{
|
||||||
jObj[options.textNodeName] = node.val;
|
jObj[options.textNodeName] = node.val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
util.merge(jObj, node.attrsMap);
|
util.merge(jObj, node.attrsMap, options.arrayMode);
|
||||||
|
|
||||||
const keys = Object.keys(node.child);
|
const keys = Object.keys(node.child);
|
||||||
for (let index = 0; index < keys.length; index++) {
|
for (let index = 0; index < keys.length; index++) {
|
||||||
|
@ -28,9 +32,19 @@ const convertToJson = function(node, options) {
|
||||||
jObj[tagname].push(convertToJson(node.child[tagname][tag], options));
|
jObj[tagname].push(convertToJson(node.child[tagname][tag], options));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if(options.arrayMode === true){
|
||||||
|
const result = convertToJson(node.child[tagname][0], options)
|
||||||
|
if(typeof result === 'object')
|
||||||
|
jObj[tagname] = [ result ];
|
||||||
|
else
|
||||||
|
jObj[tagname] = result;
|
||||||
|
}else if(options.arrayMode === "strict"){
|
||||||
|
jObj[tagname] = [convertToJson(node.child[tagname][0], options) ];
|
||||||
|
}else{
|
||||||
jObj[tagname] = convertToJson(node.child[tagname][0], options);
|
jObj[tagname] = convertToJson(node.child[tagname][0], options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//add value
|
//add value
|
||||||
return jObj;
|
return jObj;
|
||||||
|
|
|
@ -7,17 +7,22 @@ type X2jOptions = {
|
||||||
allowBooleanAttributes: boolean;
|
allowBooleanAttributes: boolean;
|
||||||
parseNodeValue: boolean;
|
parseNodeValue: boolean;
|
||||||
parseAttributeValue: boolean;
|
parseAttributeValue: boolean;
|
||||||
arrayMode: boolean;
|
arrayMode: boolean | 'strict';
|
||||||
trimValues: boolean;
|
trimValues: boolean;
|
||||||
cdataTagName: false | string;
|
cdataTagName: false | string;
|
||||||
cdataPositionChar: string;
|
cdataPositionChar: string;
|
||||||
localeRange: string;
|
localeRange: string;
|
||||||
parseTrueNumberOnly: boolean;
|
parseTrueNumberOnly: boolean;
|
||||||
tagValueProcessor: (tagValue: string) => string;
|
tagValueProcessor: (tagValue: string, tagName: string) => string;
|
||||||
attrValueProcessor: (attrValue: string) => string;
|
attrValueProcessor: (attrValue: string, attrName: string) => string;
|
||||||
|
stopNodes: string[];
|
||||||
};
|
};
|
||||||
type X2jOptionsOptional = Partial<X2jOptions>;
|
type X2jOptionsOptional = Partial<X2jOptions>;
|
||||||
|
type validationOptions = {
|
||||||
|
allowBooleanAttributes: boolean;
|
||||||
|
localeRange: string;
|
||||||
|
};
|
||||||
|
type validationOptionsOptional = Partial<validationOptions>;
|
||||||
type J2xOptions = {
|
type J2xOptions = {
|
||||||
attributeNamePrefix: string;
|
attributeNamePrefix: string;
|
||||||
attrNodeName: false | string;
|
attrNodeName: false | string;
|
||||||
|
@ -39,7 +44,7 @@ type ValidationError = {
|
||||||
err: { code: string; msg: string };
|
err: { code: string; msg: string };
|
||||||
};
|
};
|
||||||
|
|
||||||
export function parse(xmlData: string, options?: X2jOptionsOptional): any;
|
export function parse(xmlData: string, options?: X2jOptionsOptional, validationOptions?: validationOptionsOptional | boolean): any;
|
||||||
export function convert2nimn(
|
export function convert2nimn(
|
||||||
node: any,
|
node: any,
|
||||||
e_schema: ESchema,
|
e_schema: ESchema,
|
||||||
|
@ -56,7 +61,7 @@ export function convertToJsonString(
|
||||||
): string;
|
): string;
|
||||||
export function validate(
|
export function validate(
|
||||||
xmlData: string,
|
xmlData: string,
|
||||||
options?: { allowBooleanAttributes?: boolean }
|
options?: validationOptionsOptional
|
||||||
): true | ValidationError;
|
): true | ValidationError;
|
||||||
export class j2xParser {
|
export class j2xParser {
|
||||||
constructor(options: J2xOptionsOptional);
|
constructor(options: J2xOptionsOptional);
|
||||||
|
|
|
@ -4,8 +4,17 @@ const nodeToJson = require('./node2json');
|
||||||
const xmlToNodeobj = require('./xmlstr2xmlnode');
|
const xmlToNodeobj = require('./xmlstr2xmlnode');
|
||||||
const x2xmlnode = require('./xmlstr2xmlnode');
|
const x2xmlnode = require('./xmlstr2xmlnode');
|
||||||
const buildOptions = require('./util').buildOptions;
|
const buildOptions = require('./util').buildOptions;
|
||||||
|
const validator = require('./validator');
|
||||||
|
|
||||||
exports.parse = function(xmlData, options) {
|
exports.parse = function(xmlData, options, validationOption) {
|
||||||
|
if( validationOption){
|
||||||
|
if(validationOption === true) validationOption = {}
|
||||||
|
|
||||||
|
const result = validator.validate(xmlData, validationOption);
|
||||||
|
if (result !== true) {
|
||||||
|
throw Error( result.err.msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
options = buildOptions(options, x2xmlnode.defaultOptions, x2xmlnode.props);
|
options = buildOptions(options, x2xmlnode.defaultOptions, x2xmlnode.props);
|
||||||
return nodeToJson.convertToJson(xmlToNodeobj.getTraversalObj(xmlData, options), options);
|
return nodeToJson.convertToJson(xmlToNodeobj.getTraversalObj(xmlData, options), options);
|
||||||
};
|
};
|
||||||
|
@ -13,7 +22,7 @@ exports.convertTonimn = require('../src/nimndata').convert2nimn;
|
||||||
exports.getTraversalObj = xmlToNodeobj.getTraversalObj;
|
exports.getTraversalObj = xmlToNodeobj.getTraversalObj;
|
||||||
exports.convertToJson = nodeToJson.convertToJson;
|
exports.convertToJson = nodeToJson.convertToJson;
|
||||||
exports.convertToJsonString = require('./node2json_str').convertToJsonString;
|
exports.convertToJsonString = require('./node2json_str').convertToJsonString;
|
||||||
exports.validate = require('./validator').validate;
|
exports.validate = validator.validate;
|
||||||
exports.j2xParser = require('./json2xml');
|
exports.j2xParser = require('./json2xml');
|
||||||
exports.parseToNimn = function(xmlData, schema, options) {
|
exports.parseToNimn = function(xmlData, schema, options) {
|
||||||
return exports.convertTonimn(exports.getTraversalObj(xmlData, options), schema, options);
|
return exports.convertTonimn(exports.getTraversalObj(xmlData, options), schema, options);
|
||||||
|
|
|
@ -37,14 +37,18 @@ exports.isEmptyObject = function(obj) {
|
||||||
* @param {*} target
|
* @param {*} target
|
||||||
* @param {*} a
|
* @param {*} a
|
||||||
*/
|
*/
|
||||||
exports.merge = function(target, a) {
|
exports.merge = function(target, a, arrayMode) {
|
||||||
if (a) {
|
if (a) {
|
||||||
const keys = Object.keys(a); // will return an array of own properties
|
const keys = Object.keys(a); // will return an array of own properties
|
||||||
const len = keys.length; //don't make it inline
|
const len = keys.length; //don't make it inline
|
||||||
for (let i = 0; i < len; i++) {
|
for (let i = 0; i < len; i++) {
|
||||||
|
if(arrayMode === 'strict'){
|
||||||
|
target[keys[i]] = [ a[keys[i]] ];
|
||||||
|
}else{
|
||||||
target[keys[i]] = a[keys[i]];
|
target[keys[i]] = a[keys[i]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
/* exports.merge =function (b,a){
|
/* exports.merge =function (b,a){
|
||||||
return Object.assign(b,a);
|
return Object.assign(b,a);
|
||||||
|
|
|
@ -10,21 +10,30 @@ const defaultOptions = {
|
||||||
const props = ['allowBooleanAttributes', 'localeRange'];
|
const props = ['allowBooleanAttributes', 'localeRange'];
|
||||||
|
|
||||||
//const tagsPattern = new RegExp("<\\/?([\\w:\\-_\.]+)\\s*\/?>","g");
|
//const tagsPattern = new RegExp("<\\/?([\\w:\\-_\.]+)\\s*\/?>","g");
|
||||||
exports.validate = function(xmlData, options) {
|
exports.validate = function (xmlData, options) {
|
||||||
options = util.buildOptions(options, defaultOptions, props);
|
options = util.buildOptions(options, defaultOptions, props);
|
||||||
|
|
||||||
//xmlData = xmlData.replace(/(\r\n|\n|\r)/gm,"");//make it single line
|
//xmlData = xmlData.replace(/(\r\n|\n|\r)/gm,"");//make it single line
|
||||||
//xmlData = xmlData.replace(/(^\s*<\?xml.*?\?>)/g,"");//Remove XML starting tag
|
//xmlData = xmlData.replace(/(^\s*<\?xml.*?\?>)/g,"");//Remove XML starting tag
|
||||||
//xmlData = xmlData.replace(/(<!DOCTYPE[\s\w\"\.\/\-\:]+(\[.*\])*\s*>)/g,"");//Remove DOCTYPE
|
//xmlData = xmlData.replace(/(<!DOCTYPE[\s\w\"\.\/\-\:]+(\[.*\])*\s*>)/g,"");//Remove DOCTYPE
|
||||||
|
const localRangeRegex = new RegExp(`[${options.localeRange}]`);
|
||||||
|
|
||||||
|
if (localRangeRegex.test("<#$'\"\\\/:0")) {
|
||||||
|
return getErrorObject('InvalidOptions', 'Invalid localeRange', 1);
|
||||||
|
}
|
||||||
|
|
||||||
const tags = [];
|
const tags = [];
|
||||||
let tagFound = false;
|
let tagFound = false;
|
||||||
|
|
||||||
|
//indicates that the root tag has been closed (aka. depth 0 has been reached)
|
||||||
|
let reachedRoot = false;
|
||||||
|
|
||||||
if (xmlData[0] === '\ufeff') {
|
if (xmlData[0] === '\ufeff') {
|
||||||
// check for byte order mark (BOM)
|
// check for byte order mark (BOM)
|
||||||
xmlData = xmlData.substr(1);
|
xmlData = xmlData.substr(1);
|
||||||
}
|
}
|
||||||
const regxAttrName = new RegExp('^[_w][\\w\\-.:]*$'.replace('_w', '_' + options.localeRange));
|
const regxAttrName = new RegExp(`^[${options.localeRange}_][${options.localeRange}0-9\\-\\.:]*$`);
|
||||||
const regxTagName = new RegExp('^([w]|_)[\\w.\\-_:]*'.replace('([w', '([' + options.localeRange));
|
const regxTagName = new RegExp(`^([${options.localeRange}_])[${options.localeRange}0-9\\.\\-_:]*$`);
|
||||||
for (let i = 0; i < xmlData.length; i++) {
|
for (let i = 0; i < xmlData.length; i++) {
|
||||||
if (xmlData[i] === '<') {
|
if (xmlData[i] === '<') {
|
||||||
//starting of tag
|
//starting of tag
|
||||||
|
@ -66,15 +75,22 @@ exports.validate = function(xmlData, options) {
|
||||||
if (tagName[tagName.length - 1] === '/') {
|
if (tagName[tagName.length - 1] === '/') {
|
||||||
//self closing tag without attributes
|
//self closing tag without attributes
|
||||||
tagName = tagName.substring(0, tagName.length - 1);
|
tagName = tagName.substring(0, tagName.length - 1);
|
||||||
continue;
|
//continue;
|
||||||
|
i--;
|
||||||
}
|
}
|
||||||
if (!validateTagName(tagName, regxTagName)) {
|
if (!validateTagName(tagName, regxTagName)) {
|
||||||
return {err: {code: 'InvalidTag', msg: 'Tag ' + tagName + ' is an invalid name.'}};
|
let msg;
|
||||||
|
if(tagName.trim().length === 0) {
|
||||||
|
msg = "There is an unnecessary space between tag name and backward slash '</ ..'.";
|
||||||
|
}else{
|
||||||
|
msg = `Tag '${tagName}' is an invalid name.`;
|
||||||
|
}
|
||||||
|
return getErrorObject('InvalidTag', msg, getLineNumberForPosition(xmlData, i));
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = readAttributeStr(xmlData, i);
|
const result = readAttributeStr(xmlData, i);
|
||||||
if (result === false) {
|
if (result === false) {
|
||||||
return {err: {code: 'InvalidAttr', msg: 'Attributes for ' + tagName + ' have open quote'}};
|
return getErrorObject('InvalidAttr', `Attributes for '${tagName}' have open quote.`, getLineNumberForPosition(xmlData, i));
|
||||||
}
|
}
|
||||||
let attrStr = result.value;
|
let attrStr = result.value;
|
||||||
i = result.index;
|
i = result.index;
|
||||||
|
@ -87,27 +103,43 @@ exports.validate = function(xmlData, options) {
|
||||||
tagFound = true;
|
tagFound = true;
|
||||||
//continue; //text may presents after self closing tag
|
//continue; //text may presents after self closing tag
|
||||||
} else {
|
} else {
|
||||||
return isValid;
|
//the result from the nested function returns the position of the error within the attribute
|
||||||
|
//in order to get the 'true' error line, we need to calculate the position where the attribute begins (i - attrStr.length) and then add the position within the attribute
|
||||||
|
//this gives us the absolute index in the entire xml, which we can use to find the line at last
|
||||||
|
return getErrorObject(isValid.err.code, isValid.err.msg, getLineNumberForPosition(xmlData, i - attrStr.length + isValid.err.line));
|
||||||
}
|
}
|
||||||
} else if (closingTag) {
|
} else if (closingTag) {
|
||||||
if (attrStr.trim().length > 0) {
|
if (!result.tagClosed) {
|
||||||
return {
|
return getErrorObject('InvalidTag', `Closing tag '${tagName}' doesn't have proper closing.`, getLineNumberForPosition(xmlData, i));
|
||||||
err: {code: 'InvalidTag', msg: 'closing tag ' + tagName + " can't have attributes or invalid starting."},
|
} else if (attrStr.trim().length > 0) {
|
||||||
};
|
return getErrorObject('InvalidTag', `Closing tag '${tagName}' can't have attributes or invalid starting.`, getLineNumberForPosition(xmlData, i));
|
||||||
} else {
|
} else {
|
||||||
const otg = tags.pop();
|
const otg = tags.pop();
|
||||||
if (tagName !== otg) {
|
if (tagName !== otg) {
|
||||||
return {
|
return getErrorObject('InvalidTag', `Closing tag '${otg}' is expected inplace of '${tagName}'.`, getLineNumberForPosition(xmlData, i));
|
||||||
err: {code: 'InvalidTag', msg: 'closing tag ' + otg + ' is expected inplace of ' + tagName + '.'},
|
}
|
||||||
};
|
|
||||||
|
//when there are no more tags, we reached the root level.
|
||||||
|
if(tags.length == 0)
|
||||||
|
{
|
||||||
|
reachedRoot = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const isValid = validateAttributeString(attrStr, options, regxAttrName);
|
const isValid = validateAttributeString(attrStr, options, regxAttrName);
|
||||||
if (isValid !== true) {
|
if (isValid !== true) {
|
||||||
return isValid;
|
//the result from the nested function returns the position of the error within the attribute
|
||||||
|
//in order to get the 'true' error line, we need to calculate the position where the attribute begins (i - attrStr.length) and then add the position within the attribute
|
||||||
|
//this gives us the absolute index in the entire xml, which we can use to find the line at last
|
||||||
|
return getErrorObject(isValid.err.code, isValid.err.msg, getLineNumberForPosition(xmlData, i - attrStr.length + isValid.err.line));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//if the root level has been reached before ...
|
||||||
|
if(reachedRoot === true) {
|
||||||
|
return getErrorObject('InvalidXml', 'Multiple possible root nodes found.', getLineNumberForPosition(xmlData, i));
|
||||||
|
} else {
|
||||||
tags.push(tagName);
|
tags.push(tagName);
|
||||||
|
}
|
||||||
tagFound = true;
|
tagFound = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,16 +165,14 @@ exports.validate = function(xmlData, options) {
|
||||||
if (xmlData[i] === ' ' || xmlData[i] === '\t' || xmlData[i] === '\n' || xmlData[i] === '\r') {
|
if (xmlData[i] === ' ' || xmlData[i] === '\t' || xmlData[i] === '\n' || xmlData[i] === '\r') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
return {err: {code: 'InvalidChar', msg: 'char ' + xmlData[i] + ' is not expected .'}};
|
return getErrorObject('InvalidChar', `char '${xmlData[i]}' is not expected.`, getLineNumberForPosition(xmlData, i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tagFound) {
|
if (!tagFound) {
|
||||||
return {err: {code: 'InvalidXml', msg: 'Start tag expected.'}};
|
return getErrorObject('InvalidXml', 'Start tag expected.', 1);
|
||||||
} else if (tags.length > 0) {
|
} else if (tags.length > 0) {
|
||||||
return {
|
return getErrorObject('InvalidXml', `Invalid '${JSON.stringify(tags, null, 4).replace(/\r?\n/g, '')}' found.`, 1);
|
||||||
err: {code: 'InvalidXml', msg: 'Invalid ' + JSON.stringify(tags, null, 4).replace(/\r?\n/g, '') + ' found.'},
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -160,7 +190,7 @@ function readPI(xmlData, i) {
|
||||||
//tagname
|
//tagname
|
||||||
var tagname = xmlData.substr(start, i - start);
|
var tagname = xmlData.substr(start, i - start);
|
||||||
if (i > 5 && tagname === 'xml') {
|
if (i > 5 && tagname === 'xml') {
|
||||||
return {err: {code: 'InvalidXml', msg: 'XML declaration allowed only at the start of the document.'}};
|
return getErrorObject('InvalidXml', 'XML declaration allowed only at the start of the document.', getLineNumberForPosition(xmlData, i));
|
||||||
} else if (xmlData[i] == '?' && xmlData[i + 1] == '>') {
|
} else if (xmlData[i] == '?' && xmlData[i + 1] == '>') {
|
||||||
//check if valid attribut string
|
//check if valid attribut string
|
||||||
i++;
|
i++;
|
||||||
|
@ -235,6 +265,7 @@ var singleQuote = "'";
|
||||||
function readAttributeStr(xmlData, i) {
|
function readAttributeStr(xmlData, i) {
|
||||||
let attrStr = '';
|
let attrStr = '';
|
||||||
let startChar = '';
|
let startChar = '';
|
||||||
|
let tagClosed = false;
|
||||||
for (; i < xmlData.length; i++) {
|
for (; i < xmlData.length; i++) {
|
||||||
if (xmlData[i] === doubleQuote || xmlData[i] === singleQuote) {
|
if (xmlData[i] === doubleQuote || xmlData[i] === singleQuote) {
|
||||||
if (startChar === '') {
|
if (startChar === '') {
|
||||||
|
@ -247,6 +278,7 @@ function readAttributeStr(xmlData, i) {
|
||||||
}
|
}
|
||||||
} else if (xmlData[i] === '>') {
|
} else if (xmlData[i] === '>') {
|
||||||
if (startChar === '') {
|
if (startChar === '') {
|
||||||
|
tagClosed = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -256,7 +288,7 @@ function readAttributeStr(xmlData, i) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {value: attrStr, index: i};
|
return { value: attrStr, index: i, tagClosed: tagClosed };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -275,34 +307,40 @@ function validateAttributeString(attrStr, options, regxAttrName) {
|
||||||
const attrNames = {};
|
const attrNames = {};
|
||||||
|
|
||||||
for (let i = 0; i < matches.length; i++) {
|
for (let i = 0; i < matches.length; i++) {
|
||||||
//console.log(matches[i]);
|
|
||||||
|
|
||||||
if (matches[i][1].length === 0) {
|
if (matches[i][1].length === 0) {
|
||||||
//nospace before attribute name: a="sd"b="saf"
|
//nospace before attribute name: a="sd"b="saf"
|
||||||
return {err: {code: 'InvalidAttr', msg: 'attribute ' + matches[i][2] + ' has no space in starting.'}};
|
return getErrorObject('InvalidAttr', `Attribute '${matches[i][2]}' has no space in starting.`, getPositionFromMatch(attrStr, matches[i][0]))
|
||||||
} else if (matches[i][3] === undefined && !options.allowBooleanAttributes) {
|
} else if (matches[i][3] === undefined && !options.allowBooleanAttributes) {
|
||||||
//independent attribute: ab
|
//independent attribute: ab
|
||||||
return {err: {code: 'InvalidAttr', msg: 'boolean attribute ' + matches[i][2] + ' is not allowed.'}};
|
return getErrorObject('InvalidAttr', `boolean attribute '${matches[i][2]}' is not allowed.`, getPositionFromMatch(attrStr, matches[i][0]));
|
||||||
}
|
}
|
||||||
/* else if(matches[i][6] === undefined){//attribute without value: ab=
|
/* else if(matches[i][6] === undefined){//attribute without value: ab=
|
||||||
return { err: { code:"InvalidAttr",msg:"attribute " + matches[i][2] + " has no value assigned."}};
|
return { err: { code:"InvalidAttr",msg:"attribute " + matches[i][2] + " has no value assigned."}};
|
||||||
} */
|
} */
|
||||||
const attrName = matches[i][2];
|
const attrName = matches[i][2];
|
||||||
if (!validateAttrName(attrName, regxAttrName)) {
|
if (!validateAttrName(attrName, regxAttrName)) {
|
||||||
return {err: {code: 'InvalidAttr', msg: 'attribute ' + attrName + ' is an invalid name.'}};
|
return getErrorObject('InvalidAttr', `Attribute '${attrName}' is an invalid name.`, getPositionFromMatch(attrStr, matches[i][0]));
|
||||||
}
|
}
|
||||||
if (!attrNames.hasOwnProperty(attrName)) {
|
if (!attrNames.hasOwnProperty(attrName)) {
|
||||||
//check for duplicate attribute.
|
//check for duplicate attribute.
|
||||||
attrNames[attrName] = 1;
|
attrNames[attrName] = 1;
|
||||||
} else {
|
} else {
|
||||||
return {err: {code: 'InvalidAttr', msg: 'attribute ' + attrName + ' is repeated.'}};
|
return getErrorObject('InvalidAttr', `Attribute '${attrName}' is repeated.`, getPositionFromMatch(attrStr, matches[i][0]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// const validAttrRegxp = /^[_a-zA-Z][\w\-.:]*$/;
|
function getErrorObject(code, message, lineNumber) {
|
||||||
|
return {
|
||||||
|
err: {
|
||||||
|
code: code,
|
||||||
|
msg: message,
|
||||||
|
line: lineNumber,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function validateAttrName(attrName, regxAttrName) {
|
function validateAttrName(attrName, regxAttrName) {
|
||||||
// const validAttrRegxp = new RegExp(regxAttrName);
|
// const validAttrRegxp = new RegExp(regxAttrName);
|
||||||
|
@ -315,5 +353,17 @@ function validateAttrName(attrName, regxAttrName) {
|
||||||
function validateTagName(tagname, regxTagName) {
|
function validateTagName(tagname, regxTagName) {
|
||||||
/*if(util.doesMatch(tagname,startsWithXML)) return false;
|
/*if(util.doesMatch(tagname,startsWithXML)) return false;
|
||||||
else*/
|
else*/
|
||||||
|
//return !tagname.toLowerCase().startsWith("xml") || !util.doesNotMatch(tagname, regxTagName);
|
||||||
return !util.doesNotMatch(tagname, regxTagName);
|
return !util.doesNotMatch(tagname, regxTagName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//this function returns the line number for the character at the given index
|
||||||
|
function getLineNumberForPosition(xmlData, index) {
|
||||||
|
var lines = xmlData.substring(0, index).split(/\r?\n/);
|
||||||
|
return lines.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
//this function returns the position of the last character of match within attrStr
|
||||||
|
function getPositionFromMatch(attrStr, match) {
|
||||||
|
return attrStr.indexOf(match) + match.length;
|
||||||
|
}
|
|
@ -33,10 +33,10 @@ const defaultOptions = {
|
||||||
cdataTagName: false,
|
cdataTagName: false,
|
||||||
cdataPositionChar: '\\c',
|
cdataPositionChar: '\\c',
|
||||||
localeRange: '',
|
localeRange: '',
|
||||||
tagValueProcessor: function(a) {
|
tagValueProcessor: function(a, tagName) {
|
||||||
return a;
|
return a;
|
||||||
},
|
},
|
||||||
attrValueProcessor: function(a) {
|
attrValueProcessor: function(a, attrName) {
|
||||||
return a;
|
return a;
|
||||||
},
|
},
|
||||||
stopNodes: []
|
stopNodes: []
|
||||||
|
@ -84,7 +84,7 @@ const getTraversalObj = function(xmlData, options) {
|
||||||
if (tagType === TagType.CLOSING) {
|
if (tagType === TagType.CLOSING) {
|
||||||
//add parsed data to parent node
|
//add parsed data to parent node
|
||||||
if (currentNode.parent && tag[14]) {
|
if (currentNode.parent && tag[14]) {
|
||||||
currentNode.parent.val = util.getValue(currentNode.parent.val) + '' + processTagValue(tag[14], options);
|
currentNode.parent.val = util.getValue(currentNode.parent.val) + '' + processTagValue(tag, options, currentNode.parent.tagname);
|
||||||
}
|
}
|
||||||
if (options.stopNodes.length && options.stopNodes.includes(currentNode.tagname)) {
|
if (options.stopNodes.length && options.stopNodes.includes(currentNode.tagname)) {
|
||||||
currentNode.child = []
|
currentNode.child = []
|
||||||
|
@ -102,14 +102,14 @@ const getTraversalObj = function(xmlData, options) {
|
||||||
currentNode.val = util.getValue(currentNode.val) + options.cdataPositionChar;
|
currentNode.val = util.getValue(currentNode.val) + options.cdataPositionChar;
|
||||||
//add rest value to parent node
|
//add rest value to parent node
|
||||||
if (tag[14]) {
|
if (tag[14]) {
|
||||||
currentNode.val += processTagValue(tag[14], options);
|
currentNode.val += processTagValue(tag, options);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
currentNode.val = (currentNode.val || '') + (tag[3] || '') + processTagValue(tag[14], options);
|
currentNode.val = (currentNode.val || '') + (tag[3] || '') + processTagValue(tag, options);
|
||||||
}
|
}
|
||||||
} else if (tagType === TagType.SELF) {
|
} else if (tagType === TagType.SELF) {
|
||||||
if (currentNode && tag[14]) {
|
if (currentNode && tag[14]) {
|
||||||
currentNode.val = util.getValue(currentNode.val) + '' + processTagValue(tag[14], options);
|
currentNode.val = util.getValue(currentNode.val) + '' + processTagValue(tag, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
const childNode = new xmlNode(options.ignoreNameSpace ? tag[7] : tag[5], currentNode, '');
|
const childNode = new xmlNode(options.ignoreNameSpace ? tag[7] : tag[5], currentNode, '');
|
||||||
|
@ -123,7 +123,7 @@ const getTraversalObj = function(xmlData, options) {
|
||||||
const childNode = new xmlNode(
|
const childNode = new xmlNode(
|
||||||
options.ignoreNameSpace ? tag[7] : tag[5],
|
options.ignoreNameSpace ? tag[7] : tag[5],
|
||||||
currentNode,
|
currentNode,
|
||||||
processTagValue(tag[14], options)
|
processTagValue(tag, options)
|
||||||
);
|
);
|
||||||
if (options.stopNodes.length && options.stopNodes.includes(childNode.tagname)) {
|
if (options.stopNodes.length && options.stopNodes.includes(childNode.tagname)) {
|
||||||
childNode.startIndex=tag.index + tag[1].length
|
childNode.startIndex=tag.index + tag[1].length
|
||||||
|
@ -140,12 +140,14 @@ const getTraversalObj = function(xmlData, options) {
|
||||||
return xmlObj;
|
return xmlObj;
|
||||||
};
|
};
|
||||||
|
|
||||||
function processTagValue(val, options) {
|
function processTagValue(parsedTags, options, parentTagName) {
|
||||||
|
const tagName = parsedTags[7] || parentTagName;
|
||||||
|
let val = parsedTags[14];
|
||||||
if (val) {
|
if (val) {
|
||||||
if (options.trimValues) {
|
if (options.trimValues) {
|
||||||
val = val.trim();
|
val = val.trim();
|
||||||
}
|
}
|
||||||
val = options.tagValueProcessor(val);
|
val = options.tagValueProcessor(val, tagName);
|
||||||
val = parseValue(val, options.parseNodeValue, options.parseTrueNumberOnly);
|
val = parseValue(val, options.parseNodeValue, options.parseTrueNumberOnly);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,6 +191,7 @@ function parseValue(val, shouldParse, parseTrueNumberOnly) {
|
||||||
parsed = Number.parseInt(val, 16);
|
parsed = Number.parseInt(val, 16);
|
||||||
} else if (val.indexOf('.') !== -1) {
|
} else if (val.indexOf('.') !== -1) {
|
||||||
parsed = Number.parseFloat(val);
|
parsed = Number.parseFloat(val);
|
||||||
|
val = val.replace(/0+$/,"");
|
||||||
} else {
|
} else {
|
||||||
parsed = Number.parseInt(val, 10);
|
parsed = Number.parseInt(val, 10);
|
||||||
}
|
}
|
||||||
|
@ -225,7 +228,7 @@ function buildAttributesMap(attrStr, options) {
|
||||||
if (options.trimValues) {
|
if (options.trimValues) {
|
||||||
matches[i][4] = matches[i][4].trim();
|
matches[i][4] = matches[i][4].trim();
|
||||||
}
|
}
|
||||||
matches[i][4] = options.attrValueProcessor(matches[i][4]);
|
matches[i][4] = options.attrValueProcessor(matches[i][4], attrName);
|
||||||
attrs[options.attributeNamePrefix + attrName] = parseValue(
|
attrs[options.attributeNamePrefix + attrName] = parseValue(
|
||||||
matches[i][4],
|
matches[i][4],
|
||||||
options.parseAttributeValue,
|
options.parseAttributeValue,
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,16 +0,0 @@
|
||||||
{
|
|
||||||
"version": "0.2.0",
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"type": "node",
|
|
||||||
"request": "launch",
|
|
||||||
"name": "Jasmine Tests",
|
|
||||||
"program": "${workspaceFolder}/node_modules/jasmine/bin/jasmine.js",
|
|
||||||
"args": [
|
|
||||||
"${workspaceFolder}/test/dateparser_test.js"
|
|
||||||
],
|
|
||||||
"internalConsoleOptions": "openOnSessionStart"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2018
|
|
||||||
|
|
||||||
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.
|
|
|
@ -1,139 +0,0 @@
|
||||||
var monthInitials = ["J","F","M","A","m","j","U","a","S","O","N","D"];
|
|
||||||
|
|
||||||
var initials = ["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
|
|
||||||
var timeZone = [
|
|
||||||
12*60,
|
|
||||||
11*60,
|
|
||||||
10*60,
|
|
||||||
9.5*60,
|
|
||||||
9*60,
|
|
||||||
8*60,
|
|
||||||
7*60,
|
|
||||||
6*60,
|
|
||||||
5*60,
|
|
||||||
4*60,
|
|
||||||
3.5*60,
|
|
||||||
3*60,
|
|
||||||
2*60,
|
|
||||||
1*60,
|
|
||||||
0*60,
|
|
||||||
-1*60,
|
|
||||||
-2*60,
|
|
||||||
-3*60,
|
|
||||||
-3.5*60,
|
|
||||||
-4*60,
|
|
||||||
-4.5*60,
|
|
||||||
-5*60,
|
|
||||||
-5.5*60,
|
|
||||||
-5.75*60,
|
|
||||||
-6*60,
|
|
||||||
-6.5*60,
|
|
||||||
-7*60,
|
|
||||||
-8*60,
|
|
||||||
-8.5*60,
|
|
||||||
-8.75*60,
|
|
||||||
-9*60,
|
|
||||||
-9.5*60,
|
|
||||||
-10*60,
|
|
||||||
-10.5*60,
|
|
||||||
-11*60,
|
|
||||||
-12*60,
|
|
||||||
-12.75*60,
|
|
||||||
-13*60,
|
|
||||||
-14*60
|
|
||||||
];
|
|
||||||
|
|
||||||
function parseToUTC(dtObj, includeDate, includeCentury, includeTime){
|
|
||||||
if(typeof dtObj === "string"){
|
|
||||||
dtObj = new Date(dtObj);
|
|
||||||
}
|
|
||||||
var dtStr = "";
|
|
||||||
if(includeCentury){
|
|
||||||
dtStr += char(Math.floor(dtObj.getUTCFullYear()/100)) ;
|
|
||||||
}
|
|
||||||
if(includeDate){//3
|
|
||||||
//year
|
|
||||||
dtStr += char(dtObj.getUTCFullYear()%100);
|
|
||||||
//month
|
|
||||||
dtStr += monthInitials[dtObj.getUTCMonth()];
|
|
||||||
//date
|
|
||||||
dtStr += initials[dtObj.getUTCDate()]
|
|
||||||
}
|
|
||||||
|
|
||||||
if(includeTime){//5
|
|
||||||
//h
|
|
||||||
dtStr += initials[dtObj.getUTCHours()]
|
|
||||||
//m
|
|
||||||
dtStr += initials[dtObj.getUTCMinutes()];
|
|
||||||
//s
|
|
||||||
dtStr += initials[dtObj.getUTCSeconds()];
|
|
||||||
//ms
|
|
||||||
var ms = dtObj.getUTCMilliseconds();
|
|
||||||
dtStr += char(Math.floor(ms/10)) ;
|
|
||||||
dtStr += char(ms%10) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
//zone
|
|
||||||
//if(includeZone){//1
|
|
||||||
dtStr += initials[timeZone.indexOf(dtObj.getTimezoneOffset() ) ]
|
|
||||||
//}
|
|
||||||
return dtStr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {*} dtStr
|
|
||||||
* @param {*} includeDate
|
|
||||||
* @param {*} includeCentury
|
|
||||||
* @param {*} includeTime
|
|
||||||
* @param {*} includeZone
|
|
||||||
*/
|
|
||||||
function parseBackUTC(dtStr,includeDate, includeCentury, includeTime){
|
|
||||||
|
|
||||||
var century = 0;
|
|
||||||
var startFrom = 0;
|
|
||||||
var Y = 0, M = 0, D = 0, h = 0, m = 0, s = 0, ms = 0, z = 0;
|
|
||||||
if(includeCentury){//1st digit is century
|
|
||||||
century = 100 * ascii(dtStr[startFrom++]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(includeDate){
|
|
||||||
Y = century + ascii(dtStr[startFrom++]);
|
|
||||||
M = monthInitials.indexOf(dtStr[startFrom++]);
|
|
||||||
D = initials.indexOf(dtStr[startFrom++])
|
|
||||||
//startFrom += 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(includeTime){
|
|
||||||
h = initials.indexOf(dtStr[startFrom++]);
|
|
||||||
m = initials.indexOf(dtStr[startFrom++]);
|
|
||||||
s = initials.indexOf(dtStr[startFrom++]);
|
|
||||||
|
|
||||||
ms = ascii(dtStr[startFrom++])*10 + ascii(dtStr[startFrom++]);
|
|
||||||
//startFrom += 5;
|
|
||||||
}
|
|
||||||
var dt = new Date(Y,M,D,h,m,s,ms);
|
|
||||||
//if(includeZone){
|
|
||||||
z = timeZone[initials.indexOf(dtStr[startFrom])];
|
|
||||||
dt.setTime(dt.getTime() - z*60*1000);
|
|
||||||
//}
|
|
||||||
|
|
||||||
return dt;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function ascii(ch){
|
|
||||||
return ch.charCodeAt(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* converts a ASCII number into equivalant ASCII char
|
|
||||||
* @param {number} a
|
|
||||||
* @returns ASCII char
|
|
||||||
*/
|
|
||||||
var char = function (a){
|
|
||||||
return String.fromCharCode(a);
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.parse = parseToUTC;
|
|
||||||
exports.parseBack = parseBackUTC;
|
|
|
@ -1,63 +0,0 @@
|
||||||
{
|
|
||||||
"_args": [
|
|
||||||
[
|
|
||||||
"nimn-date-parser@1.0.0",
|
|
||||||
"C:\\dev\\repos\\actions\\setup-dotnet"
|
|
||||||
]
|
|
||||||
],
|
|
||||||
"_from": "nimn-date-parser@1.0.0",
|
|
||||||
"_id": "nimn-date-parser@1.0.0",
|
|
||||||
"_inBundle": false,
|
|
||||||
"_integrity": "sha512-1Nf+x3EeMvHUiHsVuEhiZnwA8RMeOBVTQWfB1S2n9+i6PYCofHd2HRMD+WOHIHYshy4T4Gk8wQoCol7Hq3av8Q==",
|
|
||||||
"_location": "/nimn-date-parser",
|
|
||||||
"_phantomChildren": {},
|
|
||||||
"_requested": {
|
|
||||||
"type": "version",
|
|
||||||
"registry": true,
|
|
||||||
"raw": "nimn-date-parser@1.0.0",
|
|
||||||
"name": "nimn-date-parser",
|
|
||||||
"escapedName": "nimn-date-parser",
|
|
||||||
"rawSpec": "1.0.0",
|
|
||||||
"saveSpec": null,
|
|
||||||
"fetchSpec": "1.0.0"
|
|
||||||
},
|
|
||||||
"_requiredBy": [
|
|
||||||
"/nimnjs"
|
|
||||||
],
|
|
||||||
"_resolved": "https://registry.npmjs.org/nimn-date-parser/-/nimn-date-parser-1.0.0.tgz",
|
|
||||||
"_spec": "1.0.0",
|
|
||||||
"_where": "C:\\dev\\repos\\actions\\setup-dotnet",
|
|
||||||
"author": {
|
|
||||||
"name": "Amit Gupta",
|
|
||||||
"url": "https://github.com/amitguptagwl"
|
|
||||||
},
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/nimndata/nimnjs-date-parser/issues"
|
|
||||||
},
|
|
||||||
"description": "Compress date for nimnjs",
|
|
||||||
"devDependencies": {
|
|
||||||
"jasmine": "^3.0.0",
|
|
||||||
"jasmine-core": "^2.99.1"
|
|
||||||
},
|
|
||||||
"directories": {
|
|
||||||
"test": "tests"
|
|
||||||
},
|
|
||||||
"homepage": "https://github.com/nimndata/nimnjs-date-parser#readme",
|
|
||||||
"keywords": [
|
|
||||||
"nimn",
|
|
||||||
"nimnjs",
|
|
||||||
"date",
|
|
||||||
"parser"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
|
||||||
"main": "dateparser.js",
|
|
||||||
"name": "nimn-date-parser",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git+https://github.com/nimndata/nimnjs-date-parser.git"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"test": "jasmine tests/*test.js"
|
|
||||||
},
|
|
||||||
"version": "1.0.0"
|
|
||||||
}
|
|
|
@ -1,72 +0,0 @@
|
||||||
var parser = require("../dateparser.js");
|
|
||||||
|
|
||||||
describe("Date parser", function () {
|
|
||||||
it(" should parse and parseback full date", function () {
|
|
||||||
|
|
||||||
var dt = new Date("Mon Feb 26 2018 17:42:17 GMT+0530 (IST)");
|
|
||||||
//var dt = new Date("Tue May 15 2012 05:45:40 GMT-0500");
|
|
||||||
//console.log(dt);
|
|
||||||
|
|
||||||
var nimnDt = parser.parse(dt,true,true,true);
|
|
||||||
console.log(nimnDt);
|
|
||||||
|
|
||||||
var dt2 = parser.parseBack(nimnDt,true,true,true);
|
|
||||||
//console.log(dt2);
|
|
||||||
|
|
||||||
expect(dt).toEqual(dt2);
|
|
||||||
expect(10).toEqual(nimnDt.length);
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
it(" should parse and parseback only date part", function () {
|
|
||||||
|
|
||||||
var dt = new Date();
|
|
||||||
//console.log(dt);
|
|
||||||
|
|
||||||
var nimnDt = parser.parse(dt,true,false);
|
|
||||||
//console.log(nimnDt);
|
|
||||||
|
|
||||||
var dt2 = parser.parseBack(nimnDt,true,false);
|
|
||||||
//console.log(dt2);
|
|
||||||
|
|
||||||
expect(4).toEqual(nimnDt.length);
|
|
||||||
expect(dt.getFullYear()%100).toEqual(dt2.getFullYear()%100);
|
|
||||||
expect(dt.getMonth()).toEqual(dt2.getMonth());
|
|
||||||
expect(dt.getDate()).toEqual(dt2.getDate());
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
it(" should parse and parseback date part with century", function () {
|
|
||||||
var dt = new Date();
|
|
||||||
//console.log(dt);
|
|
||||||
|
|
||||||
var nimnDt = parser.parse(dt,true,true);
|
|
||||||
//console.log(nimnDt);
|
|
||||||
|
|
||||||
var dt2 = parser.parseBack(nimnDt,true,true);
|
|
||||||
//console.log(dt2);
|
|
||||||
|
|
||||||
expect(5).toEqual(nimnDt.length);
|
|
||||||
expect(dt.getFullYear()).toEqual(dt2.getFullYear());
|
|
||||||
expect(dt.getMonth()).toEqual(dt2.getMonth());
|
|
||||||
expect(dt.getDate()).toEqual(dt2.getDate());
|
|
||||||
});
|
|
||||||
|
|
||||||
it(" should parse and parseback time", function () {
|
|
||||||
var dt = new Date();
|
|
||||||
//console.log(dt);
|
|
||||||
|
|
||||||
var nimnDt = parser.parse(dt,false,false,true);
|
|
||||||
//console.log(nimnDt);
|
|
||||||
|
|
||||||
var dt2 = parser.parseBack(nimnDt,false,false,true);
|
|
||||||
//console.log(dt2);
|
|
||||||
|
|
||||||
expect(6).toEqual(nimnDt.length);
|
|
||||||
expect(dt.getHours()).toEqual(dt2.getHours());
|
|
||||||
expect(dt.getMinutes()).toEqual(dt2.getMinutes());
|
|
||||||
expect(dt.getSeconds()).toEqual(dt2.getSeconds());
|
|
||||||
expect(dt.getMilliseconds()).toEqual(dt2.getMilliseconds());
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
|
@ -1,21 +0,0 @@
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2018
|
|
||||||
|
|
||||||
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.
|
|
|
@ -1,49 +0,0 @@
|
||||||
# nimnjs-schema-builder
|
|
||||||
Build schema from JS object or JSON to feed into [nimnjs](https://github.com/nimndata/nimnjs-node).
|
|
||||||
|
|
||||||
|
|
||||||
## Usages
|
|
||||||
|
|
||||||
First install or add to your npm package
|
|
||||||
```
|
|
||||||
$npm install nimn_schema_builder
|
|
||||||
```
|
|
||||||
|
|
||||||
```js
|
|
||||||
var builder = require("nimn_schema_builder");
|
|
||||||
|
|
||||||
var data = {
|
|
||||||
name : "amit",
|
|
||||||
age : 32,
|
|
||||||
human : true,
|
|
||||||
projects : [
|
|
||||||
{
|
|
||||||
name: "some",
|
|
||||||
from: new Date(),
|
|
||||||
//to: null,
|
|
||||||
decription : "some long description"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
var schema = builder.build(data);
|
|
||||||
|
|
||||||
/*
|
|
||||||
var schema = {
|
|
||||||
name : "string",
|
|
||||||
age : "number",
|
|
||||||
human : "boolean",
|
|
||||||
projects : [
|
|
||||||
{
|
|
||||||
name: "string",
|
|
||||||
from: "date",
|
|
||||||
decription : "string"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
```
|
|
||||||
|
|
||||||
You can also use it in browser from [dist](dist/nimn-schema-builder.js) folder.
|
|
||||||
|
|
||||||
Check the [demo](https://nimndata.github.io/nimnjs-schema-builder/) for instant use.
|
|
|
@ -1,44 +0,0 @@
|
||||||
|
|
||||||
/**
|
|
||||||
* Build Schema for nimnification of JSON data
|
|
||||||
* @param {*} jsObj
|
|
||||||
*/
|
|
||||||
function buildSchema(jsObj){
|
|
||||||
var type = typeOf(jsObj);
|
|
||||||
switch(type){
|
|
||||||
case "array":
|
|
||||||
return [buildSchema(jsObj[0])];
|
|
||||||
case "object":
|
|
||||||
var schema = { };
|
|
||||||
var keys = Object.keys(jsObj);
|
|
||||||
for(var i in keys){
|
|
||||||
var key = keys[i];
|
|
||||||
/* if(key === null || typeof key === "undefined"){//in case of null or undefined, take sibling's type
|
|
||||||
if(keys[i+1] ){
|
|
||||||
schema[key] = buildSchema(jsObj[keys[i+1]]);
|
|
||||||
}else if(keys[i-1]){
|
|
||||||
schema[key] = buildSchema(jsObj[keys[i-1]]);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
} */
|
|
||||||
schema[key] = buildSchema(jsObj[key]);
|
|
||||||
}
|
|
||||||
return schema;
|
|
||||||
case "string":
|
|
||||||
case "number":
|
|
||||||
case "date":
|
|
||||||
case "boolean":
|
|
||||||
return type;
|
|
||||||
default:
|
|
||||||
throw Error("Unacceptable type : " + type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function typeOf(obj){
|
|
||||||
if(obj === null) return "null";
|
|
||||||
else if(Array.isArray(obj)) return "array";
|
|
||||||
else if(obj instanceof Date) return "date";
|
|
||||||
else return typeof obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports.build = buildSchema;
|
|
|
@ -1,47 +0,0 @@
|
||||||
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.nimnSchemaBuilder = f()}})(function(){var define,module,exports;return (function(){function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}return e})()({1:[function(require,module,exports){
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Build Schema for nimnification of JSON data
|
|
||||||
* @param {*} jsObj
|
|
||||||
*/
|
|
||||||
function buildSchema(jsObj){
|
|
||||||
var type = typeOf(jsObj);
|
|
||||||
switch(type){
|
|
||||||
case "array":
|
|
||||||
return [buildSchema(jsObj[0])];
|
|
||||||
case "object":
|
|
||||||
var schema = { };
|
|
||||||
var keys = Object.keys(jsObj);
|
|
||||||
for(var i in keys){
|
|
||||||
var key = keys[i];
|
|
||||||
/* if(key === null || typeof key === "undefined"){//in case of null or undefined, take sibling's type
|
|
||||||
if(keys[i+1] ){
|
|
||||||
schema[key] = buildSchema(jsObj[keys[i+1]]);
|
|
||||||
}else if(keys[i-1]){
|
|
||||||
schema[key] = buildSchema(jsObj[keys[i-1]]);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
} */
|
|
||||||
schema[key] = buildSchema(jsObj[key]);
|
|
||||||
}
|
|
||||||
return schema;
|
|
||||||
case "string":
|
|
||||||
case "number":
|
|
||||||
case "date":
|
|
||||||
case "boolean":
|
|
||||||
return type;
|
|
||||||
default:
|
|
||||||
throw Error("Unacceptable type : " + type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function typeOf(obj){
|
|
||||||
if(obj === null) return "null";
|
|
||||||
else if(Array.isArray(obj)) return "array";
|
|
||||||
else if(obj instanceof Date) return "date";
|
|
||||||
else return typeof obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports.build = buildSchema;
|
|
||||||
},{}]},{},[1])(1)
|
|
||||||
});
|
|
|
@ -1,59 +0,0 @@
|
||||||
{
|
|
||||||
"_args": [
|
|
||||||
[
|
|
||||||
"nimn_schema_builder@1.1.0",
|
|
||||||
"C:\\dev\\repos\\actions\\setup-dotnet"
|
|
||||||
]
|
|
||||||
],
|
|
||||||
"_from": "nimn_schema_builder@1.1.0",
|
|
||||||
"_id": "nimn_schema_builder@1.1.0",
|
|
||||||
"_inBundle": false,
|
|
||||||
"_integrity": "sha512-DK5/B8CM4qwzG2URy130avcwPev4uO0ev836FbQyKo1ms6I9z/i6EJyiZ+d9xtgloxUri0W+5gfR8YbPq7SheA==",
|
|
||||||
"_location": "/nimn_schema_builder",
|
|
||||||
"_phantomChildren": {},
|
|
||||||
"_requested": {
|
|
||||||
"type": "version",
|
|
||||||
"registry": true,
|
|
||||||
"raw": "nimn_schema_builder@1.1.0",
|
|
||||||
"name": "nimn_schema_builder",
|
|
||||||
"escapedName": "nimn_schema_builder",
|
|
||||||
"rawSpec": "1.1.0",
|
|
||||||
"saveSpec": null,
|
|
||||||
"fetchSpec": "1.1.0"
|
|
||||||
},
|
|
||||||
"_requiredBy": [
|
|
||||||
"/nimnjs"
|
|
||||||
],
|
|
||||||
"_resolved": "https://registry.npmjs.org/nimn_schema_builder/-/nimn_schema_builder-1.1.0.tgz",
|
|
||||||
"_spec": "1.1.0",
|
|
||||||
"_where": "C:\\dev\\repos\\actions\\setup-dotnet",
|
|
||||||
"author": {
|
|
||||||
"name": "Amit Gupta",
|
|
||||||
"url": "https://github.com/amitguptagwl"
|
|
||||||
},
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/nimndata/nimnjs-schema-builder/issues"
|
|
||||||
},
|
|
||||||
"description": "Build schema from JS object or JSON to feed into nimnjs",
|
|
||||||
"devDependencies": {
|
|
||||||
"browserify": "^16.1.0"
|
|
||||||
},
|
|
||||||
"homepage": "https://github.com/nimndata/nimnjs-schema-builder#readme",
|
|
||||||
"keywords": [
|
|
||||||
"nimn",
|
|
||||||
"nimnjs",
|
|
||||||
"builder",
|
|
||||||
"schema"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
|
||||||
"main": "builder.js",
|
|
||||||
"name": "nimn_schema_builder",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git+https://github.com/nimndata/nimnjs-schema-builder.git"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"bundle": "browserify builder.js -s nimn-schema-builder -o dist/nimn-schema-builder.js"
|
|
||||||
},
|
|
||||||
"version": "1.1.0"
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
{
|
|
||||||
"version": "0.2.0",
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"type": "node",
|
|
||||||
"request": "launch",
|
|
||||||
"name": "Jasmine Tests",
|
|
||||||
"program": "${workspaceFolder}/node_modules/jasmine/bin/jasmine.js",
|
|
||||||
"args": [
|
|
||||||
"${workspaceFolder}/test/encode_test.js"
|
|
||||||
],
|
|
||||||
"internalConsoleOptions": "openOnSessionStart"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
## Thanks
|
|
||||||
I would like to thank you for your valuable time and effort and applogies if this PR is rejected due to any reason.
|
|
||||||
|
|
||||||
Aim: Implementing Nimn specification so that Js object can be converted to nimn format.
|
|
||||||
|
|
||||||
### DoD
|
|
||||||
Here is the check list to publish any change
|
|
||||||
|
|
||||||
* Changes are not half implemented due to the library limitation or any other reason.
|
|
||||||
* Changes are well discussed by raising github issue. So they are well known by other contributers and users
|
|
||||||
* Echoing the above point. The purpose / goal for the PR should be mentioned in the description.
|
|
||||||
* Multiple unrelated changes should not be clubbed in single PR.
|
|
||||||
* If you are adding any dependency (specially if it is not the dev dependency) please check that
|
|
||||||
* it is not dependent on other language packages like c/c++
|
|
||||||
* the package is not very old or very new, discontinued, has any vulnerability etc.
|
|
||||||
* please check the performance and size of package
|
|
||||||
* please check alternate available options
|
|
||||||
* Please write tests for the new changes
|
|
||||||
* Don't forget to write tests for negative cases
|
|
||||||
* Don't comment existing test case.
|
|
||||||
|
|
||||||
Note that publishing changes or accepting any PR may take time. So please keep patience.
|
|
||||||
|
|
||||||
### Guidelines for first time contributors
|
|
||||||
|
|
||||||
* https://github.com/Roshanjossey/first-contributions
|
|
|
@ -1,21 +0,0 @@
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2018 nimndata
|
|
||||||
|
|
||||||
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.
|
|
|
@ -1,109 +0,0 @@
|
||||||
# nimnjs-node
|
|
||||||
JS implementation of nimn specification. Highly Compressed JS object/JSON. 60% or more compressed than JSON, 40% or more compressed than msgpack
|
|
||||||
|
|
||||||
[![Known Vulnerabilities](https://snyk.io/test/github/nimndata/nimnjs-node//badge.svg)](https://snyk.io/test/github/nimndata/nimnjs-node/)
|
|
||||||
[![Travis ci Build Status](https://travis-ci.org/nimndata/nimnjs-node.svg?branch=master)](https://travis-ci.org/nimndata/nimnjs-node/)
|
|
||||||
[![Coverage Status](https://coveralls.io/repos/github/nimndata/nimnjs-node/badge.svg?branch=master)](https://coveralls.io/github/nimndata/nimnjs-node/?branch=master)
|
|
||||||
[<img src="https://img.shields.io/badge/Try-me-blue.svg?colorA=FFA500&colorB=0000FF" alt="Try me"/>](https://nimndata.github.io/nimnjs-node/)
|
|
||||||
|
|
||||||
<a href="https://www.patreon.com/bePatron?u=9531404" data-patreon-widget-type="become-patron-button"><img src="https://c5.patreon.com/external/logo/become_a_patron_button.png" alt="Become a Patron!" width="200" /></a>
|
|
||||||
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=KQJAX48SPUKNC"> <img src="https://www.paypalobjects.com/webstatic/en_US/btn/btn_donate_92x26.png" alt="Stubmatic donate button"/></a>
|
|
||||||
|
|
||||||
<img align="right" src="static/img/nimnjs-logo.png" />
|
|
||||||
|
|
||||||
## Introduction
|
|
||||||
NIMN JS can parse JS object to nimn data and vice versa. See Nimn [specification](https://github.com/nimndata/spec) for more detail.
|
|
||||||
|
|
||||||
## Usages
|
|
||||||
First install or add to your npm package
|
|
||||||
```
|
|
||||||
$npm install nimnjs
|
|
||||||
```
|
|
||||||
|
|
||||||
```js
|
|
||||||
var nimn = require("nimnjs");
|
|
||||||
|
|
||||||
var schema = {
|
|
||||||
"name": "string",
|
|
||||||
"age": "number",
|
|
||||||
"human": "boolean",
|
|
||||||
"projects": [{
|
|
||||||
"name": "string",
|
|
||||||
"decription": "string"
|
|
||||||
}]
|
|
||||||
}
|
|
||||||
|
|
||||||
var nimnInstance = new nimn();
|
|
||||||
nimnInstance.addSchema(schema);
|
|
||||||
|
|
||||||
var data = {
|
|
||||||
"name" : "amit",
|
|
||||||
"age" : 32,
|
|
||||||
"human" : true,
|
|
||||||
"projects" : [
|
|
||||||
{
|
|
||||||
"name": "some",
|
|
||||||
"decription" : "some long description"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
var result = nimnInstance.encode(data);//Æamitº32ÙÇÆsomeºsome long description
|
|
||||||
result = nimnInstance.decode(result);
|
|
||||||
expect(result).toEqual(data);
|
|
||||||
```
|
|
||||||
|
|
||||||
For date compression
|
|
||||||
```js
|
|
||||||
var nimnDateparser = require("nimn-date-parser");
|
|
||||||
//generate schema and data
|
|
||||||
var nimnInstance = new nimn();
|
|
||||||
nimnInstance.addDataHandler("date",function(val){
|
|
||||||
return nimnDateparser.parse(val,true,true,true)
|
|
||||||
},function(val){
|
|
||||||
return nimnDateparser.parseBack(val,true,true,true)
|
|
||||||
});
|
|
||||||
nimnInstance.addSchema(schema); //add after adding all data handlers
|
|
||||||
|
|
||||||
var nimndata = nimnInstance.encode(data);
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
Encode enum type
|
|
||||||
```js
|
|
||||||
var nimnInstance = new nimn();
|
|
||||||
nimnInstance.addDataHandler("status",null,null,{
|
|
||||||
"M" : "Married",
|
|
||||||
"S" : "Single"
|
|
||||||
});
|
|
||||||
nimnInstance.addSchema(schema); //add after adding all data handlers
|
|
||||||
```
|
|
||||||
|
|
||||||
Just mark a data type
|
|
||||||
```js
|
|
||||||
var nimnInstance = new nimn();
|
|
||||||
nimnInstance.addDataHandler("image");
|
|
||||||
nimnInstance.addSchema(schema); //add after adding all data handlers
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
Include [dist](dist/nimn.js) in your HTML to use it in browser.
|
|
||||||
|
|
||||||
|
|
||||||
Check the [demo](https://nimndata.github.io/nimnjs-node/) for instant use. It generates schema automatically with the help of [schema builder](https://github.com/nimndata/nimnjs-schema-builder) when sample json is provided.
|
|
||||||
|
|
||||||
|
|
||||||
## Support
|
|
||||||
I need your expert advice, and contribution to grow nimn (निम्न) so that it can support all mazor languages. Please join the [official organization](https://github.com/nimndata) on github to support it. And ask your friends, and colleagues to give it a try. It can not only save bandwidth but speed up communication, search and much more.
|
|
||||||
|
|
||||||
|
|
||||||
### Worth to mention
|
|
||||||
|
|
||||||
- **[imglab](https://github.com/NaturalIntelligence/imglab)** : Web based tool to label images for object. So that they can be used to train dlib or other object detectors. You can integrate 3rd party libraries for fast labeling.
|
|
||||||
- **[अनुमार्गक (anumargak)](https://github.com/NaturalIntelligence/anumargak)** : The fastest router for node web servers.
|
|
||||||
|
|
||||||
- [Stubmatic](https://github.com/NaturalIntelligence/Stubmatic) : A stub server to mock behaviour of HTTP(s) / REST / SOAP services.
|
|
||||||
- **[fastify-xml-body-parser](https://github.com/NaturalIntelligence/fastify-xml-body-parser/)** : Fastify plugin / module to parse XML payload / body into JS object using fast-xml-parser.
|
|
||||||
- [fast-lorem-ipsum](https://github.com/amitguptagwl/fast-lorem-ipsum) : Generate lorem ipsum words, sentences, paragraph very quickly.
|
|
||||||
- [Grapes](https://github.com/amitguptagwl/grapes) : Flexible Regular expression engine which can be applied on char stream. (under development)
|
|
||||||
- [fast XML Parser](https://github.com/amitguptagwl/fast-xml-parser) : Fastest pure js XML parser for xml to js/json and vice versa. And XML validation.
|
|
|
@ -1,76 +0,0 @@
|
||||||
{
|
|
||||||
"_args": [
|
|
||||||
[
|
|
||||||
"nimnjs@1.3.2",
|
|
||||||
"C:\\dev\\repos\\actions\\setup-dotnet"
|
|
||||||
]
|
|
||||||
],
|
|
||||||
"_from": "nimnjs@1.3.2",
|
|
||||||
"_id": "nimnjs@1.3.2",
|
|
||||||
"_inBundle": false,
|
|
||||||
"_integrity": "sha512-TIOtI4iqkQrUM1tiM76AtTQem0c7e56SkDZ7sj1d1MfUsqRcq2ZWQvej/O+HBTZV7u/VKnwlKTDugK/75IRPPw==",
|
|
||||||
"_location": "/nimnjs",
|
|
||||||
"_phantomChildren": {},
|
|
||||||
"_requested": {
|
|
||||||
"type": "version",
|
|
||||||
"registry": true,
|
|
||||||
"raw": "nimnjs@1.3.2",
|
|
||||||
"name": "nimnjs",
|
|
||||||
"escapedName": "nimnjs",
|
|
||||||
"rawSpec": "1.3.2",
|
|
||||||
"saveSpec": null,
|
|
||||||
"fetchSpec": "1.3.2"
|
|
||||||
},
|
|
||||||
"_requiredBy": [
|
|
||||||
"/fast-xml-parser"
|
|
||||||
],
|
|
||||||
"_resolved": "https://registry.npmjs.org/nimnjs/-/nimnjs-1.3.2.tgz",
|
|
||||||
"_spec": "1.3.2",
|
|
||||||
"_where": "C:\\dev\\repos\\actions\\setup-dotnet",
|
|
||||||
"author": {
|
|
||||||
"name": "Amit Gupta",
|
|
||||||
"url": "https://github.com/amitguptagwl"
|
|
||||||
},
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/nimndata/nimnjs-node/issues"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"nimn-date-parser": "^1.0.0",
|
|
||||||
"nimn_schema_builder": "^1.0.0"
|
|
||||||
},
|
|
||||||
"description": "Schema aware compression of JS object/JSON data. 60% more compressed than json",
|
|
||||||
"devDependencies": {
|
|
||||||
"benchmark": "^2.1.4",
|
|
||||||
"browserify": "^15.1.0",
|
|
||||||
"cbor": "^4.0.0",
|
|
||||||
"istanbul": "^0.4.5",
|
|
||||||
"jasmine": "^3.0.0",
|
|
||||||
"jasmine-core": "^2.99.1",
|
|
||||||
"msgpack": "^1.0.2",
|
|
||||||
"notepack.io": "^2.1.2"
|
|
||||||
},
|
|
||||||
"homepage": "https://github.com/nimndata/nimnjs-node",
|
|
||||||
"keywords": [
|
|
||||||
"nimn",
|
|
||||||
"nimnjs",
|
|
||||||
"json",
|
|
||||||
"compress",
|
|
||||||
"parse",
|
|
||||||
"format",
|
|
||||||
"msgpack"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
|
||||||
"main": "src/nimn.js",
|
|
||||||
"name": "nimnjs",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git+https://github.com/nimndata/nimnjs-node.git"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"bundle": "browserify src/nimn.js -s nimn -o dist/nimn.js",
|
|
||||||
"coverage": "istanbul cover -x \"tests/*test.js\" jasmine tests/*test.js;",
|
|
||||||
"coverage:check": "istanbul check-coverage --branch 90 --statement 90",
|
|
||||||
"test": "jasmine tests/*test.js"
|
|
||||||
},
|
|
||||||
"version": "1.3.2"
|
|
||||||
}
|
|
|
@ -1,63 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {string} dataType
|
|
||||||
* @param {function} parse
|
|
||||||
* @param {function} parseBack
|
|
||||||
* @param {object} charset
|
|
||||||
* @param {boolean} treatAsUnique
|
|
||||||
*/
|
|
||||||
function DataHandler(dataType, /* parse, parseBack, */ charset,treatAsUnique){
|
|
||||||
this.dataType = dataType;
|
|
||||||
//parse || (this.parse = parse);
|
|
||||||
//parseBack || (this.parseBack = parseBack);
|
|
||||||
if(charset){
|
|
||||||
//this.hasFixedInstances = true;
|
|
||||||
this.char2val = charset;
|
|
||||||
this.val2char = {};
|
|
||||||
var keys = Object.keys(charset);
|
|
||||||
for(var i in keys){
|
|
||||||
var val = charset[keys[i]];
|
|
||||||
this.val2char[val] = keys[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
this.charcodes = Object.keys(charset);
|
|
||||||
}
|
|
||||||
if(treatAsUnique){
|
|
||||||
this.hasFixedInstances = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//this.treatAsUnique = treatAsUnique;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataHandler.prototype.parse = function(a){
|
|
||||||
if(this.char2val){
|
|
||||||
return this.getCharCodeFor(a);
|
|
||||||
}else{
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DataHandler.prototype.parseBack = function(a){
|
|
||||||
if(this.char2val){
|
|
||||||
return this.getValueOf(a);
|
|
||||||
}else{
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* returns an array of supported characters or empty array when it supportes dynamic data
|
|
||||||
*/
|
|
||||||
DataHandler.prototype.getCharCodes =function(){
|
|
||||||
return this.charcodes;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataHandler.prototype.getValueOf =function(chCode){
|
|
||||||
return this.char2val[chCode];
|
|
||||||
}
|
|
||||||
|
|
||||||
DataHandler.prototype.getCharCodeFor =function(value){
|
|
||||||
return this.val2char[value];
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = DataHandler;
|
|
|
@ -1,40 +0,0 @@
|
||||||
var char = require("./util").char;
|
|
||||||
|
|
||||||
|
|
||||||
/* 176-178
|
|
||||||
180-190
|
|
||||||
198-208
|
|
||||||
219-223
|
|
||||||
*/
|
|
||||||
|
|
||||||
const chars= {
|
|
||||||
nilChar : char(176),
|
|
||||||
missingChar : char(201),
|
|
||||||
nilPremitive : char(175),
|
|
||||||
missingPremitive : char(200),
|
|
||||||
|
|
||||||
emptyChar : char(178),
|
|
||||||
emptyValue: char(177),//empty Premitive
|
|
||||||
|
|
||||||
boundryChar : char(179),
|
|
||||||
|
|
||||||
objStart: char(198),
|
|
||||||
arrStart: char(204),
|
|
||||||
arrayEnd: char(185),
|
|
||||||
}
|
|
||||||
|
|
||||||
const charsArr = [
|
|
||||||
chars.nilChar ,
|
|
||||||
chars.nilPremitive,
|
|
||||||
chars.missingChar,
|
|
||||||
chars.missingPremitive,
|
|
||||||
chars.boundryChar ,
|
|
||||||
chars.emptyChar,
|
|
||||||
chars.emptyValue,
|
|
||||||
chars.arrayEnd,
|
|
||||||
chars.objStart,
|
|
||||||
chars.arrStart
|
|
||||||
]
|
|
||||||
|
|
||||||
exports.chars = chars;
|
|
||||||
exports.charsArr = charsArr;
|
|
|
@ -1,108 +0,0 @@
|
||||||
var chars = require("./chars").chars;
|
|
||||||
|
|
||||||
decoder.prototype._d = function(schema){
|
|
||||||
if(ifNil(this.currentChar())){
|
|
||||||
this.index++;
|
|
||||||
return null;
|
|
||||||
}else if(ifMissing(this.currentChar())){
|
|
||||||
this.index++;
|
|
||||||
return undefined;
|
|
||||||
}else if(typeof schema.type === "string"){//premitive
|
|
||||||
return this.readPremitiveValue(schema);
|
|
||||||
}else if(Array.isArray(schema)){
|
|
||||||
if(this.currentChar() === chars.emptyChar){
|
|
||||||
this.index++;
|
|
||||||
return [];
|
|
||||||
}else if(this.currentChar() !== chars.arrStart){
|
|
||||||
throw Error("Parsing error: Array start char was expected");
|
|
||||||
}else{
|
|
||||||
this.index++;//skip array start char
|
|
||||||
var item = schema[0];
|
|
||||||
var obj = []
|
|
||||||
do{
|
|
||||||
var r = this._d(item) ;
|
|
||||||
if(r !== undefined){
|
|
||||||
obj.push(r);
|
|
||||||
}
|
|
||||||
}while(this.dataToDecode[this.index] !== chars.arrayEnd);
|
|
||||||
++this.index;
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
}else{//object
|
|
||||||
if(this.currentChar() === chars.emptyChar){
|
|
||||||
this.index++;
|
|
||||||
return {};
|
|
||||||
}else if(this.currentChar() !== chars.objStart){
|
|
||||||
throw Error("Parsing error: Object start char was expected : " + this.currentChar());
|
|
||||||
}else{
|
|
||||||
this.index++;//skip object start char
|
|
||||||
var keys = Object.keys(schema);
|
|
||||||
var len = keys.length;
|
|
||||||
var obj = {};
|
|
||||||
for(var i=0; i< len; i++){
|
|
||||||
|
|
||||||
var r = this._d(schema[keys[i]]) ;
|
|
||||||
if(r !== undefined){
|
|
||||||
obj[keys[i]] = r;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function ifNil(ch){
|
|
||||||
return ch === chars.nilChar || ch === chars.nilPremitive;
|
|
||||||
}
|
|
||||||
|
|
||||||
function ifMissing(ch){
|
|
||||||
return ch === chars.missingChar || ch === chars.missingPremitive;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* returns character index pointing to
|
|
||||||
*/
|
|
||||||
decoder.prototype.currentChar = function(){
|
|
||||||
return this.dataToDecode[this.index];
|
|
||||||
}
|
|
||||||
|
|
||||||
decoder.prototype.readPremitiveValue = function(schemaOfCurrentKey){
|
|
||||||
var val = this.readFieldValue(schemaOfCurrentKey);
|
|
||||||
if(this.currentChar() === chars.boundryChar) this.index++;
|
|
||||||
var dh = this.dataHandlers[schemaOfCurrentKey.type];
|
|
||||||
return dh.parseBack(val);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Read characters until app supported char is found
|
|
||||||
*/
|
|
||||||
decoder.prototype.readFieldValue = function(schemaOfCurrentKey){
|
|
||||||
if(schemaOfCurrentKey.readUntil){
|
|
||||||
if(this.currentChar() === chars.emptyValue){
|
|
||||||
this.index++;
|
|
||||||
return "";
|
|
||||||
}else{
|
|
||||||
var until = schemaOfCurrentKey.readUntil;
|
|
||||||
var len = this.dataToDecode.length;
|
|
||||||
var start = this.index;
|
|
||||||
|
|
||||||
for(;this.index < len && until.indexOf(this.currentChar()) === -1;this.index++);
|
|
||||||
return this.dataToDecode.substr(start, this.index-start);
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
return this.dataToDecode[this.index++];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
decoder.prototype.decode = function(objStr){
|
|
||||||
this.index= 0;
|
|
||||||
if(!objStr || typeof objStr !== "string" || objStr.length === 0) throw Error("input should be a valid string");
|
|
||||||
this.dataToDecode = objStr;
|
|
||||||
return this._d(this.schema);
|
|
||||||
}
|
|
||||||
|
|
||||||
function decoder(schema,dataHandlers){
|
|
||||||
this.schema = schema;
|
|
||||||
this.dataHandlers = dataHandlers;
|
|
||||||
}
|
|
||||||
module.exports = decoder;
|
|
|
@ -1,89 +0,0 @@
|
||||||
var chars = require("./chars").chars;
|
|
||||||
var appCharsArr = require("./chars").charsArr;
|
|
||||||
|
|
||||||
Encoder.prototype._e = function(jObj,e_schema){
|
|
||||||
if(typeof e_schema.type === "string"){//premitive
|
|
||||||
return this.getValue(jObj,e_schema.type);
|
|
||||||
}else{
|
|
||||||
var hasValidData = hasData(jObj);
|
|
||||||
if(hasValidData === true){
|
|
||||||
var str = "";
|
|
||||||
if(Array.isArray(e_schema)){
|
|
||||||
str += chars.arrStart;
|
|
||||||
var itemSchema = e_schema[0];
|
|
||||||
//var itemSchemaType = itemSchema;
|
|
||||||
var arr_len = jObj.length;
|
|
||||||
for(var arr_i=0;arr_i < arr_len;arr_i++){
|
|
||||||
var r = this._e(jObj[arr_i],itemSchema) ;
|
|
||||||
str = this.processValue(str,r);
|
|
||||||
}
|
|
||||||
str += chars.arrayEnd;//indicates that next item is not array item
|
|
||||||
}else{//object
|
|
||||||
str += chars.objStart;
|
|
||||||
var keys = Object.keys(e_schema);
|
|
||||||
for(var i in keys){
|
|
||||||
var key = keys[i];
|
|
||||||
var r = this._e(jObj[key],e_schema[key]) ;
|
|
||||||
str = this.processValue(str,r);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return str;
|
|
||||||
}else{
|
|
||||||
return hasValidData;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Encoder.prototype.processValue= function(str,r){
|
|
||||||
if(!this.isAppChar(r[0]) && !this.isAppChar(str[str.length -1])){
|
|
||||||
str += chars.boundryChar;
|
|
||||||
}
|
|
||||||
return str + r;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {*} a
|
|
||||||
* @param {*} type
|
|
||||||
* @return {string} return either the parsed value or a special char representing the value
|
|
||||||
*/
|
|
||||||
Encoder.prototype.getValue= function(a,type){
|
|
||||||
switch(a){
|
|
||||||
case undefined: return chars.missingPremitive;
|
|
||||||
case null: return chars.nilPremitive;
|
|
||||||
case "": return chars.emptyValue;
|
|
||||||
default: return this.dataHandlers[type].parse(a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the given object is empty, null, or undefined. Returns true otherwise.
|
|
||||||
* @param {*} jObj
|
|
||||||
*/
|
|
||||||
function hasData(jObj){
|
|
||||||
if(jObj === undefined) return chars.missingChar;
|
|
||||||
else if(jObj === null) return chars.nilChar;
|
|
||||||
else if( jObj.length === 0 || Object.keys(jObj).length === 0){
|
|
||||||
return chars.emptyChar;
|
|
||||||
}else{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Encoder.prototype.isAppChar = function(ch){
|
|
||||||
return this.handledChars.indexOf(ch) !== -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
Encoder.prototype.encode = function(jObj){
|
|
||||||
return this._e(jObj,this.schema);
|
|
||||||
}
|
|
||||||
|
|
||||||
function Encoder(schema,dHandlers, charArr){
|
|
||||||
this.dataHandlers = dHandlers;
|
|
||||||
this.handledChars = appCharsArr.slice();
|
|
||||||
this.handledChars = this.handledChars.concat(charArr);
|
|
||||||
|
|
||||||
this.schema = schema;
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = Encoder;
|
|
|
@ -1,27 +0,0 @@
|
||||||
|
|
||||||
/**
|
|
||||||
* Verify if all the datahandlers are added given in schema.
|
|
||||||
* @param {*} schema
|
|
||||||
* @param {*} datahandlers
|
|
||||||
*/
|
|
||||||
var validateSchema = function(schema,datahandlers){
|
|
||||||
if(Array.isArray(schema)){
|
|
||||||
validateSchema(schema[0],datahandlers);
|
|
||||||
}else if(typeof schema === "object"){
|
|
||||||
var keys = Object.keys(schema);
|
|
||||||
var len = keys.length;
|
|
||||||
|
|
||||||
for(var i=0; i< len; i++){
|
|
||||||
var key = keys[i];
|
|
||||||
var nextKey = keys[i+1];
|
|
||||||
|
|
||||||
validateSchema(schema[key],datahandlers);
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
if(!datahandlers[schema]){
|
|
||||||
throw Error("You've forgot to add data handler for " + schema)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.validateSchema = validateSchema;
|
|
|
@ -1,95 +0,0 @@
|
||||||
var boolean = require("./parsers/boolean");
|
|
||||||
var numParser = require("./parsers/number");
|
|
||||||
var chars = require("./chars").chars;
|
|
||||||
var appCharsArr = require("./chars").charsArr;
|
|
||||||
var helper = require("./helper");
|
|
||||||
var schemaMarker = require("./schemaMarker");
|
|
||||||
var Decoder = require("./decoder");
|
|
||||||
var Encoder = require("./encoder");
|
|
||||||
var DataHandler = require("./DataHandler");
|
|
||||||
|
|
||||||
function nimn() {
|
|
||||||
this.handledChars = [];//appCharsArr.slice();
|
|
||||||
this.dataHandlers = {};
|
|
||||||
this.addDataHandler("boolean",null,null,boolean.charset,true);
|
|
||||||
//this.addDataHandler("boolean",boolean.parse,boolean.parseBack,boolean.charset,true);
|
|
||||||
this.addDataHandler("string");
|
|
||||||
this.addDataHandler("number",numParser.parse, numParser.parseBack);
|
|
||||||
this.addDataHandler("date");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method should be called once all the data handlers are registered.
|
|
||||||
* It updates internal schema based on given schema.
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* {
|
|
||||||
* "field1" : "string",
|
|
||||||
* "field2" : "date",
|
|
||||||
* "field3" : {
|
|
||||||
* "field4" : "number"
|
|
||||||
* },
|
|
||||||
* "field5" : [ "image"],
|
|
||||||
* "field6" : [{ "field7" : "boolean"}]
|
|
||||||
* }
|
|
||||||
* @param {*} schema
|
|
||||||
* @returns {void}
|
|
||||||
*/
|
|
||||||
nimn.prototype.addSchema= function(schema){
|
|
||||||
this.schema = JSON.parse(JSON.stringify(schema));
|
|
||||||
new schemaMarker(this.dataHandlers).markNextPossibleChars(this.schema);
|
|
||||||
//helper.validateSchema(schema,this.dataHandlers);
|
|
||||||
this.encoder = new Encoder(this.schema,this.dataHandlers,this.handledChars);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* You can update existnig handler od add new using this method.
|
|
||||||
* "string", "number", "boolean", and "date" are handled by default.
|
|
||||||
*
|
|
||||||
* charset should be set when given type should be treated as enum or fixed set of values
|
|
||||||
* @example
|
|
||||||
* //to map
|
|
||||||
* nimnInstance.addDataHandler("status",null,null,{ "R": "running", "S" : "stop", "I", "ready to run"},false)
|
|
||||||
* @example
|
|
||||||
* //just for identification
|
|
||||||
* nimnInstance.addDataHandler("image");
|
|
||||||
* @example
|
|
||||||
* //to compress more
|
|
||||||
* nimnInstance.addDataHandler("date", datecompressor.parse, datecompressor.parseBack);
|
|
||||||
* @param {string} type
|
|
||||||
* @param {function} parseWith - will be used by encoder to encode given type's value
|
|
||||||
* @param {function} parseBackWith - will be used by decoder to decode given type's value
|
|
||||||
* @param {Object} charset - map of charset and fixed values
|
|
||||||
* @param {boolean} [noBoundaryChar=false] - if true encoder will not separate given type's value with boundary char
|
|
||||||
*/
|
|
||||||
nimn.prototype.addDataHandler = function(type,parseWith,parseBackWith,charset,noBoundaryChar){
|
|
||||||
var dataHandler = new DataHandler(type,/* parseWith,parseBackWith, */charset,noBoundaryChar);
|
|
||||||
if(parseWith) dataHandler.parse = parseWith;
|
|
||||||
if(parseBackWith) dataHandler.parseBack = parseBackWith;
|
|
||||||
|
|
||||||
//unque charset don't require boundary char. Hence check them is they are already added
|
|
||||||
if(noBoundaryChar && charset){
|
|
||||||
var keys = Object.keys(charset);
|
|
||||||
|
|
||||||
for(var k in keys){
|
|
||||||
var ch = keys[k];
|
|
||||||
if(this.handledChars.indexOf(ch) !== -1 || appCharsArr.indexOf(ch) !== -1){
|
|
||||||
throw Error("DataHandler Error: "+ ch +" is not allowed. Either it is reserved or being used by another data handler");
|
|
||||||
}else{
|
|
||||||
this.handledChars.push(ch);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.dataHandlers[type] = dataHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
nimn.prototype.encode = function(jObj){
|
|
||||||
return this.encoder.encode(jObj);
|
|
||||||
}
|
|
||||||
|
|
||||||
nimn.prototype.decode= function(encodedVal){
|
|
||||||
var decoder = new Decoder(this.schema,this.dataHandlers);
|
|
||||||
return decoder.decode(encodedVal);
|
|
||||||
}
|
|
||||||
module.exports = nimn;
|
|
|
@ -1,11 +0,0 @@
|
||||||
var chars = require("../chars").chars;
|
|
||||||
var char = require("../util").char;
|
|
||||||
|
|
||||||
var yes = char(181);
|
|
||||||
var no = char(183);
|
|
||||||
|
|
||||||
booleanCharset = {};
|
|
||||||
booleanCharset[yes] = true;
|
|
||||||
booleanCharset[no] = false;
|
|
||||||
|
|
||||||
exports.charset = booleanCharset;
|
|
|
@ -1,18 +0,0 @@
|
||||||
var chars = require("../chars").chars;
|
|
||||||
|
|
||||||
function parse(val){
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseBack(val){
|
|
||||||
if(val.indexOf(".") !== -1){
|
|
||||||
val = Number.parseFloat(val);
|
|
||||||
}else{
|
|
||||||
val = Number.parseInt(val,10);
|
|
||||||
}
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
exports.parse = parse;
|
|
||||||
exports.parseBack = parseBack;
|
|
|
@ -1,125 +0,0 @@
|
||||||
var chars = require("./chars").chars;
|
|
||||||
var appCharsArr = require("./chars").charsArr;
|
|
||||||
|
|
||||||
schemaMarker.prototype._m = function(schema){
|
|
||||||
if(Array.isArray(schema)){
|
|
||||||
if(typeof schema[0] === "string"){
|
|
||||||
var itemSchema = {
|
|
||||||
type : schema[0]
|
|
||||||
}
|
|
||||||
this.setReadUntil(itemSchema, schema[0]);
|
|
||||||
schema[0] = itemSchema;//make it object so a function cant set it's value
|
|
||||||
if(schema[0].readUntil)
|
|
||||||
schema[0].readUntil.push(chars.arrayEnd);
|
|
||||||
}else{
|
|
||||||
this._m(schema[0]);//let's object portion handle it
|
|
||||||
var lastMostKey = getLastMostKey(schema[0]);
|
|
||||||
if(lastMostKey){
|
|
||||||
this.setReadUntil(lastMostKey, schema[0]);
|
|
||||||
if(lastMostKey.readUntil)
|
|
||||||
lastMostKey.readUntil.push(chars.arrayEnd);
|
|
||||||
}else{
|
|
||||||
//lastmostkey was set as it was under an array
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}else if(typeof schema === "object"){
|
|
||||||
var keys = Object.keys(schema);
|
|
||||||
var len = keys.length;
|
|
||||||
|
|
||||||
for(var i=0; i< len; i++){
|
|
||||||
var key = keys[i];
|
|
||||||
var nextKey = keys[i+1];
|
|
||||||
|
|
||||||
this._m(schema[key]);
|
|
||||||
if(Array.isArray(schema[key])) continue;
|
|
||||||
else if(nextKey){
|
|
||||||
if(typeof schema[key] !== "string"){//not an object
|
|
||||||
var lastMostKey = getLastMostKey(schema[key]);
|
|
||||||
if(lastMostKey){
|
|
||||||
this.setReadUntil(lastMostKey,schema[nextKey]);
|
|
||||||
}else{
|
|
||||||
//lastmostkey was set as it was under an array
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
var itemSchema = {
|
|
||||||
type : schema[key]
|
|
||||||
}
|
|
||||||
this.setReadUntil(itemSchema,schema[nextKey]);
|
|
||||||
schema[key] = itemSchema ;
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
if(typeof schema[key] === "object") continue;
|
|
||||||
schema[key] = {
|
|
||||||
type : schema[key]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
if(!this.dataHandlers[schema]){//handled
|
|
||||||
throw Error("You've forgot to add data handler for " + schema)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
schemaMarker.prototype.setReadUntil = function(current,next){
|
|
||||||
//status: R,S
|
|
||||||
if(this.dataHandlers[current.type].hasFixedInstances){
|
|
||||||
//if current char is set by user and need to be separated by boundary char
|
|
||||||
//then don't set readUntil, read current char
|
|
||||||
return ;
|
|
||||||
}else{
|
|
||||||
|
|
||||||
//return [chars.boundryChar, chars.missingPremitive, chars.nilPremitive];
|
|
||||||
if(Array.isArray(next)){
|
|
||||||
current.readUntil = [ chars.arrStart, chars.missingChar, chars.emptyChar, chars.nilChar];
|
|
||||||
}else if(typeof next === "object"){
|
|
||||||
current.readUntil = [ chars.objStart, chars.missingChar, chars.emptyChar, chars.nilChar];
|
|
||||||
}else{
|
|
||||||
if(this.dataHandlers[next] && this.dataHandlers[next].hasFixedInstances){//but need to be separated by boundary char
|
|
||||||
//status,boolean
|
|
||||||
current.readUntil = [chars.missingPremitive, chars.nilPremitive];
|
|
||||||
current.readUntil = current.readUntil.concat(this.dataHandlers[next].getCharCodes());
|
|
||||||
}else{
|
|
||||||
///status,age
|
|
||||||
current.readUntil = [chars.boundryChar, chars.emptyValue, chars.missingPremitive, chars.nilPremitive];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* obj can't be an array
|
|
||||||
* @param {*} obj
|
|
||||||
*/
|
|
||||||
function getLastMostKey(obj){
|
|
||||||
var lastProperty;
|
|
||||||
if(Array.isArray(obj)){
|
|
||||||
return;
|
|
||||||
}else{
|
|
||||||
var keys = Object.keys(obj);
|
|
||||||
lastProperty = obj[keys[keys.length-1]];
|
|
||||||
}
|
|
||||||
|
|
||||||
if(typeof lastProperty === "object" && !(lastProperty.type && typeof lastProperty.type === "string")){
|
|
||||||
return getLastMostKey(lastProperty);
|
|
||||||
}else{
|
|
||||||
return lastProperty;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
schemaMarker.prototype.markNextPossibleChars = function(schema){
|
|
||||||
this._m(schema);
|
|
||||||
if(!Array.isArray(schema)){
|
|
||||||
var lastMostKey = getLastMostKey(schema);
|
|
||||||
if(lastMostKey){
|
|
||||||
lastMostKey.readUntil = [chars.nilChar]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function schemaMarker(dataHandlers){
|
|
||||||
this.dataHandlers = dataHandlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = schemaMarker;
|
|
|
@ -1,30 +0,0 @@
|
||||||
/**
|
|
||||||
* converts a ASCII number into equivalant ASCII char
|
|
||||||
* @param {number} a
|
|
||||||
* @returns ASCII char
|
|
||||||
*/
|
|
||||||
var char = function (a){
|
|
||||||
return String.fromCharCode(a);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* return key of an object
|
|
||||||
* @param {*} obj
|
|
||||||
* @param {number} i
|
|
||||||
*/
|
|
||||||
/* function getKey(obj,i){
|
|
||||||
return obj[Object.keys(obj)[i]];
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* function indexOf(arr,searchedID) {
|
|
||||||
var arrayLen = arr.length;
|
|
||||||
var c = 0;
|
|
||||||
while (c < arrayLen) {
|
|
||||||
if (arr[c] === searchedID) return c;
|
|
||||||
c++;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
} */
|
|
||||||
exports.char = char;
|
|
||||||
//exports.indexOf = indexOf;
|
|
|
@ -1,5 +1,28 @@
|
||||||
# changes log
|
# changes log
|
||||||
|
|
||||||
|
## 6.2.0
|
||||||
|
|
||||||
|
* Coerce numbers to strings when passed to semver.coerce()
|
||||||
|
* Add `rtl` option to coerce from right to left
|
||||||
|
|
||||||
|
## 6.1.3
|
||||||
|
|
||||||
|
* Handle X-ranges properly in includePrerelease mode
|
||||||
|
|
||||||
|
## 6.1.2
|
||||||
|
|
||||||
|
* Do not throw when testing invalid version strings
|
||||||
|
|
||||||
|
## 6.1.1
|
||||||
|
|
||||||
|
* Add options support for semver.coerce()
|
||||||
|
* Handle undefined version passed to Range.test
|
||||||
|
|
||||||
|
## 6.1.0
|
||||||
|
|
||||||
|
* Add semver.compareBuild function
|
||||||
|
* Support `*` in semver.intersects
|
||||||
|
|
||||||
## 6.0
|
## 6.0
|
||||||
|
|
||||||
* Fix `intersects` logic.
|
* Fix `intersects` logic.
|
||||||
|
|
|
@ -60,6 +60,12 @@ Options:
|
||||||
Coerce a string into SemVer if possible
|
Coerce a string into SemVer if possible
|
||||||
(does not imply --loose)
|
(does not imply --loose)
|
||||||
|
|
||||||
|
--rtl
|
||||||
|
Coerce version strings right to left
|
||||||
|
|
||||||
|
--ltr
|
||||||
|
Coerce version strings left to right (default)
|
||||||
|
|
||||||
Program exits successfully if any valid version satisfies
|
Program exits successfully if any valid version satisfies
|
||||||
all supplied ranges, and prints all satisfying versions.
|
all supplied ranges, and prints all satisfying versions.
|
||||||
|
|
||||||
|
@ -399,19 +405,26 @@ range, use the `satisfies(version, range)` function.
|
||||||
|
|
||||||
### Coercion
|
### Coercion
|
||||||
|
|
||||||
* `coerce(version)`: Coerces a string to semver if possible
|
* `coerce(version, options)`: Coerces a string to semver if possible
|
||||||
|
|
||||||
This aims to provide a very forgiving translation of a non-semver
|
This aims to provide a very forgiving translation of a non-semver string to
|
||||||
string to semver. It looks for the first digit in a string, and
|
semver. It looks for the first digit in a string, and consumes all
|
||||||
consumes all remaining characters which satisfy at least a partial semver
|
remaining characters which satisfy at least a partial semver (e.g., `1`,
|
||||||
(e.g., `1`, `1.2`, `1.2.3`) up to the max permitted length (256 characters).
|
`1.2`, `1.2.3`) up to the max permitted length (256 characters). Longer
|
||||||
Longer versions are simply truncated (`4.6.3.9.2-alpha2` becomes `4.6.3`).
|
versions are simply truncated (`4.6.3.9.2-alpha2` becomes `4.6.3`). All
|
||||||
All surrounding text is simply ignored (`v3.4 replaces v3.3.1` becomes `3.4.0`).
|
surrounding text is simply ignored (`v3.4 replaces v3.3.1` becomes
|
||||||
Only text which lacks digits will fail coercion (`version one` is not valid).
|
`3.4.0`). Only text which lacks digits will fail coercion (`version one`
|
||||||
The maximum length for any semver component considered for coercion is 16 characters;
|
is not valid). The maximum length for any semver component considered for
|
||||||
longer components will be ignored (`10000000000000000.4.7.4` becomes `4.7.4`).
|
coercion is 16 characters; longer components will be ignored
|
||||||
The maximum value for any semver component is `Integer.MAX_SAFE_INTEGER || (2**53 - 1)`;
|
(`10000000000000000.4.7.4` becomes `4.7.4`). The maximum value for any
|
||||||
higher value components are invalid (`9999999999999999.4.7.4` is likely invalid).
|
semver component is `Integer.MAX_SAFE_INTEGER || (2**53 - 1)`; higher value
|
||||||
|
components are invalid (`9999999999999999.4.7.4` is likely invalid).
|
||||||
|
|
||||||
|
If the `options.rtl` flag is set, then `coerce` will return the right-most
|
||||||
|
coercible tuple that does not share an ending index with a longer coercible
|
||||||
|
tuple. For example, `1.2.3.4` will return `2.3.4` in rtl mode, not
|
||||||
|
`4.0.0`. `1.2.3/4` will return `4.0.0`, because the `4` is not a part of
|
||||||
|
any other overlapping SemVer tuple.
|
||||||
|
|
||||||
### Clean
|
### Clean
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,8 @@ var includePrerelease = false
|
||||||
|
|
||||||
var coerce = false
|
var coerce = false
|
||||||
|
|
||||||
|
var rtl = false
|
||||||
|
|
||||||
var identifier
|
var identifier
|
||||||
|
|
||||||
var semver = require('../semver')
|
var semver = require('../semver')
|
||||||
|
@ -71,6 +73,12 @@ function main () {
|
||||||
case '-c': case '--coerce':
|
case '-c': case '--coerce':
|
||||||
coerce = true
|
coerce = true
|
||||||
break
|
break
|
||||||
|
case '--rtl':
|
||||||
|
rtl = true
|
||||||
|
break
|
||||||
|
case '--ltr':
|
||||||
|
rtl = false
|
||||||
|
break
|
||||||
case '-h': case '--help': case '-?':
|
case '-h': case '--help': case '-?':
|
||||||
return help()
|
return help()
|
||||||
default:
|
default:
|
||||||
|
@ -79,10 +87,10 @@ function main () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var options = { loose: loose, includePrerelease: includePrerelease }
|
var options = { loose: loose, includePrerelease: includePrerelease, rtl: rtl }
|
||||||
|
|
||||||
versions = versions.map(function (v) {
|
versions = versions.map(function (v) {
|
||||||
return coerce ? (semver.coerce(v) || { version: v }).version : v
|
return coerce ? (semver.coerce(v, options) || { version: v }).version : v
|
||||||
}).filter(function (v) {
|
}).filter(function (v) {
|
||||||
return semver.valid(v)
|
return semver.valid(v)
|
||||||
})
|
})
|
||||||
|
@ -149,6 +157,12 @@ function help () {
|
||||||
' Coerce a string into SemVer if possible',
|
' Coerce a string into SemVer if possible',
|
||||||
' (does not imply --loose)',
|
' (does not imply --loose)',
|
||||||
'',
|
'',
|
||||||
|
'--rtl',
|
||||||
|
' Coerce version strings right to left',
|
||||||
|
'',
|
||||||
|
'--ltr',
|
||||||
|
' Coerce version strings left to right (default)',
|
||||||
|
'',
|
||||||
'Program exits successfully if any valid version satisfies',
|
'Program exits successfully if any valid version satisfies',
|
||||||
'all supplied ranges, and prints all satisfying versions.',
|
'all supplied ranges, and prints all satisfying versions.',
|
||||||
'',
|
'',
|
|
@ -1,43 +1,41 @@
|
||||||
{
|
{
|
||||||
"_args": [
|
"_from": "semver@6.3.0",
|
||||||
[
|
"_id": "semver@6.3.0",
|
||||||
"semver@6.1.1",
|
|
||||||
"C:\\dev\\repos\\actions\\setup-dotnet"
|
|
||||||
]
|
|
||||||
],
|
|
||||||
"_from": "semver@6.1.1",
|
|
||||||
"_id": "semver@6.1.1",
|
|
||||||
"_inBundle": false,
|
"_inBundle": false,
|
||||||
"_integrity": "sha512-rWYq2e5iYW+fFe/oPPtYJxYgjBm8sC4rmoGdUOgBB7VnwKt6HrL793l2voH1UlsyYZpJ4g0wfjnTEO1s1NP2eQ==",
|
"_integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
|
||||||
"_location": "/semver",
|
"_location": "/semver",
|
||||||
"_phantomChildren": {},
|
"_phantomChildren": {},
|
||||||
"_requested": {
|
"_requested": {
|
||||||
"type": "version",
|
"type": "version",
|
||||||
"registry": true,
|
"registry": true,
|
||||||
"raw": "semver@6.1.1",
|
"raw": "semver@6.3.0",
|
||||||
"name": "semver",
|
"name": "semver",
|
||||||
"escapedName": "semver",
|
"escapedName": "semver",
|
||||||
"rawSpec": "6.1.1",
|
"rawSpec": "6.3.0",
|
||||||
"saveSpec": null,
|
"saveSpec": null,
|
||||||
"fetchSpec": "6.1.1"
|
"fetchSpec": "6.3.0"
|
||||||
},
|
},
|
||||||
"_requiredBy": [
|
"_requiredBy": [
|
||||||
|
"#USER",
|
||||||
"/",
|
"/",
|
||||||
"/@actions/tool-cache",
|
"/@actions/tool-cache",
|
||||||
"/istanbul-lib-instrument"
|
"/istanbul-lib-instrument"
|
||||||
],
|
],
|
||||||
"_resolved": "https://registry.npmjs.org/semver/-/semver-6.1.1.tgz",
|
"_resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
|
||||||
"_spec": "6.1.1",
|
"_shasum": "ee0a64c8af5e8ceea67687b133761e1becbd1d3d",
|
||||||
"_where": "C:\\dev\\repos\\actions\\setup-dotnet",
|
"_spec": "semver@6.3.0",
|
||||||
|
"_where": "C:\\Users\\Stanley\\Projects\\GitHub\\setup-dotnet",
|
||||||
"bin": {
|
"bin": {
|
||||||
"semver": "./bin/semver"
|
"semver": "./bin/semver.js"
|
||||||
},
|
},
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/npm/node-semver/issues"
|
"url": "https://github.com/npm/node-semver/issues"
|
||||||
},
|
},
|
||||||
|
"bundleDependencies": false,
|
||||||
|
"deprecated": false,
|
||||||
"description": "The semantic version parser used by npm.",
|
"description": "The semantic version parser used by npm.",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"tap": "^14.1.6"
|
"tap": "^14.3.1"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"bin",
|
"bin",
|
||||||
|
@ -61,5 +59,5 @@
|
||||||
"tap": {
|
"tap": {
|
||||||
"check-coverage": true
|
"check-coverage": true
|
||||||
},
|
},
|
||||||
"version": "6.1.1"
|
"version": "6.3.0"
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,75 +29,80 @@ var MAX_SAFE_COMPONENT_LENGTH = 16
|
||||||
// The actual regexps go on exports.re
|
// The actual regexps go on exports.re
|
||||||
var re = exports.re = []
|
var re = exports.re = []
|
||||||
var src = exports.src = []
|
var src = exports.src = []
|
||||||
|
var t = exports.tokens = {}
|
||||||
var R = 0
|
var R = 0
|
||||||
|
|
||||||
|
function tok (n) {
|
||||||
|
t[n] = R++
|
||||||
|
}
|
||||||
|
|
||||||
// The following Regular Expressions can be used for tokenizing,
|
// The following Regular Expressions can be used for tokenizing,
|
||||||
// validating, and parsing SemVer version strings.
|
// validating, and parsing SemVer version strings.
|
||||||
|
|
||||||
// ## Numeric Identifier
|
// ## Numeric Identifier
|
||||||
// A single `0`, or a non-zero digit followed by zero or more digits.
|
// A single `0`, or a non-zero digit followed by zero or more digits.
|
||||||
|
|
||||||
var NUMERICIDENTIFIER = R++
|
tok('NUMERICIDENTIFIER')
|
||||||
src[NUMERICIDENTIFIER] = '0|[1-9]\\d*'
|
src[t.NUMERICIDENTIFIER] = '0|[1-9]\\d*'
|
||||||
var NUMERICIDENTIFIERLOOSE = R++
|
tok('NUMERICIDENTIFIERLOOSE')
|
||||||
src[NUMERICIDENTIFIERLOOSE] = '[0-9]+'
|
src[t.NUMERICIDENTIFIERLOOSE] = '[0-9]+'
|
||||||
|
|
||||||
// ## Non-numeric Identifier
|
// ## Non-numeric Identifier
|
||||||
// Zero or more digits, followed by a letter or hyphen, and then zero or
|
// Zero or more digits, followed by a letter or hyphen, and then zero or
|
||||||
// more letters, digits, or hyphens.
|
// more letters, digits, or hyphens.
|
||||||
|
|
||||||
var NONNUMERICIDENTIFIER = R++
|
tok('NONNUMERICIDENTIFIER')
|
||||||
src[NONNUMERICIDENTIFIER] = '\\d*[a-zA-Z-][a-zA-Z0-9-]*'
|
src[t.NONNUMERICIDENTIFIER] = '\\d*[a-zA-Z-][a-zA-Z0-9-]*'
|
||||||
|
|
||||||
// ## Main Version
|
// ## Main Version
|
||||||
// Three dot-separated numeric identifiers.
|
// Three dot-separated numeric identifiers.
|
||||||
|
|
||||||
var MAINVERSION = R++
|
tok('MAINVERSION')
|
||||||
src[MAINVERSION] = '(' + src[NUMERICIDENTIFIER] + ')\\.' +
|
src[t.MAINVERSION] = '(' + src[t.NUMERICIDENTIFIER] + ')\\.' +
|
||||||
'(' + src[NUMERICIDENTIFIER] + ')\\.' +
|
'(' + src[t.NUMERICIDENTIFIER] + ')\\.' +
|
||||||
'(' + src[NUMERICIDENTIFIER] + ')'
|
'(' + src[t.NUMERICIDENTIFIER] + ')'
|
||||||
|
|
||||||
var MAINVERSIONLOOSE = R++
|
tok('MAINVERSIONLOOSE')
|
||||||
src[MAINVERSIONLOOSE] = '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' +
|
src[t.MAINVERSIONLOOSE] = '(' + src[t.NUMERICIDENTIFIERLOOSE] + ')\\.' +
|
||||||
'(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' +
|
'(' + src[t.NUMERICIDENTIFIERLOOSE] + ')\\.' +
|
||||||
'(' + src[NUMERICIDENTIFIERLOOSE] + ')'
|
'(' + src[t.NUMERICIDENTIFIERLOOSE] + ')'
|
||||||
|
|
||||||
// ## Pre-release Version Identifier
|
// ## Pre-release Version Identifier
|
||||||
// A numeric identifier, or a non-numeric identifier.
|
// A numeric identifier, or a non-numeric identifier.
|
||||||
|
|
||||||
var PRERELEASEIDENTIFIER = R++
|
tok('PRERELEASEIDENTIFIER')
|
||||||
src[PRERELEASEIDENTIFIER] = '(?:' + src[NUMERICIDENTIFIER] +
|
src[t.PRERELEASEIDENTIFIER] = '(?:' + src[t.NUMERICIDENTIFIER] +
|
||||||
'|' + src[NONNUMERICIDENTIFIER] + ')'
|
'|' + src[t.NONNUMERICIDENTIFIER] + ')'
|
||||||
|
|
||||||
var PRERELEASEIDENTIFIERLOOSE = R++
|
tok('PRERELEASEIDENTIFIERLOOSE')
|
||||||
src[PRERELEASEIDENTIFIERLOOSE] = '(?:' + src[NUMERICIDENTIFIERLOOSE] +
|
src[t.PRERELEASEIDENTIFIERLOOSE] = '(?:' + src[t.NUMERICIDENTIFIERLOOSE] +
|
||||||
'|' + src[NONNUMERICIDENTIFIER] + ')'
|
'|' + src[t.NONNUMERICIDENTIFIER] + ')'
|
||||||
|
|
||||||
// ## Pre-release Version
|
// ## Pre-release Version
|
||||||
// Hyphen, followed by one or more dot-separated pre-release version
|
// Hyphen, followed by one or more dot-separated pre-release version
|
||||||
// identifiers.
|
// identifiers.
|
||||||
|
|
||||||
var PRERELEASE = R++
|
tok('PRERELEASE')
|
||||||
src[PRERELEASE] = '(?:-(' + src[PRERELEASEIDENTIFIER] +
|
src[t.PRERELEASE] = '(?:-(' + src[t.PRERELEASEIDENTIFIER] +
|
||||||
'(?:\\.' + src[PRERELEASEIDENTIFIER] + ')*))'
|
'(?:\\.' + src[t.PRERELEASEIDENTIFIER] + ')*))'
|
||||||
|
|
||||||
var PRERELEASELOOSE = R++
|
tok('PRERELEASELOOSE')
|
||||||
src[PRERELEASELOOSE] = '(?:-?(' + src[PRERELEASEIDENTIFIERLOOSE] +
|
src[t.PRERELEASELOOSE] = '(?:-?(' + src[t.PRERELEASEIDENTIFIERLOOSE] +
|
||||||
'(?:\\.' + src[PRERELEASEIDENTIFIERLOOSE] + ')*))'
|
'(?:\\.' + src[t.PRERELEASEIDENTIFIERLOOSE] + ')*))'
|
||||||
|
|
||||||
// ## Build Metadata Identifier
|
// ## Build Metadata Identifier
|
||||||
// Any combination of digits, letters, or hyphens.
|
// Any combination of digits, letters, or hyphens.
|
||||||
|
|
||||||
var BUILDIDENTIFIER = R++
|
tok('BUILDIDENTIFIER')
|
||||||
src[BUILDIDENTIFIER] = '[0-9A-Za-z-]+'
|
src[t.BUILDIDENTIFIER] = '[0-9A-Za-z-]+'
|
||||||
|
|
||||||
// ## Build Metadata
|
// ## Build Metadata
|
||||||
// Plus sign, followed by one or more period-separated build metadata
|
// Plus sign, followed by one or more period-separated build metadata
|
||||||
// identifiers.
|
// identifiers.
|
||||||
|
|
||||||
var BUILD = R++
|
tok('BUILD')
|
||||||
src[BUILD] = '(?:\\+(' + src[BUILDIDENTIFIER] +
|
src[t.BUILD] = '(?:\\+(' + src[t.BUILDIDENTIFIER] +
|
||||||
'(?:\\.' + src[BUILDIDENTIFIER] + ')*))'
|
'(?:\\.' + src[t.BUILDIDENTIFIER] + ')*))'
|
||||||
|
|
||||||
// ## Full Version String
|
// ## Full Version String
|
||||||
// A main version, followed optionally by a pre-release version and
|
// A main version, followed optionally by a pre-release version and
|
||||||
|
@ -108,129 +113,133 @@ src[BUILD] = '(?:\\+(' + src[BUILDIDENTIFIER] +
|
||||||
// capturing group, because it should not ever be used in version
|
// capturing group, because it should not ever be used in version
|
||||||
// comparison.
|
// comparison.
|
||||||
|
|
||||||
var FULL = R++
|
tok('FULL')
|
||||||
var FULLPLAIN = 'v?' + src[MAINVERSION] +
|
tok('FULLPLAIN')
|
||||||
src[PRERELEASE] + '?' +
|
src[t.FULLPLAIN] = 'v?' + src[t.MAINVERSION] +
|
||||||
src[BUILD] + '?'
|
src[t.PRERELEASE] + '?' +
|
||||||
|
src[t.BUILD] + '?'
|
||||||
|
|
||||||
src[FULL] = '^' + FULLPLAIN + '$'
|
src[t.FULL] = '^' + src[t.FULLPLAIN] + '$'
|
||||||
|
|
||||||
// like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
|
// like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
|
||||||
// also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
|
// also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
|
||||||
// common in the npm registry.
|
// common in the npm registry.
|
||||||
var LOOSEPLAIN = '[v=\\s]*' + src[MAINVERSIONLOOSE] +
|
tok('LOOSEPLAIN')
|
||||||
src[PRERELEASELOOSE] + '?' +
|
src[t.LOOSEPLAIN] = '[v=\\s]*' + src[t.MAINVERSIONLOOSE] +
|
||||||
src[BUILD] + '?'
|
src[t.PRERELEASELOOSE] + '?' +
|
||||||
|
src[t.BUILD] + '?'
|
||||||
|
|
||||||
var LOOSE = R++
|
tok('LOOSE')
|
||||||
src[LOOSE] = '^' + LOOSEPLAIN + '$'
|
src[t.LOOSE] = '^' + src[t.LOOSEPLAIN] + '$'
|
||||||
|
|
||||||
var GTLT = R++
|
tok('GTLT')
|
||||||
src[GTLT] = '((?:<|>)?=?)'
|
src[t.GTLT] = '((?:<|>)?=?)'
|
||||||
|
|
||||||
// Something like "2.*" or "1.2.x".
|
// Something like "2.*" or "1.2.x".
|
||||||
// Note that "x.x" is a valid xRange identifer, meaning "any version"
|
// Note that "x.x" is a valid xRange identifer, meaning "any version"
|
||||||
// Only the first item is strictly required.
|
// Only the first item is strictly required.
|
||||||
var XRANGEIDENTIFIERLOOSE = R++
|
tok('XRANGEIDENTIFIERLOOSE')
|
||||||
src[XRANGEIDENTIFIERLOOSE] = src[NUMERICIDENTIFIERLOOSE] + '|x|X|\\*'
|
src[t.XRANGEIDENTIFIERLOOSE] = src[t.NUMERICIDENTIFIERLOOSE] + '|x|X|\\*'
|
||||||
var XRANGEIDENTIFIER = R++
|
tok('XRANGEIDENTIFIER')
|
||||||
src[XRANGEIDENTIFIER] = src[NUMERICIDENTIFIER] + '|x|X|\\*'
|
src[t.XRANGEIDENTIFIER] = src[t.NUMERICIDENTIFIER] + '|x|X|\\*'
|
||||||
|
|
||||||
var XRANGEPLAIN = R++
|
tok('XRANGEPLAIN')
|
||||||
src[XRANGEPLAIN] = '[v=\\s]*(' + src[XRANGEIDENTIFIER] + ')' +
|
src[t.XRANGEPLAIN] = '[v=\\s]*(' + src[t.XRANGEIDENTIFIER] + ')' +
|
||||||
'(?:\\.(' + src[XRANGEIDENTIFIER] + ')' +
|
'(?:\\.(' + src[t.XRANGEIDENTIFIER] + ')' +
|
||||||
'(?:\\.(' + src[XRANGEIDENTIFIER] + ')' +
|
'(?:\\.(' + src[t.XRANGEIDENTIFIER] + ')' +
|
||||||
'(?:' + src[PRERELEASE] + ')?' +
|
'(?:' + src[t.PRERELEASE] + ')?' +
|
||||||
src[BUILD] + '?' +
|
src[t.BUILD] + '?' +
|
||||||
')?)?'
|
')?)?'
|
||||||
|
|
||||||
var XRANGEPLAINLOOSE = R++
|
tok('XRANGEPLAINLOOSE')
|
||||||
src[XRANGEPLAINLOOSE] = '[v=\\s]*(' + src[XRANGEIDENTIFIERLOOSE] + ')' +
|
src[t.XRANGEPLAINLOOSE] = '[v=\\s]*(' + src[t.XRANGEIDENTIFIERLOOSE] + ')' +
|
||||||
'(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' +
|
'(?:\\.(' + src[t.XRANGEIDENTIFIERLOOSE] + ')' +
|
||||||
'(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' +
|
'(?:\\.(' + src[t.XRANGEIDENTIFIERLOOSE] + ')' +
|
||||||
'(?:' + src[PRERELEASELOOSE] + ')?' +
|
'(?:' + src[t.PRERELEASELOOSE] + ')?' +
|
||||||
src[BUILD] + '?' +
|
src[t.BUILD] + '?' +
|
||||||
')?)?'
|
')?)?'
|
||||||
|
|
||||||
var XRANGE = R++
|
tok('XRANGE')
|
||||||
src[XRANGE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAIN] + '$'
|
src[t.XRANGE] = '^' + src[t.GTLT] + '\\s*' + src[t.XRANGEPLAIN] + '$'
|
||||||
var XRANGELOOSE = R++
|
tok('XRANGELOOSE')
|
||||||
src[XRANGELOOSE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAINLOOSE] + '$'
|
src[t.XRANGELOOSE] = '^' + src[t.GTLT] + '\\s*' + src[t.XRANGEPLAINLOOSE] + '$'
|
||||||
|
|
||||||
// Coercion.
|
// Coercion.
|
||||||
// Extract anything that could conceivably be a part of a valid semver
|
// Extract anything that could conceivably be a part of a valid semver
|
||||||
var COERCE = R++
|
tok('COERCE')
|
||||||
src[COERCE] = '(?:^|[^\\d])' +
|
src[t.COERCE] = '(^|[^\\d])' +
|
||||||
'(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '})' +
|
'(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '})' +
|
||||||
'(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' +
|
'(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' +
|
||||||
'(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' +
|
'(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' +
|
||||||
'(?:$|[^\\d])'
|
'(?:$|[^\\d])'
|
||||||
|
tok('COERCERTL')
|
||||||
|
re[t.COERCERTL] = new RegExp(src[t.COERCE], 'g')
|
||||||
|
|
||||||
// Tilde ranges.
|
// Tilde ranges.
|
||||||
// Meaning is "reasonably at or greater than"
|
// Meaning is "reasonably at or greater than"
|
||||||
var LONETILDE = R++
|
tok('LONETILDE')
|
||||||
src[LONETILDE] = '(?:~>?)'
|
src[t.LONETILDE] = '(?:~>?)'
|
||||||
|
|
||||||
var TILDETRIM = R++
|
tok('TILDETRIM')
|
||||||
src[TILDETRIM] = '(\\s*)' + src[LONETILDE] + '\\s+'
|
src[t.TILDETRIM] = '(\\s*)' + src[t.LONETILDE] + '\\s+'
|
||||||
re[TILDETRIM] = new RegExp(src[TILDETRIM], 'g')
|
re[t.TILDETRIM] = new RegExp(src[t.TILDETRIM], 'g')
|
||||||
var tildeTrimReplace = '$1~'
|
var tildeTrimReplace = '$1~'
|
||||||
|
|
||||||
var TILDE = R++
|
tok('TILDE')
|
||||||
src[TILDE] = '^' + src[LONETILDE] + src[XRANGEPLAIN] + '$'
|
src[t.TILDE] = '^' + src[t.LONETILDE] + src[t.XRANGEPLAIN] + '$'
|
||||||
var TILDELOOSE = R++
|
tok('TILDELOOSE')
|
||||||
src[TILDELOOSE] = '^' + src[LONETILDE] + src[XRANGEPLAINLOOSE] + '$'
|
src[t.TILDELOOSE] = '^' + src[t.LONETILDE] + src[t.XRANGEPLAINLOOSE] + '$'
|
||||||
|
|
||||||
// Caret ranges.
|
// Caret ranges.
|
||||||
// Meaning is "at least and backwards compatible with"
|
// Meaning is "at least and backwards compatible with"
|
||||||
var LONECARET = R++
|
tok('LONECARET')
|
||||||
src[LONECARET] = '(?:\\^)'
|
src[t.LONECARET] = '(?:\\^)'
|
||||||
|
|
||||||
var CARETTRIM = R++
|
tok('CARETTRIM')
|
||||||
src[CARETTRIM] = '(\\s*)' + src[LONECARET] + '\\s+'
|
src[t.CARETTRIM] = '(\\s*)' + src[t.LONECARET] + '\\s+'
|
||||||
re[CARETTRIM] = new RegExp(src[CARETTRIM], 'g')
|
re[t.CARETTRIM] = new RegExp(src[t.CARETTRIM], 'g')
|
||||||
var caretTrimReplace = '$1^'
|
var caretTrimReplace = '$1^'
|
||||||
|
|
||||||
var CARET = R++
|
tok('CARET')
|
||||||
src[CARET] = '^' + src[LONECARET] + src[XRANGEPLAIN] + '$'
|
src[t.CARET] = '^' + src[t.LONECARET] + src[t.XRANGEPLAIN] + '$'
|
||||||
var CARETLOOSE = R++
|
tok('CARETLOOSE')
|
||||||
src[CARETLOOSE] = '^' + src[LONECARET] + src[XRANGEPLAINLOOSE] + '$'
|
src[t.CARETLOOSE] = '^' + src[t.LONECARET] + src[t.XRANGEPLAINLOOSE] + '$'
|
||||||
|
|
||||||
// A simple gt/lt/eq thing, or just "" to indicate "any version"
|
// A simple gt/lt/eq thing, or just "" to indicate "any version"
|
||||||
var COMPARATORLOOSE = R++
|
tok('COMPARATORLOOSE')
|
||||||
src[COMPARATORLOOSE] = '^' + src[GTLT] + '\\s*(' + LOOSEPLAIN + ')$|^$'
|
src[t.COMPARATORLOOSE] = '^' + src[t.GTLT] + '\\s*(' + src[t.LOOSEPLAIN] + ')$|^$'
|
||||||
var COMPARATOR = R++
|
tok('COMPARATOR')
|
||||||
src[COMPARATOR] = '^' + src[GTLT] + '\\s*(' + FULLPLAIN + ')$|^$'
|
src[t.COMPARATOR] = '^' + src[t.GTLT] + '\\s*(' + src[t.FULLPLAIN] + ')$|^$'
|
||||||
|
|
||||||
// An expression to strip any whitespace between the gtlt and the thing
|
// An expression to strip any whitespace between the gtlt and the thing
|
||||||
// it modifies, so that `> 1.2.3` ==> `>1.2.3`
|
// it modifies, so that `> 1.2.3` ==> `>1.2.3`
|
||||||
var COMPARATORTRIM = R++
|
tok('COMPARATORTRIM')
|
||||||
src[COMPARATORTRIM] = '(\\s*)' + src[GTLT] +
|
src[t.COMPARATORTRIM] = '(\\s*)' + src[t.GTLT] +
|
||||||
'\\s*(' + LOOSEPLAIN + '|' + src[XRANGEPLAIN] + ')'
|
'\\s*(' + src[t.LOOSEPLAIN] + '|' + src[t.XRANGEPLAIN] + ')'
|
||||||
|
|
||||||
// this one has to use the /g flag
|
// this one has to use the /g flag
|
||||||
re[COMPARATORTRIM] = new RegExp(src[COMPARATORTRIM], 'g')
|
re[t.COMPARATORTRIM] = new RegExp(src[t.COMPARATORTRIM], 'g')
|
||||||
var comparatorTrimReplace = '$1$2$3'
|
var comparatorTrimReplace = '$1$2$3'
|
||||||
|
|
||||||
// Something like `1.2.3 - 1.2.4`
|
// Something like `1.2.3 - 1.2.4`
|
||||||
// Note that these all use the loose form, because they'll be
|
// Note that these all use the loose form, because they'll be
|
||||||
// checked against either the strict or loose comparator form
|
// checked against either the strict or loose comparator form
|
||||||
// later.
|
// later.
|
||||||
var HYPHENRANGE = R++
|
tok('HYPHENRANGE')
|
||||||
src[HYPHENRANGE] = '^\\s*(' + src[XRANGEPLAIN] + ')' +
|
src[t.HYPHENRANGE] = '^\\s*(' + src[t.XRANGEPLAIN] + ')' +
|
||||||
'\\s+-\\s+' +
|
'\\s+-\\s+' +
|
||||||
'(' + src[XRANGEPLAIN] + ')' +
|
'(' + src[t.XRANGEPLAIN] + ')' +
|
||||||
'\\s*$'
|
'\\s*$'
|
||||||
|
|
||||||
var HYPHENRANGELOOSE = R++
|
tok('HYPHENRANGELOOSE')
|
||||||
src[HYPHENRANGELOOSE] = '^\\s*(' + src[XRANGEPLAINLOOSE] + ')' +
|
src[t.HYPHENRANGELOOSE] = '^\\s*(' + src[t.XRANGEPLAINLOOSE] + ')' +
|
||||||
'\\s+-\\s+' +
|
'\\s+-\\s+' +
|
||||||
'(' + src[XRANGEPLAINLOOSE] + ')' +
|
'(' + src[t.XRANGEPLAINLOOSE] + ')' +
|
||||||
'\\s*$'
|
'\\s*$'
|
||||||
|
|
||||||
// Star ranges basically just allow anything at all.
|
// Star ranges basically just allow anything at all.
|
||||||
var STAR = R++
|
tok('STAR')
|
||||||
src[STAR] = '(<|>)?=?\\s*\\*'
|
src[t.STAR] = '(<|>)?=?\\s*\\*'
|
||||||
|
|
||||||
// Compile to actual regexp objects.
|
// Compile to actual regexp objects.
|
||||||
// All are flag-free, unless they were created above with a flag.
|
// All are flag-free, unless they were created above with a flag.
|
||||||
|
@ -262,7 +271,7 @@ function parse (version, options) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
var r = options.loose ? re[LOOSE] : re[FULL]
|
var r = options.loose ? re[t.LOOSE] : re[t.FULL]
|
||||||
if (!r.test(version)) {
|
if (!r.test(version)) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
@ -317,7 +326,7 @@ function SemVer (version, options) {
|
||||||
this.options = options
|
this.options = options
|
||||||
this.loose = !!options.loose
|
this.loose = !!options.loose
|
||||||
|
|
||||||
var m = version.trim().match(options.loose ? re[LOOSE] : re[FULL])
|
var m = version.trim().match(options.loose ? re[t.LOOSE] : re[t.FULL])
|
||||||
|
|
||||||
if (!m) {
|
if (!m) {
|
||||||
throw new TypeError('Invalid Version: ' + version)
|
throw new TypeError('Invalid Version: ' + version)
|
||||||
|
@ -778,7 +787,7 @@ function Comparator (comp, options) {
|
||||||
|
|
||||||
var ANY = {}
|
var ANY = {}
|
||||||
Comparator.prototype.parse = function (comp) {
|
Comparator.prototype.parse = function (comp) {
|
||||||
var r = this.options.loose ? re[COMPARATORLOOSE] : re[COMPARATOR]
|
var r = this.options.loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR]
|
||||||
var m = comp.match(r)
|
var m = comp.match(r)
|
||||||
|
|
||||||
if (!m) {
|
if (!m) {
|
||||||
|
@ -810,7 +819,11 @@ Comparator.prototype.test = function (version) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof version === 'string') {
|
if (typeof version === 'string') {
|
||||||
|
try {
|
||||||
version = new SemVer(version, this.options)
|
version = new SemVer(version, this.options)
|
||||||
|
} catch (er) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmp(version, this.operator, this.semver, this.options)
|
return cmp(version, this.operator, this.semver, this.options)
|
||||||
|
@ -929,18 +942,18 @@ Range.prototype.parseRange = function (range) {
|
||||||
var loose = this.options.loose
|
var loose = this.options.loose
|
||||||
range = range.trim()
|
range = range.trim()
|
||||||
// `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
|
// `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
|
||||||
var hr = loose ? re[HYPHENRANGELOOSE] : re[HYPHENRANGE]
|
var hr = loose ? re[t.HYPHENRANGELOOSE] : re[t.HYPHENRANGE]
|
||||||
range = range.replace(hr, hyphenReplace)
|
range = range.replace(hr, hyphenReplace)
|
||||||
debug('hyphen replace', range)
|
debug('hyphen replace', range)
|
||||||
// `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
|
// `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
|
||||||
range = range.replace(re[COMPARATORTRIM], comparatorTrimReplace)
|
range = range.replace(re[t.COMPARATORTRIM], comparatorTrimReplace)
|
||||||
debug('comparator trim', range, re[COMPARATORTRIM])
|
debug('comparator trim', range, re[t.COMPARATORTRIM])
|
||||||
|
|
||||||
// `~ 1.2.3` => `~1.2.3`
|
// `~ 1.2.3` => `~1.2.3`
|
||||||
range = range.replace(re[TILDETRIM], tildeTrimReplace)
|
range = range.replace(re[t.TILDETRIM], tildeTrimReplace)
|
||||||
|
|
||||||
// `^ 1.2.3` => `^1.2.3`
|
// `^ 1.2.3` => `^1.2.3`
|
||||||
range = range.replace(re[CARETTRIM], caretTrimReplace)
|
range = range.replace(re[t.CARETTRIM], caretTrimReplace)
|
||||||
|
|
||||||
// normalize spaces
|
// normalize spaces
|
||||||
range = range.split(/\s+/).join(' ')
|
range = range.split(/\s+/).join(' ')
|
||||||
|
@ -948,7 +961,7 @@ Range.prototype.parseRange = function (range) {
|
||||||
// At this point, the range is completely trimmed and
|
// At this point, the range is completely trimmed and
|
||||||
// ready to be split into comparators.
|
// ready to be split into comparators.
|
||||||
|
|
||||||
var compRe = loose ? re[COMPARATORLOOSE] : re[COMPARATOR]
|
var compRe = loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR]
|
||||||
var set = range.split(' ').map(function (comp) {
|
var set = range.split(' ').map(function (comp) {
|
||||||
return parseComparator(comp, this.options)
|
return parseComparator(comp, this.options)
|
||||||
}, this).join(' ').split(/\s+/)
|
}, this).join(' ').split(/\s+/)
|
||||||
|
@ -1048,7 +1061,7 @@ function replaceTildes (comp, options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function replaceTilde (comp, options) {
|
function replaceTilde (comp, options) {
|
||||||
var r = options.loose ? re[TILDELOOSE] : re[TILDE]
|
var r = options.loose ? re[t.TILDELOOSE] : re[t.TILDE]
|
||||||
return comp.replace(r, function (_, M, m, p, pr) {
|
return comp.replace(r, function (_, M, m, p, pr) {
|
||||||
debug('tilde', comp, _, M, m, p, pr)
|
debug('tilde', comp, _, M, m, p, pr)
|
||||||
var ret
|
var ret
|
||||||
|
@ -1089,7 +1102,7 @@ function replaceCarets (comp, options) {
|
||||||
|
|
||||||
function replaceCaret (comp, options) {
|
function replaceCaret (comp, options) {
|
||||||
debug('caret', comp, options)
|
debug('caret', comp, options)
|
||||||
var r = options.loose ? re[CARETLOOSE] : re[CARET]
|
var r = options.loose ? re[t.CARETLOOSE] : re[t.CARET]
|
||||||
return comp.replace(r, function (_, M, m, p, pr) {
|
return comp.replace(r, function (_, M, m, p, pr) {
|
||||||
debug('caret', comp, _, M, m, p, pr)
|
debug('caret', comp, _, M, m, p, pr)
|
||||||
var ret
|
var ret
|
||||||
|
@ -1148,7 +1161,7 @@ function replaceXRanges (comp, options) {
|
||||||
|
|
||||||
function replaceXRange (comp, options) {
|
function replaceXRange (comp, options) {
|
||||||
comp = comp.trim()
|
comp = comp.trim()
|
||||||
var r = options.loose ? re[XRANGELOOSE] : re[XRANGE]
|
var r = options.loose ? re[t.XRANGELOOSE] : re[t.XRANGE]
|
||||||
return comp.replace(r, function (ret, gtlt, M, m, p, pr) {
|
return comp.replace(r, function (ret, gtlt, M, m, p, pr) {
|
||||||
debug('xRange', comp, ret, gtlt, M, m, p, pr)
|
debug('xRange', comp, ret, gtlt, M, m, p, pr)
|
||||||
var xM = isX(M)
|
var xM = isX(M)
|
||||||
|
@ -1160,10 +1173,14 @@ function replaceXRange (comp, options) {
|
||||||
gtlt = ''
|
gtlt = ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if we're including prereleases in the match, then we need
|
||||||
|
// to fix this to -0, the lowest possible prerelease value
|
||||||
|
pr = options.includePrerelease ? '-0' : ''
|
||||||
|
|
||||||
if (xM) {
|
if (xM) {
|
||||||
if (gtlt === '>' || gtlt === '<') {
|
if (gtlt === '>' || gtlt === '<') {
|
||||||
// nothing is allowed
|
// nothing is allowed
|
||||||
ret = '<0.0.0'
|
ret = '<0.0.0-0'
|
||||||
} else {
|
} else {
|
||||||
// nothing is forbidden
|
// nothing is forbidden
|
||||||
ret = '*'
|
ret = '*'
|
||||||
|
@ -1200,11 +1217,12 @@ function replaceXRange (comp, options) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = gtlt + M + '.' + m + '.' + p
|
ret = gtlt + M + '.' + m + '.' + p + pr
|
||||||
} else if (xm) {
|
} else if (xm) {
|
||||||
ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0'
|
ret = '>=' + M + '.0.0' + pr + ' <' + (+M + 1) + '.0.0' + pr
|
||||||
} else if (xp) {
|
} else if (xp) {
|
||||||
ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0'
|
ret = '>=' + M + '.' + m + '.0' + pr +
|
||||||
|
' <' + M + '.' + (+m + 1) + '.0' + pr
|
||||||
}
|
}
|
||||||
|
|
||||||
debug('xRange return', ret)
|
debug('xRange return', ret)
|
||||||
|
@ -1218,10 +1236,10 @@ function replaceXRange (comp, options) {
|
||||||
function replaceStars (comp, options) {
|
function replaceStars (comp, options) {
|
||||||
debug('replaceStars', comp, options)
|
debug('replaceStars', comp, options)
|
||||||
// Looseness is ignored here. star is always as loose as it gets!
|
// Looseness is ignored here. star is always as loose as it gets!
|
||||||
return comp.trim().replace(re[STAR], '')
|
return comp.trim().replace(re[t.STAR], '')
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function is passed to string.replace(re[HYPHENRANGE])
|
// This function is passed to string.replace(re[t.HYPHENRANGE])
|
||||||
// M, m, patch, prerelease, build
|
// M, m, patch, prerelease, build
|
||||||
// 1.2 - 3.4.5 => >=1.2.0 <=3.4.5
|
// 1.2 - 3.4.5 => >=1.2.0 <=3.4.5
|
||||||
// 1.2.3 - 3.4 => >=1.2.0 <3.5.0 Any 3.4.x will do
|
// 1.2.3 - 3.4 => >=1.2.0 <3.5.0 Any 3.4.x will do
|
||||||
|
@ -1261,7 +1279,11 @@ Range.prototype.test = function (version) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof version === 'string') {
|
if (typeof version === 'string') {
|
||||||
|
try {
|
||||||
version = new SemVer(version, this.options)
|
version = new SemVer(version, this.options)
|
||||||
|
} catch (er) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < this.set.length; i++) {
|
for (var i = 0; i < this.set.length; i++) {
|
||||||
|
@ -1528,17 +1550,47 @@ function coerce (version, options) {
|
||||||
return version
|
return version
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof version === 'number') {
|
||||||
|
version = String(version)
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof version !== 'string') {
|
if (typeof version !== 'string') {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
var match = version.match(re[COERCE])
|
options = options || {}
|
||||||
|
|
||||||
if (match == null) {
|
var match = null
|
||||||
|
if (!options.rtl) {
|
||||||
|
match = version.match(re[t.COERCE])
|
||||||
|
} else {
|
||||||
|
// Find the right-most coercible string that does not share
|
||||||
|
// a terminus with a more left-ward coercible string.
|
||||||
|
// Eg, '1.2.3.4' wants to coerce '2.3.4', not '3.4' or '4'
|
||||||
|
//
|
||||||
|
// Walk through the string checking with a /g regexp
|
||||||
|
// Manually set the index so as to pick up overlapping matches.
|
||||||
|
// Stop when we get a match that ends at the string end, since no
|
||||||
|
// coercible string can be more right-ward without the same terminus.
|
||||||
|
var next
|
||||||
|
while ((next = re[t.COERCERTL].exec(version)) &&
|
||||||
|
(!match || match.index + match[0].length !== version.length)
|
||||||
|
) {
|
||||||
|
if (!match ||
|
||||||
|
next.index + next[0].length !== match.index + match[0].length) {
|
||||||
|
match = next
|
||||||
|
}
|
||||||
|
re[t.COERCERTL].lastIndex = next.index + next[1].length + next[2].length
|
||||||
|
}
|
||||||
|
// leave it in a clean state
|
||||||
|
re[t.COERCERTL].lastIndex = -1
|
||||||
|
}
|
||||||
|
|
||||||
|
if (match === null) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return parse(match[1] +
|
return parse(match[2] +
|
||||||
'.' + (match[2] || '0') +
|
'.' + (match[3] || '0') +
|
||||||
'.' + (match[3] || '0'), options)
|
'.' + (match[4] || '0'), options)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,14 +5,17 @@
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": {
|
"@actions/core": {
|
||||||
"version": "1.0.0",
|
"version": "1.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.0.tgz",
|
||||||
"integrity": "sha512-aMIlkx96XH4E/2YZtEOeyrYQfhlas9jIRkfGPqMwXD095Rdkzo4lB6ZmbxPQSzD+e1M+Xsm98ZhuSMYGv/AlqA=="
|
"integrity": "sha512-ZKdyhlSlyz38S6YFfPnyNgCDZuAF2T0Qv5eHflNWytPS8Qjvz39bZFMry9Bb/dpSnqWcNeav5yM2CTYpJeY+Dw=="
|
||||||
},
|
},
|
||||||
"@actions/exec": {
|
"@actions/exec": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.0.2.tgz",
|
||||||
"integrity": "sha512-nquH0+XKng+Ll7rZfCojN7NWSbnGh+ltwUJhzfbLkmOJgxocGX2/yXcZLMyT9fa7+tByEow/NSTrBExNlEj9fw=="
|
"integrity": "sha512-Yo/wfcFuxbVjAaAfvx3aGLhMEuonOahas2jf8BwyA52IkXTAmLi7YVZTpGAQG/lTxuGoNLg9slTWQD4rr7rMDQ==",
|
||||||
|
"requires": {
|
||||||
|
"@actions/io": "^1.0.1"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"@actions/github": {
|
"@actions/github": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
|
@ -24,18 +27,18 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@actions/io": {
|
"@actions/io": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/io/-/io-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/io/-/io-1.0.1.tgz",
|
||||||
"integrity": "sha512-ezrJSRdqtXtdx1WXlfYL85+40F7gB39jCK9P0jZVODW3W6xUYmu6ZOEc/UmmElUwhRyDRm1R4yNZu1Joq2kuQg=="
|
"integrity": "sha512-rhq+tfZukbtaus7xyUtwKfuiCRXd1hWSfmJNEpFgBQJ4woqPEpsBw04awicjwz9tyG2/MVhAEMfVn664Cri5zA=="
|
||||||
},
|
},
|
||||||
"@actions/tool-cache": {
|
"@actions/tool-cache": {
|
||||||
"version": "1.0.0",
|
"version": "1.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/tool-cache/-/tool-cache-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/tool-cache/-/tool-cache-1.1.2.tgz",
|
||||||
"integrity": "sha512-l3zT0IfDfi5Ik5aMpnXqGHGATxN8xa9ls4ue+X/CBXpPhRMRZS4vcuh5Q9T98WAGbkysRCfhpbksTPHIcKnNwQ==",
|
"integrity": "sha512-IJczPaZr02ECa3Lgws/TJEVco9tjOujiQSZbO3dHuXXjhd5vrUtfOgGwhmz3/f97L910OraPZ8SknofUk6RvOQ==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@actions/core": "^1.0.0",
|
"@actions/core": "^1.1.0",
|
||||||
"@actions/exec": "^1.0.0",
|
"@actions/exec": "^1.0.1",
|
||||||
"@actions/io": "^1.0.0",
|
"@actions/io": "^1.0.1",
|
||||||
"semver": "^6.1.0",
|
"semver": "^6.1.0",
|
||||||
"typed-rest-client": "^1.4.0",
|
"typed-rest-client": "^1.4.0",
|
||||||
"uuid": "^3.3.2"
|
"uuid": "^3.3.2"
|
||||||
|
@ -1813,12 +1816,9 @@
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"fast-xml-parser": {
|
"fast-xml-parser": {
|
||||||
"version": "3.12.20",
|
"version": "3.15.1",
|
||||||
"resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-3.12.20.tgz",
|
"resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-3.15.1.tgz",
|
||||||
"integrity": "sha512-viadHdefuuqkyJWUhF2r2Ymb5LJ0T7uQhzSRv4OZzYxpoPQnY05KtaX0pLkolabD7tLzIE8q/OytIAEhqPyYbw==",
|
"integrity": "sha512-MStlD6aNPZCd9msF5wBh2VJ0jAE2zz85ipk+OIPO+pZi64ckY//oGi5kskcTVRj2bMSmBI5F2SY1IGWHWZzbCA=="
|
||||||
"requires": {
|
|
||||||
"nimnjs": "^1.3.2"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"fb-watchman": {
|
"fb-watchman": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
|
@ -3964,25 +3964,6 @@
|
||||||
"resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz",
|
"resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz",
|
||||||
"integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ=="
|
"integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ=="
|
||||||
},
|
},
|
||||||
"nimn-date-parser": {
|
|
||||||
"version": "1.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/nimn-date-parser/-/nimn-date-parser-1.0.0.tgz",
|
|
||||||
"integrity": "sha512-1Nf+x3EeMvHUiHsVuEhiZnwA8RMeOBVTQWfB1S2n9+i6PYCofHd2HRMD+WOHIHYshy4T4Gk8wQoCol7Hq3av8Q=="
|
|
||||||
},
|
|
||||||
"nimn_schema_builder": {
|
|
||||||
"version": "1.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/nimn_schema_builder/-/nimn_schema_builder-1.1.0.tgz",
|
|
||||||
"integrity": "sha512-DK5/B8CM4qwzG2URy130avcwPev4uO0ev836FbQyKo1ms6I9z/i6EJyiZ+d9xtgloxUri0W+5gfR8YbPq7SheA=="
|
|
||||||
},
|
|
||||||
"nimnjs": {
|
|
||||||
"version": "1.3.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/nimnjs/-/nimnjs-1.3.2.tgz",
|
|
||||||
"integrity": "sha512-TIOtI4iqkQrUM1tiM76AtTQem0c7e56SkDZ7sj1d1MfUsqRcq2ZWQvej/O+HBTZV7u/VKnwlKTDugK/75IRPPw==",
|
|
||||||
"requires": {
|
|
||||||
"nimn-date-parser": "^1.0.0",
|
|
||||||
"nimn_schema_builder": "^1.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node-fetch": {
|
"node-fetch": {
|
||||||
"version": "2.6.0",
|
"version": "2.6.0",
|
||||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz",
|
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz",
|
||||||
|
@ -4749,9 +4730,9 @@
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"semver": {
|
"semver": {
|
||||||
"version": "6.1.1",
|
"version": "6.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/semver/-/semver-6.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
|
||||||
"integrity": "sha512-rWYq2e5iYW+fFe/oPPtYJxYgjBm8sC4rmoGdUOgBB7VnwKt6HrL793l2voH1UlsyYZpJ4g0wfjnTEO1s1NP2eQ=="
|
"integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw=="
|
||||||
},
|
},
|
||||||
"semver-compare": {
|
"semver-compare": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
|
|
12
package.json
12
package.json
|
@ -22,13 +22,13 @@
|
||||||
"author": "GitHub",
|
"author": "GitHub",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.0.0",
|
"@actions/core": "^1.2.0",
|
||||||
"@actions/exec": "^1.0.0",
|
"@actions/exec": "^1.0.2",
|
||||||
"@actions/github": "^1.1.0",
|
"@actions/github": "^1.1.0",
|
||||||
"@actions/io": "^1.0.0",
|
"@actions/io": "^1.0.1",
|
||||||
"@actions/tool-cache": "^1.0.0",
|
"@actions/tool-cache": "^1.1.2",
|
||||||
"fast-xml-parser": "^3.12.20",
|
"fast-xml-parser": "^3.15.1",
|
||||||
"semver": "^6.1.1",
|
"semver": "^6.3.0",
|
||||||
"typed-rest-client": "1.5.0",
|
"typed-rest-client": "1.5.0",
|
||||||
"xmlbuilder": "^13.0.2"
|
"xmlbuilder": "^13.0.2"
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue