@canopycanopycanopy/b-ber-grammar-attributes 3.0.8-nav.0 → 3.0.8-next.61

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,9 +1,29 @@
1
- # `@canopycanopycanopy/b-ber-grammar-attributes`
1
+ # b-ber-grammar-attributes
2
2
 
3
- The `b-ber-grammar-attributes` package is used internally by b-ber to parse the attributes of custom Markdown extensions.
3
+ Shared attribute parsing and serialization utilities used by every other grammar package. This package does not handle a single Markdown directive on its own; instead it provides the functions that all directive handlers call to parse b-ber's inline attribute syntax (`key:value key2:"value with spaces"`) into plain objects, validate and filter those attributes against the allowed set for each directive type (using `b-ber-shapes-directives`), extend them with EPUB-required defaults (epub:type class taxonomy derived from frontmatter/bodymatter/backmatter classification), and serialize them back into HTML attribute strings or URL query strings for iframe embeds.
4
4
 
5
- ## Install
5
+ ## Usage
6
+
7
+ Imported by every grammar package:
8
+
9
+ ```js
10
+ import {
11
+ attributes,
12
+ attributesObject,
13
+ attributesString,
14
+ attributesQueryString,
15
+ htmlId,
16
+ parseAttrs,
17
+ toAlias,
18
+ } from '@canopycanopycanopy/b-ber-grammar-attributes'
19
+ ```
20
+
21
+ This package is not consumed directly by `b-ber-tasks` or end-user Markdown — it is a shared utility layer across the grammar pipeline.
22
+
23
+ ## Dev
6
24
 
7
25
  ```
8
- $ npm i -g @canopycanopycanopy/b-ber-grammar-attributes
26
+ npm test
9
27
  ```
28
+
29
+ Tests are in `__tests__/index.test.js` and cover `parseAttrs`, `attributesObject`, `attributesString`, `attributesQueryString`, `htmlId`, and `toAlias`.
package/dist/index.js CHANGED
@@ -19,7 +19,7 @@ var _reduce = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-sta
19
19
  var _entries = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/entries"));
20
20
  var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
21
21
  var _path = _interopRequireDefault(require("path"));
22
- var _lodash = _interopRequireDefault(require("lodash.has"));
22
+ var _has = _interopRequireDefault(require("lodash/has"));
23
23
  var _bBerLib = require("@canopycanopycanopy/b-ber-lib");
24
24
  var _bBerLogger = _interopRequireDefault(require("@canopycanopycanopy/b-ber-logger"));
25
25
  var _bBerShapesDirectives = require("@canopycanopycanopy/b-ber-shapes-directives");
@@ -32,6 +32,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _co
32
32
  // Class -> Order -> Family -> Genus
33
33
  // element -> block -> frontmatter -> preface
34
34
  //
35
+
35
36
  const _lookUpFamily = genus => _bBerShapesDirectives.FRONTMATTER_DIRECTIVES.has(genus) ? 'frontmatter' : _bBerShapesDirectives.BODYMATTER_DIRECTIVES.has(genus) ? 'bodymatter' : _bBerShapesDirectives.BACKMATTER_DIRECTIVES.has(genus) ? 'backmatter' : '';
36
37
 
37
38
  // Determine the directive's classification and parent's type
@@ -130,7 +131,7 @@ const parseAttrs = s => {
130
131
  exports.parseAttrs = parseAttrs;
131
132
  const _buildAttrString = (obj, reference) => {
132
133
  var _context;
133
- return (0, _reduce.default)(_context = (0, _entries.default)(obj)).call(_context, (acc, [key, val]) => !reference || (0, _lodash.default)(reference, key) ? (0, _concat.default)(acc).call(acc, _applyTransforms(key, val)) : acc, '');
134
+ return (0, _reduce.default)(_context = (0, _entries.default)(obj)).call(_context, (acc, [key, val]) => !reference || (0, _has.default)(reference, key) ? (0, _concat.default)(acc).call(acc, _applyTransforms(key, val)) : acc, '');
134
135
  };
135
136
 
136
137
  // -> ?foo=bar&baz=bat
@@ -140,7 +141,7 @@ const _buildAttrQueryString = (obj, reference) => {
140
141
  return (0, _reduce.default)(_context2 = (0, _entries.default)(obj)).call(_context2, (acc, [key, val]) => {
141
142
  const prefix = acc.length ? '&amp;' : '?';
142
143
  const encodedVal = encodeURIComponent(_bBerLib.Url.ensureDecoded(val));
143
- return !reference || (0, _lodash.default)(reference, key) ? (0, _concat.default)(acc).call(acc, `${prefix}${key}=${encodedVal}`) : acc;
144
+ return !reference || (0, _has.default)(reference, key) ? (0, _concat.default)(acc).call(acc, `${prefix}${key}=${encodedVal}`) : acc;
144
145
  }, '');
145
146
  };
146
147
 
@@ -159,7 +160,7 @@ const _extendWithDefaults = (obj, genus) => {
159
160
  if (order === 'block') {
160
161
  result.epubTypes = taxonomy;
161
162
  }
162
- if ((0, _lodash.default)(obj, 'classes')) {
163
+ if ((0, _has.default)(obj, 'classes')) {
163
164
  taxonomy = `${_lookUpFamily(result.classes)} ${genus}`;
164
165
  if (order === 'block') {
165
166
  result.epubTypes = taxonomy;
@@ -168,10 +169,9 @@ const _extendWithDefaults = (obj, genus) => {
168
169
  } else {
169
170
  result.classes = taxonomy; // -> class="bodymatter chapter"
170
171
  }
171
-
172
172
  return result;
173
173
  case 'inline':
174
- if (_requiresAltTag(genus) && !(0, _lodash.default)(obj, 'alt')) {
174
+ if (_requiresAltTag(genus) && !(0, _has.default)(obj, 'alt')) {
175
175
  result.alt = result.source;
176
176
  }
177
177
  return result;
@@ -220,7 +220,7 @@ const attributesObject = (attrs, origGenus, context = {}) => {
220
220
  // specification). do this to keep styling consistent
221
221
 
222
222
  if (genus !== origGenus) {
223
- if ((0, _lodash.default)(attrsObject, 'classes')) {
223
+ if ((0, _has.default)(attrsObject, 'classes')) {
224
224
  attrsObject.classes += ` ${origGenus}`;
225
225
  } else {
226
226
  attrsObject.classes = origGenus;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canopycanopycanopy/b-ber-grammar-attributes",
3
- "version": "3.0.8-nav.0+24db1e6b",
3
+ "version": "3.0.8-next.61+2bbec564",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -17,12 +17,10 @@
17
17
  "access": "public"
18
18
  },
19
19
  "dependencies": {
20
- "@canopycanopycanopy/b-ber-lib": "3.0.8-nav.0+24db1e6b",
21
- "@canopycanopycanopy/b-ber-logger": "3.0.8-nav.0+24db1e6b",
22
- "@canopycanopycanopy/b-ber-shapes-directives": "3.0.8-nav.0+24db1e6b",
23
- "lodash": "^4.17.21",
24
- "lodash.has": "latest",
25
- "tar": "^6.1.11"
20
+ "@canopycanopycanopy/b-ber-lib": "3.0.8-next.61+2bbec564",
21
+ "@canopycanopycanopy/b-ber-logger": "3.0.8-next.61+2bbec564",
22
+ "@canopycanopycanopy/b-ber-shapes-directives": "3.0.8-next.61+2bbec564",
23
+ "lodash": "^4.17.21"
26
24
  },
27
25
  "devDependencies": {
28
26
  "@babel/cli": "^7.10.5",
@@ -49,5 +47,5 @@
49
47
  "url": "https://maxwellsimmer.com"
50
48
  }
51
49
  ],
52
- "gitHead": "24db1e6bb491faae0d52c6dadc09d974a5a31cf5"
50
+ "gitHead": "2bbec5643278f53becb0d2ba1f55edfe379d5587"
53
51
  }