@burger-editor/frozen-patty 0.11.0 → 3.5.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen-patty
2
2
 
3
- [![npm version](https://badge.fury.io/js/%burger-editor%2Ffrozen-patty.svg)](https://badge.fury.io/js/%burger-editor%2Ffrozen-patty) [![Build Status](https://travis-ci.org/YusukeHirao/frozen-patty.svg?branch=master)](https://travis-ci.org/YusukeHirao/frozen-patty) [![Coverage Status](https://coveralls.io/repos/github/YusukeHirao/frozen-patty/badge.svg?branch=master)](https://coveralls.io/github/YusukeHirao/frozen-patty?branch=master)
3
+ [![npm version](https://badge.fury.io/js/@burger-editor%2Ffrozen-patty.svg)](https://badge.fury.io/js/@burger-editor%2Ffrozen-patty)
4
4
 
5
5
  Pure HTML to JSON converter that not use template engine.
6
6
 
@@ -15,52 +15,52 @@ $ npm install -D @burger-editor/frozen-patty
15
15
  ### Extraction
16
16
 
17
17
  ```js
18
- import FrozenPatty from 'frozen-patty';
18
+ import frozenPatty from '@burger-editor/frozen-patty';
19
19
 
20
- FrozenPatty('<div data-field="text">value</div>').toJSON(); // => { text: 'value' }
21
- FrozenPatty('<div data-field="field-name">value</div>').toJSON(); // => { 'field-name': 'value' }
22
- FrozenPatty('<a href="http://localhost" data-field="href:href">link</a>').toJSON(); // => { 'href': 'http://localhost' }
20
+ frozenPatty('<div data-field="text">value</div>').toJSON(); // => { text: 'value' }
21
+ frozenPatty('<div data-field="field-name">value</div>').toJSON(); // => { 'field-name': 'value' }
22
+ frozenPatty('<a href="http://localhost" data-field="href:href">link</a>').toJSON(); // => { 'href': 'http://localhost' }
23
23
 
24
- FrozenPatty('<div data-bge="text">value</div>', { attr: 'bge' }).toJSON(); // => { text: 'value' }
24
+ frozenPatty('<div data-bge="text">value</div>', { attr: 'bge' }).toJSON(); // => { text: 'value' }
25
25
  ```
26
26
 
27
27
  ### Data merge
28
28
 
29
29
  ```js
30
- FrozenPatty('<div data-field="text">value</div>').merge({ text: 'merged' }).toHTML(); // => "<div data-field="text">merged</div>";
30
+ frozenPatty('<div data-field="text">value</div>').merge({ text: 'merged' }).toHTML(); // => "<div data-field="text">merged</div>";
31
31
  ```
32
32
 
33
33
  ## API
34
34
 
35
- ### FrozenPatty (html[, options])
35
+ ### `frozenPatty(html[, options])`
36
36
 
37
37
  Extraction data from HTML.
38
38
 
39
- #### arguments
39
+ #### Parameters
40
40
 
41
- | args | type | required | descriptions |
42
- | ------- | -------- | -------- | ------------- |
43
- | html | `string` | required | Original HTML |
44
- | options | `Object` | optional | † |
41
+ | parameter | type | required | descriptions |
42
+ | --------- | -------- | -------- | ------------- |
43
+ | html | `string` | required | Original HTML |
44
+ | options | `Object` | optional | † |
45
45
 
46
- #### options†
46
+ #### Options†
47
47
 
48
48
  | options | type | default | descriptions |
49
49
  | ------- | ------ | --------- | ------------------------------------------------------------------------------------ |
50
50
  | attr | string | `"field"` | **Data attribute** name for specifying the node that FrozenPatty treats as a _field_ |
51
51
 
52
- ### merge (data)
52
+ ### `merge(data)`
53
53
 
54
- Data merge
54
+ Merge data.
55
55
 
56
56
  | args | type | required | descriptions |
57
57
  | ---- | -------- | -------- | ------------ |
58
58
  | data | `Object` | required | New data |
59
59
 
60
- ### toJSON
60
+ ### `toJSON`
61
61
 
62
- Data to plain Object.
62
+ Convert to JSON.
63
63
 
64
- ### toHTML
64
+ ### `toHTML`
65
65
 
66
- Render to HTML as string.
66
+ Convert to HTML string.
@@ -15,7 +15,6 @@ export default class FrozenPatty {
15
15
  export interface FrozenPattyOptions {
16
16
  /**
17
17
  * **Data attribute** name for specifying the node that FrozenPatty treats as a _field_
18
- *
19
18
  * @default `"field"`
20
19
  */
21
20
  attr?: string;
@@ -28,7 +27,6 @@ export interface FrozenPattyOptions {
28
27
  * - `"1"` => `1`
29
28
  * - `"1.0"` => `1`
30
29
  * - `"0.1"` => `0.1`
31
- *
32
30
  * @default `false`
33
31
  */
34
32
  typeConvert?: boolean;
@@ -1,10 +1,10 @@
1
1
  import type { Filter, PrimitiveDatum } from './types.js';
2
2
  /**
3
3
  * Get value from an element
4
- *
5
4
  * @param el A target element
6
5
  * @param name A label name
7
6
  * @param typeConvert Auto covert type of value
8
7
  * @param attr Data attribute name for specifying the node that FrozenPatty treats as a field
8
+ * @param filter
9
9
  */
10
10
  export declare function getValue(el: Element, name: string, typeConvert?: boolean, attr?: string, filter?: Filter): PrimitiveDatum | PrimitiveDatum[];
package/dist/get-value.js CHANGED
@@ -2,11 +2,11 @@ import { getValues } from './get-values.js';
2
2
  import { arrayToHash } from './utils.js';
3
3
  /**
4
4
  * Get value from an element
5
- *
6
5
  * @param el A target element
7
6
  * @param name A label name
8
7
  * @param typeConvert Auto covert type of value
9
8
  * @param attr Data attribute name for specifying the node that FrozenPatty treats as a field
9
+ * @param filter
10
10
  */
11
11
  export function getValue(el, name, typeConvert = false, attr = 'field', filter) {
12
12
  const value = getValues(el, typeConvert, attr, filter);
@@ -1,10 +1,10 @@
1
1
  import type { Filter, PrimitiveDatum } from './types.js';
2
2
  /**
3
3
  * Get value from an element
4
- *
5
4
  * @param el A target element
6
5
  * @param name A label name
7
6
  * @param typeConvert Auto covert type of value
8
7
  * @param attr Data attribute name for specifying the node that FrozenPatty treats as a field
8
+ * @param filter
9
9
  */
10
10
  export declare function getValues(el: Element, typeConvert?: boolean, attr?: string, filter?: Filter): [string | number, PrimitiveDatum, boolean][];
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * Get value from an element
3
- *
4
3
  * @param el A target element
5
4
  * @param name A label name
6
5
  * @param typeConvert Auto covert type of value
7
6
  * @param attr Data attribute name for specifying the node that FrozenPatty treats as a field
7
+ * @param filter
8
8
  */
9
9
  export function getValues(el, typeConvert = false, attr = 'field', filter) {
10
10
  /**
@@ -75,6 +75,12 @@ export function getValues(el, typeConvert = false, attr = 'field', filter) {
75
75
  // console.log({result});
76
76
  return result;
77
77
  }
78
+ /**
79
+ *
80
+ * @param el
81
+ * @param keyAttr
82
+ * @param typeConvert
83
+ */
78
84
  function getAttribute(el, keyAttr, typeConvert) {
79
85
  switch (keyAttr) {
80
86
  case 'contenteditable': {
@@ -112,6 +118,10 @@ function getAttribute(el, keyAttr, typeConvert) {
112
118
  }
113
119
  }
114
120
  }
121
+ /**
122
+ *
123
+ * @param value
124
+ */
115
125
  function cast(value) {
116
126
  if (value == null || value === '') {
117
127
  return '';
@@ -132,7 +142,7 @@ function cast(value) {
132
142
  }
133
143
  /**
134
144
  * Get path from value of "background-image"
135
- *
145
+ * @param value
136
146
  */
137
147
  function getBackgroundImagePath(value) {
138
148
  const origin = `${location.protocol}//${location.hostname}${location.port ? `:${location.port}` : ''}`;
package/dist/get.d.ts CHANGED
@@ -1,2 +1,9 @@
1
1
  import type { Filter, FrozenPattyData } from './types.js';
2
+ /**
3
+ *
4
+ * @param el
5
+ * @param attr
6
+ * @param typeConvert
7
+ * @param filter
8
+ */
2
9
  export default function (el: Element, attr: string, typeConvert: boolean, filter?: Filter): FrozenPattyData;
package/dist/get.js CHANGED
@@ -1,5 +1,12 @@
1
1
  import { getValues } from './get-values.js';
2
2
  import { arrayToHash } from './utils.js';
3
+ /**
4
+ *
5
+ * @param el
6
+ * @param attr
7
+ * @param typeConvert
8
+ * @param filter
9
+ */
3
10
  export default function (el, attr, typeConvert, filter) {
4
11
  // eslint-disable-next-line unicorn/prefer-spread
5
12
  const filedElements = Array.from(el.querySelectorAll(`[data-${attr}]`));
package/dist/index.d.ts CHANGED
@@ -2,8 +2,12 @@ import type { FrozenPattyOptions } from './frozen-patty.js';
2
2
  import FrozenPatty from './frozen-patty.js';
3
3
  /**
4
4
  * Pure HTML to JSON converter that not use template engine.
5
- *
6
5
  * @param html Original HTML
7
6
  * @param options Options
8
7
  */
8
+ /**
9
+ *
10
+ * @param html
11
+ * @param options
12
+ */
9
13
  export default function frozenPatty(html: string, options?: FrozenPattyOptions): FrozenPatty;
package/dist/index.js CHANGED
@@ -1,10 +1,14 @@
1
1
  import FrozenPatty from './frozen-patty.js';
2
2
  /**
3
3
  * Pure HTML to JSON converter that not use template engine.
4
- *
5
4
  * @param html Original HTML
6
5
  * @param options Options
7
6
  */
7
+ /**
8
+ *
9
+ * @param html
10
+ * @param options
11
+ */
8
12
  export default function frozenPatty(html, options) {
9
13
  return new FrozenPatty(html, options);
10
14
  }
@@ -5,10 +5,10 @@ import type { Filter, PrimitiveDatum } from './types.js';
5
5
  * ```html
6
6
  * <div [target-attribute] data-[attr]="[name]:[target-attribute]"></div>
7
7
  * ```
8
- *
9
8
  * @param el A target element
10
9
  * @param name A label name
11
10
  * @param datum A datum of value
12
11
  * @param attr Data attribute name for specifying the node that FrozenPatty treats as a field
12
+ * @param filter
13
13
  */
14
14
  export declare function setValue(el: Element, name: string, datum: PrimitiveDatum, attr?: string, filter?: Filter): void;
package/dist/set-value.js CHANGED
@@ -4,11 +4,11 @@
4
4
  * ```html
5
5
  * <div [target-attribute] data-[attr]="[name]:[target-attribute]"></div>
6
6
  * ```
7
- *
8
7
  * @param el A target element
9
8
  * @param name A label name
10
9
  * @param datum A datum of value
11
10
  * @param attr Data attribute name for specifying the node that FrozenPatty treats as a field
11
+ * @param filter
12
12
  */
13
13
  export function setValue(el, name, datum, attr = 'field', filter) {
14
14
  const bindingFormats = el.getAttribute(`data-${attr}`) || '';
@@ -107,11 +107,9 @@ export function setValue(el, name, datum, attr = 'field', filter) {
107
107
  }
108
108
  /**
109
109
  * Set attribute
110
- *
111
110
  * @param el Target HTML element
112
111
  * @param attr Attribute name
113
112
  * @param datum Datum
114
- *
115
113
  */
116
114
  function setAttribute(el, attr, datum) {
117
115
  if (datum == null) {
@@ -673,6 +671,10 @@ function setAttribute(el, attr, datum) {
673
671
  }
674
672
  }
675
673
  }
674
+ /**
675
+ *
676
+ * @param datum
677
+ */
676
678
  function toNum(datum) {
677
679
  let i;
678
680
  if (typeof datum === 'boolean') {
@@ -686,6 +688,10 @@ function toNum(datum) {
686
688
  }
687
689
  return i;
688
690
  }
691
+ /**
692
+ *
693
+ * @param datum
694
+ */
689
695
  function toInt(datum) {
690
696
  return Math.floor(toNum(datum));
691
697
  }
package/dist/set.d.ts CHANGED
@@ -1,2 +1,9 @@
1
1
  import type { Filter, FrozenPattyData } from './types.js';
2
+ /**
3
+ *
4
+ * @param el
5
+ * @param data
6
+ * @param attr
7
+ * @param filter
8
+ */
2
9
  export default function (el: Element, data: FrozenPattyData, attr: string, filter?: Filter): Element;
package/dist/set.js CHANGED
@@ -1,4 +1,11 @@
1
1
  import { setValue } from './set-value.js';
2
+ /**
3
+ *
4
+ * @param el
5
+ * @param data
6
+ * @param attr
7
+ * @param filter
8
+ */
2
9
  export default function (el, data, attr, filter) {
3
10
  el = el.cloneNode(true);
4
11
  for (const dataKeyName in data) {
package/dist/utils.d.ts CHANGED
@@ -1,4 +1,8 @@
1
1
  import type { FrozenPattyData, PrimitiveDatum } from './types.js';
2
+ /**
3
+ *
4
+ * @param kvs
5
+ */
2
6
  export declare function arrayToHash(kvs: [keyof FrozenPattyData, PrimitiveDatum, boolean][]): {
3
7
  [index: string]: PrimitiveDatum | PrimitiveDatum[];
4
8
  };
package/dist/utils.js CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ *
3
+ * @param kvs
4
+ */
1
5
  export function arrayToHash(kvs) {
2
6
  const result = {};
3
7
  for (const kv of kvs) {
package/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "@burger-editor/frozen-patty",
3
- "version": "0.11.0",
3
+ "version": "3.5.0-alpha.2",
4
4
  "description": "Pure HTML to JSON converter that not use template engine.",
5
5
  "author": "D-ZERO",
6
6
  "license": "MIT",
7
7
  "repository": {
8
- "url": "https://github.com/d-zero-dev/burger-editor.git"
8
+ "url": "https://github.com/d-zero-dev/BurgerEditor.git"
9
9
  },
10
- "private": false,
11
10
  "publishConfig": {
12
11
  "access": "public"
13
12
  },
@@ -37,8 +36,9 @@
37
36
  "dist"
38
37
  ],
39
38
  "scripts": {
40
- "build": "tsc",
39
+ "build": "tsc --project tsconfig.build.json",
40
+ "dev": "tsc --watch --project tsconfig.build.json",
41
41
  "clean": "tsc --build --clean"
42
42
  },
43
- "gitHead": "3cc9deb4a7316211f6d75cc14c346775bdb4f907"
43
+ "gitHead": "e0a04e324f527c32231095ed0f46c3dbd2c9993f"
44
44
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2017-2024 D-ZERO Co., Ltd.
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.