mirror of
https://github.com/Shiva108/ai-llm-red-team-handbook.git
synced 2026-08-28 13:50:53 +02:00
adding mermaid packages
This commit is contained in:
+3
@@ -0,0 +1,3 @@
|
||||
import { DataURI } from "./types";
|
||||
declare function DataURIASync(fileName: string, handler?: DataURI.Callback): Promise<string | undefined>;
|
||||
export = DataURIASync;
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
const parser_1 = __importDefault(require("./parser"));
|
||||
function DataURIASync(fileName, handler) {
|
||||
const parser = new parser_1.default();
|
||||
return parser.encode(fileName, handler);
|
||||
}
|
||||
module.exports = DataURIASync;
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":"3.0.0","maintainers":[{"name":"Helder Santana","email":"heldr@me.com","url":"http://heldr.com"},{"name":"Ruy Adorno","url":"http://ruyadorno.com"},{"name":"Caio Gondim","email":"me@caiogondim.com","url":"https://caiogondim.com"}],"repository":{"type":"git","url":"git://github.com/data-uri/datauri.git"},"engines":{"node":">= 8"},"keywords":["datauri","data uri","data","uri","data-uri","optimization","uri","optimize","inline","png","jpg","woff","base64"],"author":"Helder Santana","license":"MIT","name":"datauri","dependencies":{"image-size":"0.8.3","mimer":"1.1.0"},"description":"Create DataURI scheme easily"}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
import { DataURI } from "./types";
|
||||
declare class DataURIParser {
|
||||
fileName?: string;
|
||||
mimetype?: string;
|
||||
content?: string;
|
||||
base64?: string;
|
||||
encode(fileName: string, handler?: DataURI.Callback): Promise<string | undefined>;
|
||||
format(fileName: string, fileContent: DataURI.Input): this;
|
||||
getCSS(config?: DataURI.CSSConfig): string;
|
||||
private createMetadata;
|
||||
}
|
||||
export = DataURIParser;
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const util_1 = __importDefault(require("util"));
|
||||
const mimer_1 = __importDefault(require("mimer"));
|
||||
const image_size_1 = require("image-size");
|
||||
const uri_1 = __importDefault(require("./template/uri"));
|
||||
const css_1 = __importDefault(require("./template/css"));
|
||||
const defaultCSSConfig = {};
|
||||
const readFile = util_1.default.promisify(fs_1.default.readFile);
|
||||
class DataURIParser {
|
||||
async encode(fileName, handler) {
|
||||
try {
|
||||
this.base64 = await readFile(fileName, { 'encoding': 'base64' });
|
||||
this.createMetadata(fileName);
|
||||
handler && handler(undefined, this.content, this);
|
||||
return this.content;
|
||||
}
|
||||
catch (err) {
|
||||
if (handler) {
|
||||
handler(err);
|
||||
return;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
format(fileName, fileContent) {
|
||||
const fileBuffer = (fileContent instanceof Buffer) ? fileContent : Buffer.from(fileContent);
|
||||
this.base64 = fileBuffer.toString('base64');
|
||||
this.createMetadata(fileName);
|
||||
return this;
|
||||
}
|
||||
getCSS(config = defaultCSSConfig) {
|
||||
config = config || {};
|
||||
if (!this.content || !this.fileName) {
|
||||
throw new Error('Create a data-uri config using the method encodeSync');
|
||||
}
|
||||
config.class = config.class || path_1.default.basename(this.fileName, path_1.default.extname(this.fileName));
|
||||
if (config.width || config.height || config['background-size']) {
|
||||
config.dimensions = image_size_1.imageSize(this.fileName);
|
||||
}
|
||||
return css_1.default(Object.assign(Object.assign({}, config), { background: this.content }));
|
||||
}
|
||||
createMetadata(fileName) {
|
||||
this.fileName = fileName;
|
||||
this.mimetype = mimer_1.default(fileName);
|
||||
this.content = uri_1.default(this);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
module.exports = DataURIParser;
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
<h1 align="center">
|
||||
<br>
|
||||
<img width="365" src="https://cdn.rawgit.com/data-uri/datauri/master/media/datauri.svg" alt="datauri">
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
</h1>
|
||||
|
||||
Node.js [Module](#module) and [CLI](http://npm.im/datauri-cli) to generate [Data URI scheme](http://en.wikipedia.org/wiki/Data_URI_scheme).
|
||||
|
||||
> The data URI scheme is a uniform resource identifier (URI) scheme that provides a way to include data in-line in web pages as if they were external resources.
|
||||
|
||||
from: [Wikipedia](http://en.wikipedia.org/wiki/Data_URI_scheme)
|
||||
|
||||
MODULE [](http://travis-ci.org/data-uri/datauri)
|
||||
-------
|
||||
For Node 8+ compatibility:
|
||||
|
||||
`npm install --save datauri`
|
||||
|
||||
### Getting started
|
||||
By default, datauri module returns a promise, which is resolved with `data:uri` string or rejected with file read error:
|
||||
|
||||
```js
|
||||
const datauri = require('datauri');
|
||||
|
||||
const content = await datauri('test/myfile.png');
|
||||
|
||||
console.log(content)
|
||||
//=> "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
|
||||
```
|
||||
|
||||
### Callback style and meta data
|
||||
```js
|
||||
const datauri = require('datauri');
|
||||
|
||||
datauri('test/myfile.png', (err, content, meta) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
console.log(content); //=> "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
|
||||
|
||||
console.log(meta.mimetype); //=> "image/png"
|
||||
console.log(meta.base64); //=> "iVBORw0KGgoAAAANSUhEUgAA..."
|
||||
console.log(meta.getCSS()); //=> "\n.case {\n background-image: url('data:image/png;base64,iVBORw..."
|
||||
console.log(meta.getCSS({
|
||||
class: "myClass",
|
||||
width: true,
|
||||
height: true
|
||||
})); //=> adds image width and height and custom class name
|
||||
});
|
||||
```
|
||||
|
||||
### Synchronous calls
|
||||
|
||||
```js
|
||||
const Datauri = require('datauri/sync');
|
||||
const meta = Datauri('test/myfile.png');
|
||||
|
||||
console.log(meta.content); //=> "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
|
||||
console.log(meta.mimetype); //=> "image/png"
|
||||
console.log(meta.base64); //=> "iVBORw0KGgoAAAANSUhEUgAA..."
|
||||
console.log(meta.getCSS()); //=> "\n.case {\n background-image: url('data:image/png;base64,iVBORw..."
|
||||
console.log(meta.getCSS("myClass")); //=> "\n.myClass {\n background-image: url('data:image/png;base64,iVBORw..."
|
||||
```
|
||||
|
||||
### From a Buffer
|
||||
If you already have a file Buffer, that's the way to go:
|
||||
|
||||
```js
|
||||
const DatauriParser = require('datauri/parser');
|
||||
const parser = new DatauriParser();
|
||||
|
||||
const buffer = fs.readFileSync('./hello');
|
||||
|
||||
parser.format('.png', buffer); //=> "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
|
||||
```
|
||||
|
||||
### From a string
|
||||
```js
|
||||
const DatauriParser = require('datauri/parser');
|
||||
const parser = new DatauriParser();
|
||||
|
||||
parser.format('.png', 'xkcd'); //=> "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
|
||||
```
|
||||
|
||||
Contribute
|
||||
-------
|
||||
|
||||
```CLI
|
||||
$ npm install
|
||||
```
|
||||
|
||||
To run test specs
|
||||
|
||||
```CLI
|
||||
$ npm test
|
||||
```
|
||||
|
||||
|
||||
## [ChangeLog](https://github.com/data-uri/datauri/releases)
|
||||
|
||||
## Requirements
|
||||
|
||||
Node.js 8+
|
||||
|
||||
Previous Node versions and deprecated features:
|
||||
|
||||
`npm install --save datauri@2`
|
||||
|
||||
docs: https://github.com/data-uri/datauri/blob/v2.0.0/docs/datauri.md
|
||||
|
||||
## License
|
||||
|
||||
MIT License
|
||||
|
||||
(c) [Data-URI.js](https://github.com/data-uri)
|
||||
|
||||
(c) [Helder Santana](https://heldr.com)
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
import DataURIParser from "./parser";
|
||||
declare function DataURISync(fileName: string): DataURIParser;
|
||||
export = DataURISync;
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
const parser_1 = __importDefault(require("./parser"));
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
function DataURISync(fileName) {
|
||||
if (!fileName || !fileName.trim || fileName.trim() === '') {
|
||||
throw new Error('Insert a File path as string argument');
|
||||
}
|
||||
const parser = new parser_1.default();
|
||||
if (fs_1.default.existsSync(fileName)) {
|
||||
const fileContent = fs_1.default.readFileSync(fileName);
|
||||
return parser.format(fileName, fileContent);
|
||||
}
|
||||
throw new Error(`The file ${fileName} was not found!`);
|
||||
}
|
||||
module.exports = DataURISync;
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
declare function _exports(data: any): string;
|
||||
export = _exports;
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
const TAB = ' ';
|
||||
const SIZE_PROPS = key => /(width|height|background\-size)/g.test(key);
|
||||
const PROP_VALUE = (size, key) => (key === 'background-size') ?
|
||||
`${size.width}px ${size.height}px`
|
||||
: `${size[key]}px`;
|
||||
const PROP_SIZE = (size, key) => `${TAB}${key}: ${PROP_VALUE(size, key)};`;
|
||||
const BASE_CSS = (data) => [
|
||||
'',
|
||||
`.${data.class.replace(/\s+/gi, '_')} {`,
|
||||
`${TAB}background-image: url('${data.background}');`
|
||||
];
|
||||
const SIZE = data => Object.keys(data).filter(SIZE_PROPS).map(PROP_SIZE.bind(null, data.dimensions));
|
||||
module.exports = data => BASE_CSS(data).concat(SIZE(data), ['}']).join('\n');
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
declare function _exports(data: any): string;
|
||||
export = _exports;
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
'use strict';
|
||||
module.exports = data => `data:${data.mimetype};base64,${data.base64 || ''}`;
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
/// <reference types="node" />
|
||||
import Api from "./parser";
|
||||
import { ISize } from "image-size/dist/types/interface";
|
||||
export declare namespace DataURI {
|
||||
interface CSSConfig {
|
||||
width?: boolean;
|
||||
height?: boolean;
|
||||
"background-size"?: boolean;
|
||||
class?: string;
|
||||
dimensions?: ISize;
|
||||
}
|
||||
type Input = string | Buffer;
|
||||
type Callback = (err?: Error, content?: string, instance?: Api) => any;
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
Reference in New Issue
Block a user