js-build-tools 3.0.0 → 3.0.1

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 (63) hide show
  1. package/dist/build.js +59 -59
  2. package/dist/bundle.js +12 -12
  3. package/dist/bundleLint.js +17 -17
  4. package/dist/bundleMinify.js +8 -8
  5. package/dist/copyFonts.js +8 -8
  6. package/dist/default.js +15 -15
  7. package/dist/distLint.js +17 -17
  8. package/dist/distMinify.js +8 -8
  9. package/dist/partials/addToReadme.js +13 -13
  10. package/dist/partials/beginWatcher.js +9 -9
  11. package/dist/partials/distFor.js +16 -16
  12. package/dist/partials/distForSrc.js +9 -9
  13. package/dist/partials/distSeries.js +19 -19
  14. package/dist/partials/imagesFor.js +27 -27
  15. package/dist/partials/readmeTemplate.js +11 -11
  16. package/dist/partials/runOnChange.js +27 -27
  17. package/dist/partials/sassFor.js +20 -20
  18. package/dist/partials/tsFor.js +20 -20
  19. package/dist/partials.js +34 -34
  20. package/dist/test-helpers/setUp.js +51 -51
  21. package/dist/testFull.js +17 -17
  22. package/dist/testHelpers.js +8 -8
  23. package/dist/testQuick.js +19 -19
  24. package/dist/utilities/dotGet.js +42 -42
  25. package/dist/utilities/dotNotate.js +50 -50
  26. package/dist/utilities/dotSet.js +36 -36
  27. package/dist/utilities/isObject.js +4 -4
  28. package/dist/utilities/strAfter.js +14 -0
  29. package/dist/utilities/strBefore.js +14 -0
  30. package/dist/watchTest.js +13 -13
  31. package/functions/utilities/dotGet.js +2 -2
  32. package/functions/utilities/dotSet.js +2 -2
  33. package/functions/utilities/strAfter.js +13 -0
  34. package/functions/utilities/strBefore.js +13 -0
  35. package/package.json +3 -3
  36. package/vendor/array-union/index.js +30 -30
  37. package/vendor/easy-transform-stream/index.js +54 -58
  38. package/vendor/globby/gitignore.js +96 -100
  39. package/vendor/globby/index.js +191 -195
  40. package/vendor/globby/stream-utils.js +57 -57
  41. package/vendor/globby/to-path.js +19 -19
  42. package/vendor/gulp-plugin-extras/index.js +42 -46
  43. package/vendor/gulp-plugin-extras/plugin-error.js +144 -144
  44. package/vendor/ignore/index.js +467 -467
  45. package/vendor/imagemin/index.js +90 -94
  46. package/vendor/imagemin-gifsicle/index.js +33 -37
  47. package/vendor/imagemin-mozjpeg/index.js +100 -104
  48. package/vendor/imagemin-mozjpeg/node_modules/execa/index.js +2 -6
  49. package/vendor/imagemin-mozjpeg/node_modules/execa/lib/kill.js +2 -2
  50. package/vendor/imagemin-mozjpeg/node_modules/execa/lib/stream.js +2 -6
  51. package/vendor/imagemin-optipng/index.js +43 -43
  52. package/vendor/imagemin-svgo/index.js +26 -26
  53. package/vendor/is-jpg/index.js +11 -11
  54. package/vendor/junk/index.js +48 -48
  55. package/vendor/mozjpeg/index.js +8 -8
  56. package/vendor/mozjpeg/lib/index.js +17 -17
  57. package/vendor/mozjpeg/package.json +49 -50
  58. package/vendor/mozjpeg/vendor/cjpeg +0 -0
  59. package/vendor/mozjpeg/vendor/source/mozjpeg.tar.gz +0 -0
  60. package/vendor/p-pipe/index.js +22 -26
  61. package/vendor/plur/index.js +31 -31
  62. package/vendor/pretty-bytes/index.js +70 -70
  63. package/vendor/slash/index.js +11 -11
@@ -1,15 +1,15 @@
1
- "use strict";
2
-
3
- require("core-js/modules/es.string.replace.js");
4
- const gulpConfig = require('../../gulp.config.js');
5
- const bundle = require('../bundle');
6
- const distSeries = require('./distSeries');
7
- const {
8
- parallel,
9
- series
10
- } = require('gulp');
11
- const testQuick = require('../testQuick');
12
-
1
+ "use strict";
2
+
3
+ require("core-js/modules/es.string.replace.js");
4
+ const gulpConfig = require('../../gulp.config.js');
5
+ const bundle = require('../bundle');
6
+ const distSeries = require('./distSeries');
7
+ const {
8
+ parallel,
9
+ series
10
+ } = require('gulp');
11
+ const testQuick = require('../testQuick');
12
+
13
13
  /**
14
14
  * Run this function when the watched files are modified.
15
15
  * 1. Find the sub-folders within src path
@@ -34,11 +34,11 @@ const testQuick = require('../testQuick');
34
34
  * @memberOf module:partials
35
35
  * @param {string} path
36
36
  * @returns {stream.Stream}
37
- */
38
- const runOnChange = path => {
39
- const useTs = gulpConfig.get('typescript.enabled');
40
- const distPath = gulpConfig.get('dist.to');
41
- const srcPath = gulpConfig.get('srcPath');
37
+ */
38
+ const runOnChange = path => {
39
+ const useTs = gulpConfig.get('typescript.enabled');
40
+ const distPath = gulpConfig.get('dist.to');
41
+ const srcPath = gulpConfig.get('srcPath');
42
42
  /**
43
43
  * 1. The original path comes in from src and is a .ts
44
44
  * 2. Discover the outgoing dist path where that file should go
@@ -46,14 +46,14 @@ const runOnChange = path => {
46
46
  * 4. Take the original path, convert to full file path in dist
47
47
  * 5. Use the dist path found previously in #2
48
48
  * 6. Use the full dist path and the dist outgoing path in distFor
49
- */
50
- const pathRegex = new RegExp("^".concat(srcPath, "(.*\\/)(.+)\\.(js|ts)$"), 'i');
51
- const distPathResult = path.replace(pathRegex, "".concat(distPath, "$1"));
52
- let distSrcPath = path;
53
- if (useTs) {
54
- distSrcPath = path.replace(pathRegex, "".concat(distPath, "$1$2.js"));
55
- }
56
- const runSeries = distSeries(distSrcPath, distPathResult, path);
57
- return gulpConfig.get('browser.enabled') ? parallel(testQuick, series(runSeries, bundle))() : series(testQuick, runSeries)();
58
- };
49
+ */
50
+ const pathRegex = new RegExp("^".concat(srcPath, "(.*\\/)(.+)\\.(js|ts)$"), 'i');
51
+ const distPathResult = path.replace(pathRegex, "".concat(distPath, "$1"));
52
+ let distSrcPath = path;
53
+ if (useTs) {
54
+ distSrcPath = path.replace(pathRegex, "".concat(distPath, "$1$2.js"));
55
+ }
56
+ const runSeries = distSeries(distSrcPath, distPathResult, path);
57
+ return gulpConfig.get('browser.enabled') ? parallel(testQuick, series(runSeries, bundle))() : series(testQuick, runSeries)();
58
+ };
59
59
  module.exports = runOnChange;
@@ -1,27 +1,27 @@
1
- "use strict";
2
-
3
- const {
4
- dest,
5
- src
6
- } = require('gulp');
7
- const gulpConfig = require('../../gulp.config.js');
8
- const cssnano = require('gulp-cssnano');
9
- const rename = require('gulp-rename');
10
- const sass = require('gulp-sass')(require('sass'));
11
-
1
+ "use strict";
2
+
3
+ const {
4
+ dest,
5
+ src
6
+ } = require('gulp');
7
+ const gulpConfig = require('../../gulp.config.js');
8
+ const cssnano = require('gulp-cssnano');
9
+ const rename = require('gulp-rename');
10
+ const sass = require('gulp-sass')(require('sass'));
11
+
12
12
  /**
13
13
  * Build the CSS for a given source pattern.
14
14
  * @memberOf module:partials
15
15
  * @param {string|array} [srcSearch='src/config/path/sass/for']
16
16
  * @param {string} [cssPath='css/config/path']
17
17
  * @returns {stream.Stream}
18
- */
19
- const sassFor = function () {
20
- let srcSearch = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : gulpConfig.get('sass.from');
21
- let cssPath = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : gulpConfig.get('sass.to');
22
- return src(srcSearch).pipe(sass().on('error', sass.logError)) // Passes it through a gulp-sass, log errors to console
23
- .pipe(dest(cssPath)).pipe(cssnano()).pipe(rename({
24
- extname: '.min.css'
25
- })).pipe(dest(cssPath));
26
- };
18
+ */
19
+ const sassFor = function () {
20
+ let srcSearch = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : gulpConfig.get('sass.from');
21
+ let cssPath = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : gulpConfig.get('sass.to');
22
+ return src(srcSearch).pipe(sass().on('error', sass.logError)) // Passes it through a gulp-sass, log errors to console
23
+ .pipe(dest(cssPath)).pipe(cssnano()).pipe(rename({
24
+ extname: '.min.css'
25
+ })).pipe(dest(cssPath));
26
+ };
27
27
  module.exports = sassFor;
@@ -1,13 +1,13 @@
1
- "use strict";
2
-
3
- const {
4
- dest,
5
- parallel,
6
- src
7
- } = require('gulp');
8
- const gulpConfig = require('../../gulp.config.js');
9
- const ts = require('gulp-typescript');
10
-
1
+ "use strict";
2
+
3
+ const {
4
+ dest,
5
+ parallel,
6
+ src
7
+ } = require('gulp');
8
+ const gulpConfig = require('../../gulp.config.js');
9
+ const ts = require('gulp-typescript');
10
+
11
11
  /**
12
12
  * Starting at the source directory, find all the ts files and convert them into the distribution directory.
13
13
  * @memberOf module:partials
@@ -15,14 +15,14 @@ const ts = require('gulp-typescript');
15
15
  * @param {string} [distPath='']
16
16
  * @returns {Function}
17
17
  * @see `https://www.typescriptlang.org/docs/handbook/gulp.html` for more info
18
- */
19
- const tsFor = function () {
20
- let srcPath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : gulpConfig.get('typescript.from');
21
- let distPath = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : gulpConfig.get('typescript.to');
22
- const declarationProject = ts.createProject(gulpConfig.get('typescript.config'));
23
- const tsProject = ts.createProject(gulpConfig.get('typescript.config'));
24
- const makeDeclarations = () => src(srcPath).pipe(declarationProject()).dts.pipe(dest(distPath));
25
- const compileJS = () => src(srcPath).pipe(tsProject()).js.pipe(dest(distPath));
26
- return parallel(makeDeclarations, compileJS);
27
- };
18
+ */
19
+ const tsFor = function () {
20
+ let srcPath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : gulpConfig.get('typescript.from');
21
+ let distPath = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : gulpConfig.get('typescript.to');
22
+ const declarationProject = ts.createProject(gulpConfig.get('typescript.config'));
23
+ const tsProject = ts.createProject(gulpConfig.get('typescript.config'));
24
+ const makeDeclarations = () => src(srcPath).pipe(declarationProject()).dts.pipe(dest(distPath));
25
+ const compileJS = () => src(srcPath).pipe(tsProject()).js.pipe(dest(distPath));
26
+ return parallel(makeDeclarations, compileJS);
27
+ };
28
28
  module.exports = tsFor;
package/dist/partials.js CHANGED
@@ -1,5 +1,5 @@
1
- 'use strict'
2
-
1
+ 'use strict'
2
+
3
3
  /**
4
4
  * Micro-functions used as components for the main gulp functions.
5
5
  * @file
@@ -7,35 +7,35 @@
7
7
  * @version 3.0.0
8
8
  * @module partials
9
9
  * @memberOf module:js-build-tools
10
- */
11
-
12
- const addToReadme = require('./partials/addToReadme')
13
- const beginWatcher = require('./partials/beginWatcher')
14
- const clean = require('./partials/clean')
15
- const copyFor = require('./partials/copyFor')
16
- const distFor = require('./partials/distFor')
17
- const distForSrc = require('./partials/distForSrc')
18
- const distSeries = require('./partials/distSeries')
19
- const imagesFor = require('./partials/imagesFor.js')
20
- const minifyFor = require('./partials/minifyFor')
21
- const readmeTemplate = require('./partials/readmeTemplate')
22
- const removeDirectory = require('./partials/removeDirectory')
23
- const runOnChange = require('./partials/runOnChange')
24
- const sassFor = require('./partials/sassFor')
25
- const tsFor = require('./partials/tsFor')
26
- module.exports = {
27
- addToReadme,
28
- beginWatcher,
29
- clean,
30
- copyFor,
31
- distFor,
32
- distForSrc,
33
- distSeries,
34
- imagesFor,
35
- minifyFor,
36
- readmeTemplate,
37
- removeDirectory,
38
- runOnChange,
39
- sassFor,
40
- tsFor
41
- }
10
+ */
11
+
12
+ const addToReadme = require('./partials/addToReadme')
13
+ const beginWatcher = require('./partials/beginWatcher')
14
+ const clean = require('./partials/clean')
15
+ const copyFor = require('./partials/copyFor')
16
+ const distFor = require('./partials/distFor')
17
+ const distForSrc = require('./partials/distForSrc')
18
+ const distSeries = require('./partials/distSeries')
19
+ const imagesFor = require('./partials/imagesFor.js')
20
+ const minifyFor = require('./partials/minifyFor')
21
+ const readmeTemplate = require('./partials/readmeTemplate')
22
+ const removeDirectory = require('./partials/removeDirectory')
23
+ const runOnChange = require('./partials/runOnChange')
24
+ const sassFor = require('./partials/sassFor')
25
+ const tsFor = require('./partials/tsFor')
26
+ module.exports = {
27
+ addToReadme,
28
+ beginWatcher,
29
+ clean,
30
+ copyFor,
31
+ distFor,
32
+ distForSrc,
33
+ distSeries,
34
+ imagesFor,
35
+ minifyFor,
36
+ readmeTemplate,
37
+ removeDirectory,
38
+ runOnChange,
39
+ sassFor,
40
+ tsFor
41
+ }
@@ -1,69 +1,69 @@
1
- "use strict";
2
-
3
- // Import the configurations and override some of them to direct to the temp directory.
4
- const gulpConfig = require('../../gulp.config.js');
5
- const {
6
- setUp
7
- } = require('test-filesystem');
8
- let tempDir = 'test-temp/';
9
- let srcPath = "".concat(tempDir, "src");
10
-
1
+ "use strict";
2
+
3
+ // Import the configurations and override some of them to direct to the temp directory.
4
+ const gulpConfig = require('../../gulp.config.js');
5
+ const {
6
+ setUp
7
+ } = require('test-filesystem');
8
+ let tempDir = 'test-temp/';
9
+ let srcPath = "".concat(tempDir, "src");
10
+
11
11
  /**
12
12
  * Update the gulp configurations with the test data. Set the test directory where temp files will be created for testing.
13
13
  * @memberOf module:testHelpers
14
14
  * @param {string} testDir
15
- */
16
- const setDefaults = function () {
17
- let testDir = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'test-temp';
18
- tempDir = "".concat(testDir, "/");
19
- srcPath = "".concat(tempDir, "src");
20
- setUp.setDefaults(tempDir);
21
- const distPath = "".concat(tempDir, "dist");
22
- const browserPath = "".concat(tempDir, "browser");
23
- const sassPath = "".concat(tempDir, "sass");
24
- gulpConfig.set('browser.from', "".concat(distPath, "/**/*.js"));
25
- gulpConfig.set('browser.to', browserPath);
26
- gulpConfig.set('cleanPaths', [distPath, browserPath]);
27
- gulpConfig.set('dist.from', "".concat(srcPath, "/**/!(*.test).js"));
28
- gulpConfig.set('dist.main', "".concat(distPath, "/main"));
29
- gulpConfig.set('dist.to', distPath);
30
- gulpConfig.set('fonts.from', "".concat(srcPath, "/fonts/**/*"));
31
- gulpConfig.set('fonts.to', "".concat(browserPath, "/fonts"));
32
- gulpConfig.set('images.from', "".concat(srcPath, "/img/**/*.+(png|jpg|jpeg|gif|svg)"));
33
- gulpConfig.set('images.to', "".concat(browserPath, "/img"));
34
- gulpConfig.set('readme.template', "".concat(tempDir, "MAIN.md"));
35
- gulpConfig.set('readme.to', tempDir);
36
- gulpConfig.set('readme.from', "".concat(srcPath, "/**/!(*.test).js"));
37
- gulpConfig.set('rootPath', tempDir);
38
- gulpConfig.set('sass.from', "".concat(sassPath, "/**/*.+(scss|sass)"));
39
- gulpConfig.set('sass.path', sassPath);
40
- gulpConfig.set('sass.to', "".concat(browserPath, "/css"));
41
- gulpConfig.set('srcPath', srcPath);
42
- gulpConfig.set('typescript.from', "".concat(srcPath, "/**/*.ts"));
43
- gulpConfig.set('typescript.to', distPath);
44
- gulpConfig.set('test.watch', "".concat(srcPath, "/**/*.js"));
45
- };
46
- exports.setDefaults = setDefaults;
47
- exports.gulpConfig = gulpConfig;
48
-
15
+ */
16
+ const setDefaults = function () {
17
+ let testDir = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'test-temp';
18
+ tempDir = "".concat(testDir, "/");
19
+ srcPath = "".concat(tempDir, "src");
20
+ setUp.setDefaults(tempDir);
21
+ const distPath = "".concat(tempDir, "dist");
22
+ const browserPath = "".concat(tempDir, "browser");
23
+ const sassPath = "".concat(tempDir, "sass");
24
+ gulpConfig.set('browser.from', "".concat(distPath, "/**/*.js"));
25
+ gulpConfig.set('browser.to', browserPath);
26
+ gulpConfig.set('cleanPaths', [distPath, browserPath]);
27
+ gulpConfig.set('dist.from', "".concat(srcPath, "/**/!(*.test).js"));
28
+ gulpConfig.set('dist.main', "".concat(distPath, "/main"));
29
+ gulpConfig.set('dist.to', distPath);
30
+ gulpConfig.set('fonts.from', "".concat(srcPath, "/fonts/**/*"));
31
+ gulpConfig.set('fonts.to', "".concat(browserPath, "/fonts"));
32
+ gulpConfig.set('images.from', "".concat(srcPath, "/img/**/*.+(png|jpg|jpeg|gif|svg)"));
33
+ gulpConfig.set('images.to', "".concat(browserPath, "/img"));
34
+ gulpConfig.set('readme.template', "".concat(tempDir, "MAIN.md"));
35
+ gulpConfig.set('readme.to', tempDir);
36
+ gulpConfig.set('readme.from', "".concat(srcPath, "/**/!(*.test).js"));
37
+ gulpConfig.set('rootPath', tempDir);
38
+ gulpConfig.set('sass.from', "".concat(sassPath, "/**/*.+(scss|sass)"));
39
+ gulpConfig.set('sass.path', sassPath);
40
+ gulpConfig.set('sass.to', "".concat(browserPath, "/css"));
41
+ gulpConfig.set('srcPath', srcPath);
42
+ gulpConfig.set('typescript.from', "".concat(srcPath, "/**/*.ts"));
43
+ gulpConfig.set('typescript.to', distPath);
44
+ gulpConfig.set('test.watch', "".concat(srcPath, "/**/*.js"));
45
+ };
46
+ exports.setDefaults = setDefaults;
47
+ exports.gulpConfig = gulpConfig;
48
+
49
49
  /**
50
50
  * Ensure that the del has completed, recursively attempt to delete and recreate
51
51
  * @memberOf module:testHelpers
52
52
  * @param {boolean} [exists=true]
53
53
  * @returns {Promise<*|void>}
54
- */
55
- exports.createTempDir = setUp.createTempDir;
56
-
54
+ */
55
+ exports.createTempDir = setUp.createTempDir;
56
+
57
57
  /**
58
58
  * In the Jest.beforeEach function call this one to set up the temp directory.
59
59
  * @memberOf module:testHelpers
60
60
  * @returns {Promise<*|void>}
61
- */
62
- exports.beforeEach = setUp.beforeEach;
63
-
61
+ */
62
+ exports.beforeEach = setUp.beforeEach;
63
+
64
64
  /**
65
65
  * In the Jest.afterEach function call this one to clean up and remove the temp directory.
66
66
  * @memberOf module:testHelpers
67
67
  * @returns {Promise<*>}
68
- */
68
+ */
69
69
  exports.afterEach = setUp.afterEach;
package/dist/testFull.js CHANGED
@@ -1,22 +1,22 @@
1
- 'use strict'
2
-
3
- const gulpConfig = require('../gulp.config.js')
4
- const {
5
- runCLI
6
- } = require('jest')
7
-
1
+ 'use strict'
2
+
3
+ const gulpConfig = require('../gulp.config.js')
4
+ const {
5
+ runCLI
6
+ } = require('jest')
7
+
8
8
  /**
9
9
  * Run all tests with jest.
10
10
  * Configure where tests are located by using 'testPath'.
11
11
  * @memberOf module:js-build-tools
12
12
  * @returns {Promise<*>}
13
- */
14
- const testFull = () => {
15
- let testPath = gulpConfig.get('test.path')
16
- if (!Array.isArray(testPath)) {
17
- // The testPath must be an array of strings
18
- testPath = [testPath]
19
- }
20
- return runCLI(gulpConfig.get('test.options'), testPath)
21
- }
22
- module.exports = testFull
13
+ */
14
+ const testFull = () => {
15
+ let testPath = gulpConfig.get('test.path')
16
+ if (!Array.isArray(testPath)) {
17
+ // The testPath must be an array of strings
18
+ testPath = [testPath]
19
+ }
20
+ return runCLI(gulpConfig.get('test.options'), testPath)
21
+ }
22
+ module.exports = testFull
@@ -1,5 +1,5 @@
1
- 'use strict'
2
-
1
+ 'use strict'
2
+
3
3
  /**
4
4
  * Export the setUp helper.
5
5
  * @file
@@ -7,9 +7,9 @@
7
7
  * @version 3.0.0
8
8
  * @module testHelpers
9
9
  * @memberOf module:js-build-tools
10
- */
11
-
12
- const setUp = require('./test-helpers/setUp')
13
- module.exports = {
14
- setUp
15
- }
10
+ */
11
+
12
+ const setUp = require('./test-helpers/setUp')
13
+ module.exports = {
14
+ setUp
15
+ }
package/dist/testQuick.js CHANGED
@@ -1,24 +1,24 @@
1
- 'use strict'
2
-
3
- const gulpConfig = require('../gulp.config.js')
4
- const {
5
- runCLI
6
- } = require('jest')
7
-
1
+ 'use strict'
2
+
3
+ const gulpConfig = require('../gulp.config.js')
4
+ const {
5
+ runCLI
6
+ } = require('jest')
7
+
8
8
  /**
9
9
  * Run the Jest tests for files which have been modified (based on git status).
10
10
  * Configure where tests are located by using 'testPath'.
11
11
  * @memberOf module:js-build-tools
12
12
  * @returns {Promise<*>}
13
- */
14
- const testQuick = () => {
15
- let testPath = gulpConfig.get('test.path')
16
- if (!Array.isArray(testPath)) {
17
- // The testPath must be an array of strings
18
- testPath = [testPath]
19
- }
20
- return runCLI({
21
- onlyChanged: true
22
- }, testPath)
23
- }
24
- module.exports = testQuick
13
+ */
14
+ const testQuick = () => {
15
+ let testPath = gulpConfig.get('test.path')
16
+ if (!Array.isArray(testPath)) {
17
+ // The testPath must be an array of strings
18
+ testPath = [testPath]
19
+ }
20
+ return runCLI({
21
+ onlyChanged: true
22
+ }, testPath)
23
+ }
24
+ module.exports = testQuick
@@ -1,9 +1,9 @@
1
- "use strict";
2
-
3
- const isObject = require('./isObject');
4
- const strAfter = require('common-exports/dist/utilities/strAfter').default;
5
- const strBefore = require('common-exports/dist/utilities/strBefore').default;
6
-
1
+ "use strict";
2
+
3
+ const isObject = require('./isObject');
4
+ const strAfter = require('./strAfter');
5
+ const strBefore = require('./strBefore');
6
+
7
7
  /**
8
8
  * Get a nested property value from an object.
9
9
  * Original source concepts from {@link https://github.com/jheagle/si-funciona/blob/main/src/helpers/objects/dotGet.ts Sí, funciona}
@@ -11,40 +11,40 @@ const strBefore = require('common-exports/dist/utilities/strBefore').default;
11
11
  * @param {string} dotNotation - The path to the property
12
12
  * @param {string|null} [defaultValue=null] - The default value to return if the property is not found
13
13
  * @returns {*} The value of the property
14
- */
15
- const dotGet = function (arrayObject, dotNotation) {
16
- let defaultValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
17
- let key = strBefore(dotNotation, '.');
18
- const lastKey = !key;
19
- if (lastKey) {
20
- key = dotNotation;
21
- }
22
- if (key === '*') {
23
- const result = [];
24
- for (let wildKey in arrayObject) {
25
- const wildValue = arrayObject[wildKey];
26
- if (lastKey) {
27
- result[wildKey] = wildValue;
28
- continue;
29
- }
30
- if (!isObject(wildValue)) {
31
- continue;
32
- }
33
- result[wildKey] = dotGet(wildValue, strAfter(dotNotation, '.'), defaultValue);
34
- }
35
- return result;
36
- }
37
- if (lastKey) {
38
- var _arrayObject$dotNotat;
39
- return (_arrayObject$dotNotat = arrayObject[dotNotation]) !== null && _arrayObject$dotNotat !== void 0 ? _arrayObject$dotNotat : defaultValue;
40
- }
41
- if (typeof arrayObject[key] === 'undefined') {
42
- return defaultValue;
43
- }
44
- const next = arrayObject[key];
45
- if (!isObject(next)) {
46
- return defaultValue;
47
- }
48
- return dotGet(next, strAfter(dotNotation, '.'), defaultValue);
49
- };
14
+ */
15
+ const dotGet = function (arrayObject, dotNotation) {
16
+ let defaultValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
17
+ let key = strBefore(dotNotation, '.');
18
+ const lastKey = !key;
19
+ if (lastKey) {
20
+ key = dotNotation;
21
+ }
22
+ if (key === '*') {
23
+ const result = [];
24
+ for (let wildKey in arrayObject) {
25
+ const wildValue = arrayObject[wildKey];
26
+ if (lastKey) {
27
+ result[wildKey] = wildValue;
28
+ continue;
29
+ }
30
+ if (!isObject(wildValue)) {
31
+ continue;
32
+ }
33
+ result[wildKey] = dotGet(wildValue, strAfter(dotNotation, '.'), defaultValue);
34
+ }
35
+ return result;
36
+ }
37
+ if (lastKey) {
38
+ var _arrayObject$dotNotat;
39
+ return (_arrayObject$dotNotat = arrayObject[dotNotation]) !== null && _arrayObject$dotNotat !== void 0 ? _arrayObject$dotNotat : defaultValue;
40
+ }
41
+ if (typeof arrayObject[key] === 'undefined') {
42
+ return defaultValue;
43
+ }
44
+ const next = arrayObject[key];
45
+ if (!isObject(next)) {
46
+ return defaultValue;
47
+ }
48
+ return dotGet(next, strAfter(dotNotation, '.'), defaultValue);
49
+ };
50
50
  module.exports = dotGet;