@canopycanopycanopy/b-ber-grammar-attributes 3.0.8-nav-memo.4 → 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");
@@ -131,7 +131,7 @@ const parseAttrs = s => {
131
131
  exports.parseAttrs = parseAttrs;
132
132
  const _buildAttrString = (obj, reference) => {
133
133
  var _context;
134
- 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, '');
135
135
  };
136
136
 
137
137
  // -> ?foo=bar&baz=bat
@@ -141,7 +141,7 @@ const _buildAttrQueryString = (obj, reference) => {
141
141
  return (0, _reduce.default)(_context2 = (0, _entries.default)(obj)).call(_context2, (acc, [key, val]) => {
142
142
  const prefix = acc.length ? '&' : '?';
143
143
  const encodedVal = encodeURIComponent(_bBerLib.Url.ensureDecoded(val));
144
- 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;
145
145
  }, '');
146
146
  };
147
147
 
@@ -160,7 +160,7 @@ const _extendWithDefaults = (obj, genus) => {
160
160
  if (order === 'block') {
161
161
  result.epubTypes = taxonomy;
162
162
  }
163
- if ((0, _lodash.default)(obj, 'classes')) {
163
+ if ((0, _has.default)(obj, 'classes')) {
164
164
  taxonomy = `${_lookUpFamily(result.classes)} ${genus}`;
165
165
  if (order === 'block') {
166
166
  result.epubTypes = taxonomy;
@@ -171,7 +171,7 @@ const _extendWithDefaults = (obj, genus) => {
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-memo.4+d47a9aae",
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-memo.4+d47a9aae",
21
- "@canopycanopycanopy/b-ber-logger": "3.0.8-nav-memo.4+d47a9aae",
22
- "@canopycanopycanopy/b-ber-shapes-directives": "3.0.8-nav-memo.4+d47a9aae",
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": "d47a9aae74dec3e3225e363b2434c7abe0fcf21b"
50
+ "gitHead": "2bbec5643278f53becb0d2ba1f55edfe379d5587"
53
51
  }