json-to-fs-structure 1.3.0 → 2.0.0

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/package.json CHANGED
@@ -1,10 +1,17 @@
1
1
  {
2
2
  "name": "json-to-fs-structure",
3
- "version": "1.3.0",
3
+ "version": "2.0.0",
4
4
  "description": "A simple module that takes a simple JSON file and produces the properties as a file structure in the same directory or given directory.",
5
- "main": "index.js",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
6
10
  "scripts": {
7
- "test": "jest",
11
+ "build": "tsc",
12
+ "pretest": "yarn build",
13
+ "prepublishOnly": "yarn build",
14
+ "test": "jest dist/test/index.test.js",
8
15
  "format": "yarn eslint . --fix"
9
16
  },
10
17
  "keywords": [
@@ -15,12 +22,15 @@
15
22
  "author": "eldavojohn",
16
23
  "license": "MIT",
17
24
  "devDependencies": {
25
+ "@types/jest": "^30.0.0",
26
+ "@types/node": "^26.0.0",
18
27
  "eslint": "^9.39.2",
19
28
  "eslint-config-prettier": "^10.1.8",
20
29
  "eslint-plugin-prettier": "^5.5.5",
21
30
  "jest": "^30.2.0",
22
31
  "mocha": "^11.7.5",
23
- "prettier": "^3.8.1"
32
+ "prettier": "^3.8.1",
33
+ "typescript": "^6.0.3"
24
34
  },
25
35
  "resolutions": {
26
36
  "**/**/cryptiles": "^4.1.2",
@@ -39,5 +49,8 @@
39
49
  "mem": "^10.0.0",
40
50
  "minimist": "^1.2.3",
41
51
  "npm": "^11.8.0"
52
+ },
53
+ "publishConfig": {
54
+ "access": "public"
42
55
  }
43
- }
56
+ }
@@ -1,33 +0,0 @@
1
- # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2
- # For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
3
-
4
- name: Node.js Package
5
-
6
- on:
7
- release:
8
- types: [created]
9
-
10
- jobs:
11
- build:
12
- runs-on: ubuntu-latest
13
- steps:
14
- - uses: actions/checkout@v3
15
- - uses: actions/setup-node@v3
16
- with:
17
- node-version: 16
18
- - run: npm ci
19
- - run: npm test
20
-
21
- publish-npm:
22
- needs: build
23
- runs-on: ubuntu-latest
24
- steps:
25
- - uses: actions/checkout@v3
26
- - uses: actions/setup-node@v3
27
- with:
28
- node-version: 16
29
- registry-url: https://registry.npmjs.org/
30
- - run: npm ci
31
- - run: npm publish
32
- env:
33
- NODE_AUTH_TOKEN: ${{secrets.npm_token}}
Binary file
package/eslint.config.mjs DELETED
@@ -1,35 +0,0 @@
1
- import { defineConfig } from "eslint/config";
2
- import prettier from "eslint-plugin-prettier";
3
- import globals from "globals";
4
- import path from "node:path";
5
- import { fileURLToPath } from "node:url";
6
- import js from "@eslint/js";
7
- import { FlatCompat } from "@eslint/eslintrc";
8
-
9
- const __filename = fileURLToPath(import.meta.url);
10
- const __dirname = path.dirname(__filename);
11
- const compat = new FlatCompat({
12
- baseDirectory: __dirname,
13
- recommendedConfig: js.configs.recommended,
14
- allConfig: js.configs.all,
15
- });
16
-
17
- export default defineConfig([
18
- {
19
- extends: compat.extends("plugin:prettier/recommended"),
20
-
21
- plugins: {
22
- prettier,
23
- },
24
-
25
- languageOptions: {
26
- globals: {
27
- ...globals.node,
28
- },
29
- },
30
-
31
- rules: {
32
- "prettier/prettier": "error",
33
- },
34
- },
35
- ]);
package/index.js DELETED
@@ -1,216 +0,0 @@
1
- const fs = require("fs");
2
- const { sep } = require("path");
3
-
4
- const isLeaf = (testNode) =>
5
- testNode.constructor === Object && Object.keys(testNode).length === 0;
6
-
7
- const isEqualOrIsInArray = (property, stopWord) =>
8
- stopWord &&
9
- (property === stopWord ||
10
- (Array.isArray(stopWord) && stopWord.indexOf(property) > -1));
11
-
12
- const levelPropertiesToDirectories = (
13
- obj,
14
- filePath,
15
- stopWord,
16
- ignoredWords,
17
- spaceReplace,
18
- executorObject = {},
19
- ) => {
20
- if (obj && (typeof obj === "string" || obj instanceof String)) {
21
- return;
22
- }
23
- const { leafProcedure, nonLeafProcedure, procedure } = executorObject;
24
- let { accumulator } = executorObject;
25
- let promiseArray = [];
26
- let fields = [];
27
- if (obj && obj instanceof Array) {
28
- obj.forEach((arrayObject) => {
29
- promiseArray = promiseArray.concat(
30
- levelPropertiesToDirectories(
31
- arrayObject,
32
- filePath,
33
- stopWord,
34
- ignoredWords,
35
- spaceReplace,
36
- {
37
- leafProcedure,
38
- nonLeafProcedure,
39
- procedure,
40
- accumulator,
41
- },
42
- ),
43
- );
44
- });
45
- } else if (obj) {
46
- fields = Object.keys(obj) || [];
47
- }
48
- fields.forEach((property) => {
49
- if (
50
- !isEqualOrIsInArray(property, stopWord) &&
51
- ignoredWords.indexOf(property) === -1
52
- ) {
53
- const newPath = spaceReplace
54
- ? `${filePath}${sep}${property.replace(/ /g, spaceReplace)}`
55
- : `${filePath}${sep}${property}`;
56
- let accumulatorCopy = Object.assign({}, accumulator);
57
- try {
58
- fs.mkdirSync(newPath);
59
- } catch (e) {}
60
- if (obj[`${property}`] && Object.keys(obj[`${property}`]).length > 0) {
61
- if (nonLeafProcedure) {
62
- accumulatorCopy = nonLeafProcedure(
63
- newPath,
64
- accumulator,
65
- obj[`${property}`],
66
- property,
67
- );
68
- }
69
- if (procedure) {
70
- accumulatorCopy = procedure(
71
- newPath,
72
- accumulator,
73
- obj[`${property}`],
74
- property,
75
- );
76
- }
77
- promiseArray = promiseArray.concat(
78
- levelPropertiesToDirectories(
79
- obj[`${property}`],
80
- newPath,
81
- stopWord,
82
- ignoredWords,
83
- spaceReplace,
84
- {
85
- leafProcedure,
86
- nonLeafProcedure,
87
- procedure,
88
- accumulator: accumulatorCopy,
89
- },
90
- ),
91
- );
92
- } else {
93
- if (leafProcedure && isLeaf(obj[`${property}`])) {
94
- leafProcedure(
95
- newPath,
96
- Object.assign({}, accumulator),
97
- obj[`${property}`],
98
- property,
99
- );
100
- }
101
- if (procedure && isLeaf(obj[`${property}`])) {
102
- procedure(
103
- newPath,
104
- Object.assign({}, accumulator),
105
- obj[`${property}`],
106
- property,
107
- );
108
- }
109
- }
110
- } else if (ignoredWords.indexOf(property) === -1) {
111
- if (leafProcedure) {
112
- leafProcedure(
113
- `${filePath}${sep}`,
114
- Object.assign({}, accumulator),
115
- obj[`${property}`],
116
- property,
117
- );
118
- }
119
- }
120
- });
121
- return promiseArray;
122
- };
123
-
124
- exports.jsonToFsStructure = function ({
125
- jsonObject,
126
- filePath = ".",
127
- callback = () => {},
128
- stopWord,
129
- spaceReplace,
130
- ignoredWords = [],
131
- }) {
132
- return Promise.all(
133
- levelPropertiesToDirectories(
134
- jsonObject,
135
- filePath,
136
- stopWord,
137
- ignoredWords,
138
- spaceReplace,
139
- ),
140
- ).then(callback);
141
- };
142
-
143
- exports.jsonToFsWithLeafFunction = function ({
144
- jsonObject,
145
- leafProcedure = () => {},
146
- context = {},
147
- filePath = ".",
148
- callback = () => {},
149
- stopWord,
150
- spaceReplace,
151
- ignoredWords = [],
152
- }) {
153
- return Promise.all(
154
- levelPropertiesToDirectories(
155
- jsonObject,
156
- filePath,
157
- stopWord,
158
- ignoredWords,
159
- spaceReplace,
160
- {
161
- leafProcedure,
162
- accumulator: context,
163
- },
164
- ),
165
- ).then(callback);
166
- };
167
-
168
- exports.jsonToFsWithNonLeafFunction = function ({
169
- jsonObject,
170
- nonLeafProcedure = () => {},
171
- context = {},
172
- filePath = ".",
173
- callback = () => {},
174
- stopWord,
175
- spaceReplace,
176
- ignoredWords = [],
177
- }) {
178
- return Promise.all(
179
- levelPropertiesToDirectories(
180
- jsonObject,
181
- filePath,
182
- stopWord,
183
- ignoredWords,
184
- spaceReplace,
185
- {
186
- nonLeafProcedure,
187
- accumulator: context,
188
- },
189
- ),
190
- ).then(callback);
191
- };
192
-
193
- exports.jsonToFsWithFunction = function ({
194
- jsonObject,
195
- procedure = () => {},
196
- context = {},
197
- filePath = ".",
198
- callback = () => {},
199
- stopWord,
200
- spaceReplace,
201
- ignoredWords = [],
202
- }) {
203
- return Promise.all(
204
- levelPropertiesToDirectories(
205
- jsonObject,
206
- filePath,
207
- stopWord,
208
- ignoredWords,
209
- spaceReplace,
210
- {
211
- procedure,
212
- accumulator: context,
213
- },
214
- ),
215
- ).then(callback);
216
- };