@micromag/cli 0.3.508 → 0.3.510

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.
Files changed (3) hide show
  1. package/bin/export.js +98 -66
  2. package/lib/index.js +98 -66
  3. package/package.json +14 -14
package/bin/export.js CHANGED
@@ -8,7 +8,6 @@ var core = require('@micromag/core');
8
8
  var screensManager = require('@micromag/screens');
9
9
  var FieldsManager = require('@micromag/fields');
10
10
  var transforms = require('@micromag/transforms');
11
- var tslib = require('tslib');
12
11
  var path = require('path');
13
12
  var puppeteer = require('puppeteer');
14
13
  var nodeFetch = require('node-fetch');
@@ -20,83 +19,116 @@ var Viewer = require('@micromag/viewer');
20
19
 
21
20
  const readJSON = file => fsExtra.readJsonSync(file);
22
21
 
22
+ // Regexps involved with splitting words in various case formats.
23
+ const SPLIT_LOWER_UPPER_RE = /([\p{Ll}\d])(\p{Lu})/gu;
24
+ const SPLIT_UPPER_UPPER_RE = /(\p{Lu})([\p{Lu}][\p{Ll}])/gu;
25
+ // Used to iterate over the initial split result and separate numbers.
26
+ const SPLIT_SEPARATE_NUMBER_RE = /(\d)\p{Ll}|(\p{L})\d/u;
27
+ // Regexp involved with stripping non-word characters from the result.
28
+ const DEFAULT_STRIP_REGEXP = /[^\p{L}\d]+/giu;
29
+ // The replacement value for splits.
30
+ const SPLIT_REPLACE_VALUE = "$1\0$2";
31
+ // The default characters to keep after transforming case.
32
+ const DEFAULT_PREFIX_SUFFIX_CHARACTERS = "";
23
33
  /**
24
- * Source: ftp://ftp.unicode.org/Public/UCD/latest/ucd/SpecialCasing.txt
34
+ * Split any cased input strings into an array of words.
25
35
  */
26
- /**
27
- * Lower case as a function.
28
- */
29
- function lowerCase(str) {
30
- return str.toLowerCase();
36
+ function split(value) {
37
+ let result = value.trim();
38
+ result = result
39
+ .replace(SPLIT_LOWER_UPPER_RE, SPLIT_REPLACE_VALUE)
40
+ .replace(SPLIT_UPPER_UPPER_RE, SPLIT_REPLACE_VALUE);
41
+ result = result.replace(DEFAULT_STRIP_REGEXP, "\0");
42
+ let start = 0;
43
+ let end = result.length;
44
+ // Trim the delimiter from around the output string.
45
+ while (result.charAt(start) === "\0")
46
+ start++;
47
+ if (start === end)
48
+ return [];
49
+ while (result.charAt(end - 1) === "\0")
50
+ end--;
51
+ return result.slice(start, end).split(/\0/g);
31
52
  }
32
-
33
- // Support camel case ("camelCase" -> "camel Case" and "CAMELCase" -> "CAMEL Case").
34
- var DEFAULT_SPLIT_REGEXP = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g];
35
- // Remove all non-word characters.
36
- var DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi;
37
53
  /**
38
- * Normalize the string into something other libraries can manipulate easier.
54
+ * Split the input string into an array of words, separating numbers.
39
55
  */
40
- function noCase(input, options) {
41
- if (options === void 0) {
42
- options = {};
43
- }
44
- var _a = options.splitRegexp,
45
- splitRegexp = _a === void 0 ? DEFAULT_SPLIT_REGEXP : _a,
46
- _b = options.stripRegexp,
47
- stripRegexp = _b === void 0 ? DEFAULT_STRIP_REGEXP : _b,
48
- _c = options.transform,
49
- transform = _c === void 0 ? lowerCase : _c,
50
- _d = options.delimiter,
51
- delimiter = _d === void 0 ? " " : _d;
52
- var result = replace(replace(input, splitRegexp, "$1\0$2"), stripRegexp, "\0");
53
- var start = 0;
54
- var end = result.length;
55
- // Trim the delimiter from around the output string.
56
- while (result.charAt(start) === "\0") start++;
57
- while (result.charAt(end - 1) === "\0") end--;
58
- // Transform each token independently.
59
- return result.slice(start, end).split("\0").map(transform).join(delimiter);
56
+ function splitSeparateNumbers(value) {
57
+ const words = split(value);
58
+ for (let i = 0; i < words.length; i++) {
59
+ const word = words[i];
60
+ const match = SPLIT_SEPARATE_NUMBER_RE.exec(word);
61
+ if (match) {
62
+ const offset = match.index + (match[1] ?? match[2]).length;
63
+ words.splice(i, 1, word.slice(0, offset), word.slice(offset));
64
+ }
65
+ }
66
+ return words;
60
67
  }
61
68
  /**
62
- * Replace `re` in the input string with the replacement value.
69
+ * Convert a string to camel case (`fooBar`).
63
70
  */
64
- function replace(input, re, value) {
65
- if (re instanceof RegExp) return input.replace(re, value);
66
- return re.reduce(function (input, re) {
67
- return input.replace(re, value);
68
- }, input);
71
+ function camelCase(input, options) {
72
+ const [prefix, words, suffix] = splitPrefixSuffix(input, options);
73
+ const lower = lowerFactory(options?.locale);
74
+ const upper = upperFactory(options?.locale);
75
+ const transform = options?.mergeAmbiguousCharacters
76
+ ? capitalCaseTransformFactory(lower, upper)
77
+ : pascalCaseTransformFactory(lower, upper);
78
+ return (prefix +
79
+ words
80
+ .map((word, index) => {
81
+ if (index === 0)
82
+ return lower(word);
83
+ return transform(word, index);
84
+ })
85
+ .join(options?.delimiter ?? "") +
86
+ suffix);
69
87
  }
70
-
71
- function pascalCaseTransform(input, index) {
72
- var firstChar = input.charAt(0);
73
- var lowerChars = input.substr(1).toLowerCase();
74
- if (index > 0 && firstChar >= "0" && firstChar <= "9") {
75
- return "_" + firstChar + lowerChars;
76
- }
77
- return "" + firstChar.toUpperCase() + lowerChars;
88
+ function lowerFactory(locale) {
89
+ return locale === false
90
+ ? (input) => input.toLowerCase()
91
+ : (input) => input.toLocaleLowerCase(locale);
78
92
  }
79
- function pascalCase(input, options) {
80
- if (options === void 0) {
81
- options = {};
82
- }
83
- return noCase(input, tslib.__assign({
84
- delimiter: "",
85
- transform: pascalCaseTransform
86
- }, options));
93
+ function upperFactory(locale) {
94
+ return locale === false
95
+ ? (input) => input.toUpperCase()
96
+ : (input) => input.toLocaleUpperCase(locale);
87
97
  }
88
-
89
- function camelCaseTransform(input, index) {
90
- if (index === 0) return input.toLowerCase();
91
- return pascalCaseTransform(input, index);
98
+ function capitalCaseTransformFactory(lower, upper) {
99
+ return (word) => `${upper(word[0])}${lower(word.slice(1))}`;
92
100
  }
93
- function camelCase(input, options) {
94
- if (options === void 0) {
95
- options = {};
96
- }
97
- return pascalCase(input, tslib.__assign({
98
- transform: camelCaseTransform
99
- }, options));
101
+ function pascalCaseTransformFactory(lower, upper) {
102
+ return (word, index) => {
103
+ const char0 = word[0];
104
+ const initial = index > 0 && char0 >= "0" && char0 <= "9" ? "_" + char0 : upper(char0);
105
+ return initial + lower(word.slice(1));
106
+ };
107
+ }
108
+ function splitPrefixSuffix(input, options = {}) {
109
+ const splitFn = options.split ?? (options.separateNumbers ? splitSeparateNumbers : split);
110
+ const prefixCharacters = options.prefixCharacters ?? DEFAULT_PREFIX_SUFFIX_CHARACTERS;
111
+ const suffixCharacters = options.suffixCharacters ?? DEFAULT_PREFIX_SUFFIX_CHARACTERS;
112
+ let prefixIndex = 0;
113
+ let suffixIndex = input.length;
114
+ while (prefixIndex < input.length) {
115
+ const char = input.charAt(prefixIndex);
116
+ if (!prefixCharacters.includes(char))
117
+ break;
118
+ prefixIndex++;
119
+ }
120
+ while (suffixIndex > prefixIndex) {
121
+ const index = suffixIndex - 1;
122
+ const char = input.charAt(index);
123
+ if (!suffixCharacters.includes(char))
124
+ break;
125
+ suffixIndex = index;
126
+ }
127
+ return [
128
+ input.slice(0, prefixIndex),
129
+ splitFn(input.slice(prefixIndex, suffixIndex)),
130
+ input.slice(suffixIndex),
131
+ ];
100
132
  }
101
133
 
102
134
  const transformStory = (story, format) => {
package/lib/index.js CHANGED
@@ -7,7 +7,6 @@ var core = require('@micromag/core');
7
7
  var screensManager = require('@micromag/screens');
8
8
  var FieldsManager = require('@micromag/fields');
9
9
  var transforms = require('@micromag/transforms');
10
- var tslib = require('tslib');
11
10
  var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
12
11
  var path = require('path');
13
12
  var puppeteer = require('puppeteer');
@@ -19,83 +18,116 @@ var React = require('react');
19
18
  var ReactDOMServer = require('react-dom/server');
20
19
  var Viewer = require('@micromag/viewer');
21
20
 
21
+ // Regexps involved with splitting words in various case formats.
22
+ const SPLIT_LOWER_UPPER_RE = /([\p{Ll}\d])(\p{Lu})/gu;
23
+ const SPLIT_UPPER_UPPER_RE = /(\p{Lu})([\p{Lu}][\p{Ll}])/gu;
24
+ // Used to iterate over the initial split result and separate numbers.
25
+ const SPLIT_SEPARATE_NUMBER_RE = /(\d)\p{Ll}|(\p{L})\d/u;
26
+ // Regexp involved with stripping non-word characters from the result.
27
+ const DEFAULT_STRIP_REGEXP = /[^\p{L}\d]+/giu;
28
+ // The replacement value for splits.
29
+ const SPLIT_REPLACE_VALUE = "$1\0$2";
30
+ // The default characters to keep after transforming case.
31
+ const DEFAULT_PREFIX_SUFFIX_CHARACTERS = "";
22
32
  /**
23
- * Source: ftp://ftp.unicode.org/Public/UCD/latest/ucd/SpecialCasing.txt
33
+ * Split any cased input strings into an array of words.
24
34
  */
25
- /**
26
- * Lower case as a function.
27
- */
28
- function lowerCase(str) {
29
- return str.toLowerCase();
35
+ function split(value) {
36
+ let result = value.trim();
37
+ result = result
38
+ .replace(SPLIT_LOWER_UPPER_RE, SPLIT_REPLACE_VALUE)
39
+ .replace(SPLIT_UPPER_UPPER_RE, SPLIT_REPLACE_VALUE);
40
+ result = result.replace(DEFAULT_STRIP_REGEXP, "\0");
41
+ let start = 0;
42
+ let end = result.length;
43
+ // Trim the delimiter from around the output string.
44
+ while (result.charAt(start) === "\0")
45
+ start++;
46
+ if (start === end)
47
+ return [];
48
+ while (result.charAt(end - 1) === "\0")
49
+ end--;
50
+ return result.slice(start, end).split(/\0/g);
30
51
  }
31
-
32
- // Support camel case ("camelCase" -> "camel Case" and "CAMELCase" -> "CAMEL Case").
33
- var DEFAULT_SPLIT_REGEXP = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g];
34
- // Remove all non-word characters.
35
- var DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi;
36
52
  /**
37
- * Normalize the string into something other libraries can manipulate easier.
53
+ * Split the input string into an array of words, separating numbers.
38
54
  */
39
- function noCase(input, options) {
40
- if (options === void 0) {
41
- options = {};
42
- }
43
- var _a = options.splitRegexp,
44
- splitRegexp = _a === void 0 ? DEFAULT_SPLIT_REGEXP : _a,
45
- _b = options.stripRegexp,
46
- stripRegexp = _b === void 0 ? DEFAULT_STRIP_REGEXP : _b,
47
- _c = options.transform,
48
- transform = _c === void 0 ? lowerCase : _c,
49
- _d = options.delimiter,
50
- delimiter = _d === void 0 ? " " : _d;
51
- var result = replace(replace(input, splitRegexp, "$1\0$2"), stripRegexp, "\0");
52
- var start = 0;
53
- var end = result.length;
54
- // Trim the delimiter from around the output string.
55
- while (result.charAt(start) === "\0") start++;
56
- while (result.charAt(end - 1) === "\0") end--;
57
- // Transform each token independently.
58
- return result.slice(start, end).split("\0").map(transform).join(delimiter);
55
+ function splitSeparateNumbers(value) {
56
+ const words = split(value);
57
+ for (let i = 0; i < words.length; i++) {
58
+ const word = words[i];
59
+ const match = SPLIT_SEPARATE_NUMBER_RE.exec(word);
60
+ if (match) {
61
+ const offset = match.index + (match[1] ?? match[2]).length;
62
+ words.splice(i, 1, word.slice(0, offset), word.slice(offset));
63
+ }
64
+ }
65
+ return words;
59
66
  }
60
67
  /**
61
- * Replace `re` in the input string with the replacement value.
68
+ * Convert a string to camel case (`fooBar`).
62
69
  */
63
- function replace(input, re, value) {
64
- if (re instanceof RegExp) return input.replace(re, value);
65
- return re.reduce(function (input, re) {
66
- return input.replace(re, value);
67
- }, input);
70
+ function camelCase(input, options) {
71
+ const [prefix, words, suffix] = splitPrefixSuffix(input, options);
72
+ const lower = lowerFactory(options?.locale);
73
+ const upper = upperFactory(options?.locale);
74
+ const transform = options?.mergeAmbiguousCharacters
75
+ ? capitalCaseTransformFactory(lower, upper)
76
+ : pascalCaseTransformFactory(lower, upper);
77
+ return (prefix +
78
+ words
79
+ .map((word, index) => {
80
+ if (index === 0)
81
+ return lower(word);
82
+ return transform(word, index);
83
+ })
84
+ .join(options?.delimiter ?? "") +
85
+ suffix);
68
86
  }
69
-
70
- function pascalCaseTransform(input, index) {
71
- var firstChar = input.charAt(0);
72
- var lowerChars = input.substr(1).toLowerCase();
73
- if (index > 0 && firstChar >= "0" && firstChar <= "9") {
74
- return "_" + firstChar + lowerChars;
75
- }
76
- return "" + firstChar.toUpperCase() + lowerChars;
87
+ function lowerFactory(locale) {
88
+ return locale === false
89
+ ? (input) => input.toLowerCase()
90
+ : (input) => input.toLocaleLowerCase(locale);
77
91
  }
78
- function pascalCase(input, options) {
79
- if (options === void 0) {
80
- options = {};
81
- }
82
- return noCase(input, tslib.__assign({
83
- delimiter: "",
84
- transform: pascalCaseTransform
85
- }, options));
92
+ function upperFactory(locale) {
93
+ return locale === false
94
+ ? (input) => input.toUpperCase()
95
+ : (input) => input.toLocaleUpperCase(locale);
86
96
  }
87
-
88
- function camelCaseTransform(input, index) {
89
- if (index === 0) return input.toLowerCase();
90
- return pascalCaseTransform(input, index);
97
+ function capitalCaseTransformFactory(lower, upper) {
98
+ return (word) => `${upper(word[0])}${lower(word.slice(1))}`;
91
99
  }
92
- function camelCase(input, options) {
93
- if (options === void 0) {
94
- options = {};
95
- }
96
- return pascalCase(input, tslib.__assign({
97
- transform: camelCaseTransform
98
- }, options));
100
+ function pascalCaseTransformFactory(lower, upper) {
101
+ return (word, index) => {
102
+ const char0 = word[0];
103
+ const initial = index > 0 && char0 >= "0" && char0 <= "9" ? "_" + char0 : upper(char0);
104
+ return initial + lower(word.slice(1));
105
+ };
106
+ }
107
+ function splitPrefixSuffix(input, options = {}) {
108
+ const splitFn = options.split ?? (options.separateNumbers ? splitSeparateNumbers : split);
109
+ const prefixCharacters = options.prefixCharacters ?? DEFAULT_PREFIX_SUFFIX_CHARACTERS;
110
+ const suffixCharacters = options.suffixCharacters ?? DEFAULT_PREFIX_SUFFIX_CHARACTERS;
111
+ let prefixIndex = 0;
112
+ let suffixIndex = input.length;
113
+ while (prefixIndex < input.length) {
114
+ const char = input.charAt(prefixIndex);
115
+ if (!prefixCharacters.includes(char))
116
+ break;
117
+ prefixIndex++;
118
+ }
119
+ while (suffixIndex > prefixIndex) {
120
+ const index = suffixIndex - 1;
121
+ const char = input.charAt(index);
122
+ if (!suffixCharacters.includes(char))
123
+ break;
124
+ suffixIndex = index;
125
+ }
126
+ return [
127
+ input.slice(0, prefixIndex),
128
+ splitFn(input.slice(prefixIndex, suffixIndex)),
129
+ input.slice(suffixIndex),
130
+ ];
99
131
  }
100
132
 
101
133
  var transformStory = function transformStory(story, format) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micromag/cli",
3
- "version": "0.3.508",
3
+ "version": "0.3.510",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [
@@ -47,21 +47,21 @@
47
47
  },
48
48
  "dependencies": {
49
49
  "@babel/runtime": "^7.13.10",
50
- "@micromag/core": "^0.3.508",
51
- "@micromag/elements": "^0.3.508",
52
- "@micromag/fields": "^0.3.508",
53
- "@micromag/screens": "^0.3.508",
54
- "@micromag/transforms": "^0.3.508",
55
- "@micromag/viewer": "^0.3.508",
56
- "@micromag/viewer-build": "^0.3.508",
57
- "change-case": "^4.0.0",
50
+ "@micromag/core": "^0.3.509",
51
+ "@micromag/elements": "^0.3.509",
52
+ "@micromag/fields": "^0.3.510",
53
+ "@micromag/screens": "^0.3.509",
54
+ "@micromag/transforms": "^0.3.509",
55
+ "@micromag/viewer": "^0.3.509",
56
+ "@micromag/viewer-build": "^0.3.509",
57
+ "change-case": "^5.4.4",
58
58
  "classnames": "^2.2.6",
59
- "commander": "^8.3.0",
59
+ "commander": "^12.0.0",
60
60
  "express": "^4.17.1",
61
- "fs-extra": "^10.0.0",
62
- "get-port": "^5.1.1",
61
+ "fs-extra": "^11.2.0",
62
+ "get-port": "^7.1.0",
63
63
  "lodash": "^4.17.21",
64
- "node-fetch": "^2.6.1",
64
+ "node-fetch": "^3.3.2",
65
65
  "prop-types": "^15.7.2",
66
66
  "puppeteer": "^9.1.1",
67
67
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0",
@@ -71,5 +71,5 @@
71
71
  "access": "public",
72
72
  "registry": "https://registry.npmjs.org/"
73
73
  },
74
- "gitHead": "9baca9a69d472a9bcdfd35d0ebcd833595492ba4"
74
+ "gitHead": "6758a559b76df2a0f5912ddad0b88b6bd910a2f5"
75
75
  }