@amekusa/util.js 2.0.0 → 2.1.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/dist/amekusa.util.br.es.js +38 -2
- package/dist/amekusa.util.br.es.min.js +3 -3
- package/dist/amekusa.util.br.js +38 -2
- package/dist/amekusa.util.br.min.js +3 -3
- package/dist/amekusa.util.cjs +229 -5
- package/dist/amekusa.util.js +230 -6
- package/package.json +1 -1
|
@@ -160,7 +160,43 @@ function merge(x, y, opts = {}) {
|
|
|
160
160
|
return x.concat(y);
|
|
161
161
|
}
|
|
162
162
|
return y;
|
|
163
|
-
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Gets a property from the given object by the given string path.
|
|
167
|
+
* @param {object} obj - Object to traverse
|
|
168
|
+
* @param {string} path - Property names separated with '.'
|
|
169
|
+
* @return {any} value of the found property, or undefined if it's not found
|
|
170
|
+
*/
|
|
171
|
+
function dig(obj, path) {
|
|
172
|
+
path = path.split('.');
|
|
173
|
+
for (let i = 0; i < path.length; i++) {
|
|
174
|
+
let p = path[i];
|
|
175
|
+
if (typeof obj == 'object' && p in obj) obj = obj[p];
|
|
176
|
+
else return undefined;
|
|
177
|
+
}
|
|
178
|
+
return obj;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Substitutes the properties of the given data for the references in the given string.
|
|
183
|
+
* @param {string} str - String that contains references to the properties
|
|
184
|
+
* @param {object} data - Object that contains properties to replace the references
|
|
185
|
+
* @param {object} [opts] - Options
|
|
186
|
+
* @return {string} a modified `str`
|
|
187
|
+
*/
|
|
188
|
+
function subst(str, data, opts = {}) {
|
|
189
|
+
let {
|
|
190
|
+
modifier = null,
|
|
191
|
+
start = '{{',
|
|
192
|
+
end = '}}',
|
|
193
|
+
} = opts;
|
|
194
|
+
let ref = new RegExp(start + '\\s*([-.\\w]+)\\s*' + end, 'g');
|
|
195
|
+
return str.replaceAll(ref, modifier
|
|
196
|
+
? (_, m1) => (modifier(dig(data, m1), m1, data) || '')
|
|
197
|
+
: (_, m1) => (dig(data, m1) || '')
|
|
198
|
+
);
|
|
199
|
+
}var gen=/*#__PURE__*/Object.freeze({__proto__:null,arr:arr,clean:clean,dig:dig,is:is,isEmpty:isEmpty,isEmptyOrFalsey:isEmptyOrFalsey,isEmptyOrFalsy:isEmptyOrFalsy,merge:merge,subst:subst});/*!
|
|
164
200
|
* === @amekusa/util.js/web === *
|
|
165
201
|
* MIT License
|
|
166
202
|
*
|
|
@@ -379,4 +415,4 @@ function hms(d, format = null) {
|
|
|
379
415
|
*/
|
|
380
416
|
function iso9075(d) {
|
|
381
417
|
return ymd(d, '-') + ' ' + hms(d, ':');
|
|
382
|
-
}var time=/*#__PURE__*/Object.freeze({__proto__:null,addTime:addTime,ceil:ceil,date:date,floor:floor,hms:hms,iso9075:iso9075,localize:localize,ms:ms,quantize:quantize,round:round,ymd:ymd});export{arr,clean,gen,is,isEmpty,isEmptyOrFalsey,isEmptyOrFalsy,merge,time,web};
|
|
418
|
+
}var time=/*#__PURE__*/Object.freeze({__proto__:null,addTime:addTime,ceil:ceil,date:date,floor:floor,hms:hms,iso9075:iso9075,localize:localize,ms:ms,quantize:quantize,round:round,ymd:ymd});export{arr,clean,dig,gen,is,isEmpty,isEmptyOrFalsey,isEmptyOrFalsy,merge,subst,time,web};
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
23
|
* SOFTWARE.
|
|
24
24
|
*/
|
|
25
|
-
function e(e){return Array.isArray(e)?e:[e]}function t(e,...t){let r=typeof e;for(let n=0;n<t.length;n++){let i=t[n];if("string"==typeof i){if("array"==i){if(Array.isArray(e))return!0}else if(r==i)return!0}else if(e instanceof i)return!0}return!1}function r(e){if(Array.isArray(e))return 0==e.length;switch(typeof e){case"string":return!e;case"object":for(let t in e)return!1;return!0;case"undefined":return!0}return!1}function n(e){if(!e)return!0;if(Array.isArray(e))return 0==e.length;if("object"==typeof e)for(let t in e)return!1;return!1}const i=n;function u(e,t=8){if(t){if(Array.isArray(e)){let n=[];for(let i=0;i<e.length;i++){let o=u(e[i],t-1);r(o)||n.push(o)}return n}if("object"==typeof e){let n={};for(let i in e){let o=u(e[i],t-1);r(o)||(n[i]=o)}return n}}return e}function o(e,t,r={}){switch("recurse"in r||(r.recurse=8),Array.isArray(e)+Array.isArray(t)){case 0:if(r.recurse&&e&&t&&"object"==typeof e&&"object"==typeof t){r.recurse--;for(let n in t)e[n]=o(e[n],t[n],r);return r.recurse++,e}case 1:return t}switch(r.mergeArrays){case!0:for(let r=0;r<t.length;r++)e.includes(t[r])||e.push(t[r]);return e;case"push":return e.push(...t),e;case"concat":return e.concat(t)}return t}
|
|
25
|
+
function e(e){return Array.isArray(e)?e:[e]}function t(e,...t){let r=typeof e;for(let n=0;n<t.length;n++){let i=t[n];if("string"==typeof i){if("array"==i){if(Array.isArray(e))return!0}else if(r==i)return!0}else if(e instanceof i)return!0}return!1}function r(e){if(Array.isArray(e))return 0==e.length;switch(typeof e){case"string":return!e;case"object":for(let t in e)return!1;return!0;case"undefined":return!0}return!1}function n(e){if(!e)return!0;if(Array.isArray(e))return 0==e.length;if("object"==typeof e)for(let t in e)return!1;return!1}const i=n;function u(e,t=8){if(t){if(Array.isArray(e)){let n=[];for(let i=0;i<e.length;i++){let o=u(e[i],t-1);r(o)||n.push(o)}return n}if("object"==typeof e){let n={};for(let i in e){let o=u(e[i],t-1);r(o)||(n[i]=o)}return n}}return e}function o(e,t,r={}){switch("recurse"in r||(r.recurse=8),Array.isArray(e)+Array.isArray(t)){case 0:if(r.recurse&&e&&t&&"object"==typeof e&&"object"==typeof t){r.recurse--;for(let n in t)e[n]=o(e[n],t[n],r);return r.recurse++,e}case 1:return t}switch(r.mergeArrays){case!0:for(let r=0;r<t.length;r++)e.includes(t[r])||e.push(t[r]);return e;case"push":return e.push(...t),e;case"concat":return e.concat(t)}return t}function a(e,t){t=t.split(".");for(let r=0;r<t.length;r++){let n=t[r];if("object"!=typeof e||!(n in e))return;e=e[n]}return e}function c(e,t,r={}){let{modifier:n=null,start:i="{{",end:u="}}"}=r,o=new RegExp(i+"\\s*([-.\\w]+)\\s*"+u,"g");return e.replaceAll(o,n?(e,r)=>n(a(t,r),r,t)||"":(e,r)=>a(t,r)||"")}var s=Object.freeze({__proto__:null,arr:e,clean:u,dig:a,is:t,isEmpty:r,isEmptyOrFalsey:i,isEmptyOrFalsy:n,merge:o,subst:c});
|
|
26
26
|
/*!
|
|
27
27
|
* === @amekusa/util.js/web === *
|
|
28
28
|
* MIT License
|
|
@@ -46,7 +46,7 @@ function e(e){return Array.isArray(e)?e:[e]}function t(e,...t){let r=typeof e;fo
|
|
|
46
46
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
47
47
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
48
48
|
* SOFTWARE.
|
|
49
|
-
*/function
|
|
49
|
+
*/function f(e){return`${e}`.replace(p,y)}const l=f,g={"&":"amp",'"':"quot","'":"apos","<":"lt",">":"gt"},p=new RegExp(`["'<>]|(&(?!${Object.values(g).join("|")};))`,"g"),y=e=>`&${g[e]};`;var d=Object.freeze({__proto__:null,escHTML:f,escHtml:l});
|
|
50
50
|
/*!
|
|
51
51
|
* === @amekusa/util.js/time === *
|
|
52
52
|
* MIT License
|
|
@@ -70,4 +70,4 @@ function e(e){return Array.isArray(e)?e:[e]}function t(e,...t){let r=typeof e;fo
|
|
|
70
70
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
71
71
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
72
72
|
* SOFTWARE.
|
|
73
|
-
*/function
|
|
73
|
+
*/function h(e,t,r="round"){return e.setTime(Math[r](e.getTime()/t)*t),e}function m(e,t=null){let r=[e.getFullYear().toString(),(e.getMonth()+1).toString().padStart(2,"0"),e.getDate().toString().padStart(2,"0")];switch(typeof t){case"string":return r.join(t);case"object":return t?(t.Y=r[0],t.M=r[1],t.D=r[2],t):r;default:if(!t)return r;throw"invalid type"}}function A(e,t=null){let r=[e.getHours().toString().padStart(2,"0"),e.getMinutes().toString().padStart(2,"0"),e.getSeconds().toString().padStart(2,"0")];switch(typeof t){case"string":return r.join(t);case"object":return t?(t.h=r[0],t.m=r[1],t.s=r[2],t):r;default:if(!t)return r;throw"invalid type"}}var j=Object.freeze({__proto__:null,addTime:function(e,t){return e.setTime(e.getTime()+t),e},ceil:function(e,t){return h(e,t,"ceil")},date:function(...e){return e.length&&e[0]?e[0]instanceof Date?e[0]:new Date(...e):new Date},floor:function(e,t){return h(e,t,"floor")},hms:A,iso9075:function(e){return m(e,"-")+" "+A(e,":")},localize:function(e){return e.setTime(e.getTime()-6e4*e.getTimezoneOffset()),e},ms:function(...e){if(!e.length||!e[0])return Date.now();let t=e[0];return"number"==typeof t?t:t instanceof Date?t.getTime():new Date(...e).getTime()},quantize:h,round:function(e,t){return h(e,t,"round")},ymd:m});export{e as arr,u as clean,a as dig,s as gen,t as is,r as isEmpty,i as isEmptyOrFalsey,n as isEmptyOrFalsy,o as merge,c as subst,j as time,d as web};
|
package/dist/amekusa.util.br.js
CHANGED
|
@@ -160,7 +160,43 @@ function merge(x, y, opts = {}) {
|
|
|
160
160
|
return x.concat(y);
|
|
161
161
|
}
|
|
162
162
|
return y;
|
|
163
|
-
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Gets a property from the given object by the given string path.
|
|
167
|
+
* @param {object} obj - Object to traverse
|
|
168
|
+
* @param {string} path - Property names separated with '.'
|
|
169
|
+
* @return {any} value of the found property, or undefined if it's not found
|
|
170
|
+
*/
|
|
171
|
+
function dig(obj, path) {
|
|
172
|
+
path = path.split('.');
|
|
173
|
+
for (let i = 0; i < path.length; i++) {
|
|
174
|
+
let p = path[i];
|
|
175
|
+
if (typeof obj == 'object' && p in obj) obj = obj[p];
|
|
176
|
+
else return undefined;
|
|
177
|
+
}
|
|
178
|
+
return obj;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Substitutes the properties of the given data for the references in the given string.
|
|
183
|
+
* @param {string} str - String that contains references to the properties
|
|
184
|
+
* @param {object} data - Object that contains properties to replace the references
|
|
185
|
+
* @param {object} [opts] - Options
|
|
186
|
+
* @return {string} a modified `str`
|
|
187
|
+
*/
|
|
188
|
+
function subst(str, data, opts = {}) {
|
|
189
|
+
let {
|
|
190
|
+
modifier = null,
|
|
191
|
+
start = '{{',
|
|
192
|
+
end = '}}',
|
|
193
|
+
} = opts;
|
|
194
|
+
let ref = new RegExp(start + '\\s*([-.\\w]+)\\s*' + end, 'g');
|
|
195
|
+
return str.replaceAll(ref, modifier
|
|
196
|
+
? (_, m1) => (modifier(dig(data, m1), m1, data) || '')
|
|
197
|
+
: (_, m1) => (dig(data, m1) || '')
|
|
198
|
+
);
|
|
199
|
+
}var gen=/*#__PURE__*/Object.freeze({__proto__:null,arr:arr,clean:clean,dig:dig,is:is,isEmpty:isEmpty,isEmptyOrFalsey:isEmptyOrFalsey,isEmptyOrFalsy:isEmptyOrFalsy,merge:merge,subst:subst});/*!
|
|
164
200
|
* === @amekusa/util.js/web === *
|
|
165
201
|
* MIT License
|
|
166
202
|
*
|
|
@@ -379,4 +415,4 @@ function hms(d, format = null) {
|
|
|
379
415
|
*/
|
|
380
416
|
function iso9075(d) {
|
|
381
417
|
return ymd(d, '-') + ' ' + hms(d, ':');
|
|
382
|
-
}var time=/*#__PURE__*/Object.freeze({__proto__:null,addTime:addTime,ceil:ceil,date:date,floor:floor,hms:hms,iso9075:iso9075,localize:localize,ms:ms,quantize:quantize,round:round,ymd:ymd});exports.arr=arr;exports.clean=clean;exports.gen=gen;exports.is=is;exports.isEmpty=isEmpty;exports.isEmptyOrFalsey=isEmptyOrFalsey;exports.isEmptyOrFalsy=isEmptyOrFalsy;exports.merge=merge;exports.time=time;exports.web=web;return exports;})({});
|
|
418
|
+
}var time=/*#__PURE__*/Object.freeze({__proto__:null,addTime:addTime,ceil:ceil,date:date,floor:floor,hms:hms,iso9075:iso9075,localize:localize,ms:ms,quantize:quantize,round:round,ymd:ymd});exports.arr=arr;exports.clean=clean;exports.dig=dig;exports.gen=gen;exports.is=is;exports.isEmpty=isEmpty;exports.isEmptyOrFalsey=isEmptyOrFalsey;exports.isEmptyOrFalsy=isEmptyOrFalsy;exports.merge=merge;exports.subst=subst;exports.time=time;exports.web=web;return exports;})({});
|
|
@@ -22,7 +22,7 @@ this.amekusa=this.amekusa||{},this.amekusa.util=function(e){"use strict";
|
|
|
22
22
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
23
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
24
|
* SOFTWARE.
|
|
25
|
-
*/function t(e){return Array.isArray(e)?e:[e]}function r(e,...t){let r=typeof e;for(let n=0;n<t.length;n++){let i=t[n];if("string"==typeof i){if("array"==i){if(Array.isArray(e))return!0}else if(r==i)return!0}else if(e instanceof i)return!0}return!1}function n(e){if(Array.isArray(e))return 0==e.length;switch(typeof e){case"string":return!e;case"object":for(let t in e)return!1;return!0;case"undefined":return!0}return!1}function i(e){if(!e)return!0;if(Array.isArray(e))return 0==e.length;if("object"==typeof e)for(let t in e)return!1;return!1}const u=i;function o(e,t=8){if(t){if(Array.isArray(e)){let r=[];for(let i=0;i<e.length;i++){let u=o(e[i],t-1);n(u)||r.push(u)}return r}if("object"==typeof e){let r={};for(let i in e){let u=o(e[i],t-1);n(u)||(r[i]=u)}return r}}return e}function
|
|
25
|
+
*/function t(e){return Array.isArray(e)?e:[e]}function r(e,...t){let r=typeof e;for(let n=0;n<t.length;n++){let i=t[n];if("string"==typeof i){if("array"==i){if(Array.isArray(e))return!0}else if(r==i)return!0}else if(e instanceof i)return!0}return!1}function n(e){if(Array.isArray(e))return 0==e.length;switch(typeof e){case"string":return!e;case"object":for(let t in e)return!1;return!0;case"undefined":return!0}return!1}function i(e){if(!e)return!0;if(Array.isArray(e))return 0==e.length;if("object"==typeof e)for(let t in e)return!1;return!1}const u=i;function o(e,t=8){if(t){if(Array.isArray(e)){let r=[];for(let i=0;i<e.length;i++){let u=o(e[i],t-1);n(u)||r.push(u)}return r}if("object"==typeof e){let r={};for(let i in e){let u=o(e[i],t-1);n(u)||(r[i]=u)}return r}}return e}function s(e,t,r={}){switch("recurse"in r||(r.recurse=8),Array.isArray(e)+Array.isArray(t)){case 0:if(r.recurse&&e&&t&&"object"==typeof e&&"object"==typeof t){r.recurse--;for(let n in t)e[n]=s(e[n],t[n],r);return r.recurse++,e}case 1:return t}switch(r.mergeArrays){case!0:for(let r=0;r<t.length;r++)e.includes(t[r])||e.push(t[r]);return e;case"push":return e.push(...t),e;case"concat":return e.concat(t)}return t}function a(e,t){t=t.split(".");for(let r=0;r<t.length;r++){let n=t[r];if("object"!=typeof e||!(n in e))return;e=e[n]}return e}function c(e,t,r={}){let{modifier:n=null,start:i="{{",end:u="}}"}=r,o=new RegExp(i+"\\s*([-.\\w]+)\\s*"+u,"g");return e.replaceAll(o,n?(e,r)=>n(a(t,r),r,t)||"":(e,r)=>a(t,r)||"")}var f=Object.freeze({__proto__:null,arr:t,clean:o,dig:a,is:r,isEmpty:n,isEmptyOrFalsey:u,isEmptyOrFalsy:i,merge:s,subst:c});
|
|
26
26
|
/*!
|
|
27
27
|
* === @amekusa/util.js/web === *
|
|
28
28
|
* MIT License
|
|
@@ -46,7 +46,7 @@ this.amekusa=this.amekusa||{},this.amekusa.util=function(e){"use strict";
|
|
|
46
46
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
47
47
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
48
48
|
* SOFTWARE.
|
|
49
|
-
*/function
|
|
49
|
+
*/function l(e){return`${e}`.replace(p,m)}const g=l,y={"&":"amp",'"':"quot","'":"apos","<":"lt",">":"gt"},p=new RegExp(`["'<>]|(&(?!${Object.values(y).join("|")};))`,"g"),m=e=>`&${y[e]};`;var h=Object.freeze({__proto__:null,escHTML:l,escHtml:g});
|
|
50
50
|
/*!
|
|
51
51
|
* === @amekusa/util.js/time === *
|
|
52
52
|
* MIT License
|
|
@@ -70,4 +70,4 @@ this.amekusa=this.amekusa||{},this.amekusa.util=function(e){"use strict";
|
|
|
70
70
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
71
71
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
72
72
|
* SOFTWARE.
|
|
73
|
-
*/function
|
|
73
|
+
*/function d(e,t,r="round"){return e.setTime(Math[r](e.getTime()/t)*t),e}function b(e,t=null){let r=[e.getFullYear().toString(),(e.getMonth()+1).toString().padStart(2,"0"),e.getDate().toString().padStart(2,"0")];switch(typeof t){case"string":return r.join(t);case"object":return t?(t.Y=r[0],t.M=r[1],t.D=r[2],t):r;default:if(!t)return r;throw"invalid type"}}function A(e,t=null){let r=[e.getHours().toString().padStart(2,"0"),e.getMinutes().toString().padStart(2,"0"),e.getSeconds().toString().padStart(2,"0")];switch(typeof t){case"string":return r.join(t);case"object":return t?(t.h=r[0],t.m=r[1],t.s=r[2],t):r;default:if(!t)return r;throw"invalid type"}}var j=Object.freeze({__proto__:null,addTime:function(e,t){return e.setTime(e.getTime()+t),e},ceil:function(e,t){return d(e,t,"ceil")},date:function(...e){return e.length&&e[0]?e[0]instanceof Date?e[0]:new Date(...e):new Date},floor:function(e,t){return d(e,t,"floor")},hms:A,iso9075:function(e){return b(e,"-")+" "+A(e,":")},localize:function(e){return e.setTime(e.getTime()-6e4*e.getTimezoneOffset()),e},ms:function(...e){if(!e.length||!e[0])return Date.now();let t=e[0];return"number"==typeof t?t:t instanceof Date?t.getTime():new Date(...e).getTime()},quantize:d,round:function(e,t){return d(e,t,"round")},ymd:b});return e.arr=t,e.clean=o,e.dig=a,e.gen=f,e.is=r,e.isEmpty=n,e.isEmptyOrFalsey=u,e.isEmptyOrFalsy=i,e.merge=s,e.subst=c,e.time=j,e.web=h,e}({});
|
package/dist/amekusa.util.cjs
CHANGED
|
@@ -160,7 +160,43 @@ function merge$1(x, y, opts = {}) {
|
|
|
160
160
|
return x.concat(y);
|
|
161
161
|
}
|
|
162
162
|
return y;
|
|
163
|
-
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Gets a property from the given object by the given string path.
|
|
167
|
+
* @param {object} obj - Object to traverse
|
|
168
|
+
* @param {string} path - Property names separated with '.'
|
|
169
|
+
* @return {any} value of the found property, or undefined if it's not found
|
|
170
|
+
*/
|
|
171
|
+
function dig(obj, path) {
|
|
172
|
+
path = path.split('.');
|
|
173
|
+
for (let i = 0; i < path.length; i++) {
|
|
174
|
+
let p = path[i];
|
|
175
|
+
if (typeof obj == 'object' && p in obj) obj = obj[p];
|
|
176
|
+
else return undefined;
|
|
177
|
+
}
|
|
178
|
+
return obj;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Substitutes the properties of the given data for the references in the given string.
|
|
183
|
+
* @param {string} str - String that contains references to the properties
|
|
184
|
+
* @param {object} data - Object that contains properties to replace the references
|
|
185
|
+
* @param {object} [opts] - Options
|
|
186
|
+
* @return {string} a modified `str`
|
|
187
|
+
*/
|
|
188
|
+
function subst(str, data, opts = {}) {
|
|
189
|
+
let {
|
|
190
|
+
modifier = null,
|
|
191
|
+
start = '{{',
|
|
192
|
+
end = '}}',
|
|
193
|
+
} = opts;
|
|
194
|
+
let ref = new RegExp(start + '\\s*([-.\\w]+)\\s*' + end, 'g');
|
|
195
|
+
return str.replaceAll(ref, modifier
|
|
196
|
+
? (_, m1) => (modifier(dig(data, m1), m1, data) || '')
|
|
197
|
+
: (_, m1) => (dig(data, m1) || '')
|
|
198
|
+
);
|
|
199
|
+
}var gen=/*#__PURE__*/Object.freeze({__proto__:null,arr:arr,clean:clean$1,dig:dig,is:is,isEmpty:isEmpty,isEmptyOrFalsey:isEmptyOrFalsey,isEmptyOrFalsy:isEmptyOrFalsy,merge:merge$1,subst:subst});/*!
|
|
164
200
|
* === @amekusa/util.js/web === *
|
|
165
201
|
* MIT License
|
|
166
202
|
*
|
|
@@ -478,7 +514,7 @@ function dev(set = undefined) {
|
|
|
478
514
|
if (set != undefined) node_process.env.NODE_ENV = set ? value : '';
|
|
479
515
|
return node_process.env.NODE_ENV == value;
|
|
480
516
|
}var sh=/*#__PURE__*/Object.freeze({__proto__:null,args:args,dev:dev,exec:exec,prod:prod});/*!
|
|
481
|
-
* === @amekusa/util.js/io === *
|
|
517
|
+
* === @amekusa/util.js/io/AssetImporter === *
|
|
482
518
|
* MIT License
|
|
483
519
|
*
|
|
484
520
|
* Copyright (c) 2024 Satoshi Soma
|
|
@@ -503,6 +539,188 @@ function dev(set = undefined) {
|
|
|
503
539
|
*/
|
|
504
540
|
|
|
505
541
|
/**
|
|
542
|
+
* This is for copying styles or scripts to a certain HTML directory.
|
|
543
|
+
* @author Satoshi Soma (github.com/amekusa)
|
|
544
|
+
*/
|
|
545
|
+
class AssetImporter {
|
|
546
|
+
/**
|
|
547
|
+
* @param {object} config
|
|
548
|
+
* @param {boolean} [config.minify=false] - Prefer `*.min.*` version
|
|
549
|
+
* @param {string} config.src - Source dir to search
|
|
550
|
+
* @param {string} config.dst - Destination dir
|
|
551
|
+
*/
|
|
552
|
+
constructor(config) {
|
|
553
|
+
this.config = Object.assign({
|
|
554
|
+
minify: false,
|
|
555
|
+
src: '', // source dir to search
|
|
556
|
+
dst: '', // destination dir
|
|
557
|
+
}, config);
|
|
558
|
+
this.queue = [];
|
|
559
|
+
this.results = {
|
|
560
|
+
script: [],
|
|
561
|
+
style: [],
|
|
562
|
+
asset: [],
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* Adds a new item to import.
|
|
567
|
+
* @param {string|string[]|object|object[]} newImport
|
|
568
|
+
*/
|
|
569
|
+
add(newImport) {
|
|
570
|
+
if (!Array.isArray(newImport)) newImport = [newImport];
|
|
571
|
+
for (let i = 0; i < newImport.length; i++) {
|
|
572
|
+
let item = newImport[i];
|
|
573
|
+
switch (typeof item) {
|
|
574
|
+
case 'string':
|
|
575
|
+
item = {src: item};
|
|
576
|
+
break;
|
|
577
|
+
case 'object':
|
|
578
|
+
if (Array.isArray(item)) throw `invalid type: array`;
|
|
579
|
+
break;
|
|
580
|
+
default:
|
|
581
|
+
throw `invalid type: ${typeof item}`;
|
|
582
|
+
}
|
|
583
|
+
if (!('src' in item)) throw `'src' property is missing`;
|
|
584
|
+
this.queue.push(Object.assign({
|
|
585
|
+
order: 0,
|
|
586
|
+
resolve: 'local',
|
|
587
|
+
private: false,
|
|
588
|
+
}, item));
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
592
|
+
* Resolves the location of the given file path
|
|
593
|
+
* @param {string} file - File path
|
|
594
|
+
* @param {string} method - Resolution method
|
|
595
|
+
* @return {string} Resolved file path
|
|
596
|
+
*/
|
|
597
|
+
resolve(file, method) {
|
|
598
|
+
let find = [];
|
|
599
|
+
if (this.config.minify) {
|
|
600
|
+
let _ext = ext(file);
|
|
601
|
+
find.push(ext(file, '.min' + _ext));
|
|
602
|
+
}
|
|
603
|
+
find.push(file);
|
|
604
|
+
for (let i = 0; i < find.length; i++) {
|
|
605
|
+
let r;
|
|
606
|
+
switch (method) {
|
|
607
|
+
case 'module':
|
|
608
|
+
try {
|
|
609
|
+
r = require.resolve(find[i]);
|
|
610
|
+
} catch (e) {
|
|
611
|
+
if (e.code == 'MODULE_NOT_FOUND') continue;
|
|
612
|
+
throw e;
|
|
613
|
+
}
|
|
614
|
+
return r;
|
|
615
|
+
case 'local':
|
|
616
|
+
r = path.join(this.config.src, find[i]);
|
|
617
|
+
if (fs.existsSync(r)) return r;
|
|
618
|
+
break;
|
|
619
|
+
case 'local:absolute':
|
|
620
|
+
case 'local:abs':
|
|
621
|
+
r = find[i];
|
|
622
|
+
if (fs.existsSync(r)) return r;
|
|
623
|
+
break;
|
|
624
|
+
default:
|
|
625
|
+
throw `invalid resolution method: ${method}`;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
throw `cannot resolve '${file}'`;
|
|
629
|
+
}
|
|
630
|
+
/**
|
|
631
|
+
* Imports all items in the queue at once.
|
|
632
|
+
*/
|
|
633
|
+
import() {
|
|
634
|
+
let typeMap = {
|
|
635
|
+
'.css': 'style',
|
|
636
|
+
'.js': 'script',
|
|
637
|
+
};
|
|
638
|
+
this.queue.sort((a, b) => (Number(a.order) - Number(b.order))); // sort by order
|
|
639
|
+
while (this.queue.length) {
|
|
640
|
+
let item = this.queue.shift();
|
|
641
|
+
let {type, src} = item;
|
|
642
|
+
let url;
|
|
643
|
+
|
|
644
|
+
if (!item.resolve) { // no resolution
|
|
645
|
+
url = src;
|
|
646
|
+
if (!type) type = typeMap[ext(src)] || 'asset';
|
|
647
|
+
console.log('---- File Link ----');
|
|
648
|
+
console.log(' type:', type);
|
|
649
|
+
console.log(' src:', src);
|
|
650
|
+
|
|
651
|
+
} else { // needs resolution
|
|
652
|
+
let {dst:dstDir, as:dstFile} = item;
|
|
653
|
+
let create = item.resolve == 'create'; // needs creation?
|
|
654
|
+
if (create) {
|
|
655
|
+
if (!dstFile) throw `'as' property is required with {resolve: 'create'}`;
|
|
656
|
+
} else {
|
|
657
|
+
src = this.resolve(src, item.resolve);
|
|
658
|
+
if (!dstFile) dstFile = path.basename(src);
|
|
659
|
+
}
|
|
660
|
+
if (!type) type = typeMap[ext(dstFile)] || 'asset';
|
|
661
|
+
if (!dstDir) dstDir = type + 's';
|
|
662
|
+
|
|
663
|
+
// absolute destination
|
|
664
|
+
url = path.join(dstDir, dstFile);
|
|
665
|
+
let dst = path.join(this.config.dst, url);
|
|
666
|
+
dstDir = path.dirname(dst);
|
|
667
|
+
if (!fs.existsSync(dstDir)) fs.mkdirSync(dstDir, {recursive:true});
|
|
668
|
+
if (create) {
|
|
669
|
+
fs.writeFileSync(dst, src);
|
|
670
|
+
console.log('---- File Creation ----');
|
|
671
|
+
console.log(' type:', type);
|
|
672
|
+
console.log(' dst:', dst);
|
|
673
|
+
} else {
|
|
674
|
+
fs.copyFileSync(src, dst);
|
|
675
|
+
console.log('---- File Import ----');
|
|
676
|
+
console.log(' type:', type);
|
|
677
|
+
console.log(' src:', src);
|
|
678
|
+
console.log(' dst:', dst);
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
if (!item.private) {
|
|
683
|
+
if (!(type in this.results)) this.results[type] = [];
|
|
684
|
+
this.results[type].push({type, url});
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
/**
|
|
689
|
+
* Outputs HTML tags for imported items.
|
|
690
|
+
* @param {string} [type] - Type
|
|
691
|
+
* @return {string} HTML
|
|
692
|
+
*/
|
|
693
|
+
toHTML(type = null) {
|
|
694
|
+
let r;
|
|
695
|
+
if (type) {
|
|
696
|
+
let tmpl = templates[type];
|
|
697
|
+
if (!tmpl) return '';
|
|
698
|
+
let items = this.results[type];
|
|
699
|
+
r = new Array(items.length);
|
|
700
|
+
for (let i = 0; i < items.length; i++) {
|
|
701
|
+
r[i] = tmpl.replaceAll('%s', items[i].url || '');
|
|
702
|
+
}
|
|
703
|
+
} else {
|
|
704
|
+
let keys = Object.keys(this.results);
|
|
705
|
+
r = new Array(keys.length);
|
|
706
|
+
for (let i = 0; i < keys.length; i++) {
|
|
707
|
+
r[i] = this.toHTML(keys[i]);
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
return r.join('\n');
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
const templates = {
|
|
715
|
+
'script':
|
|
716
|
+
`<script src="%s"></script>`,
|
|
717
|
+
|
|
718
|
+
'script:module':
|
|
719
|
+
`<script type="module" src="%s"></script>`,
|
|
720
|
+
|
|
721
|
+
'style':
|
|
722
|
+
`<link rel="stylesheet" href="%s">`,
|
|
723
|
+
};/**
|
|
506
724
|
* Alias of `os.homedir()`.
|
|
507
725
|
* @type {string}
|
|
508
726
|
*/
|
|
@@ -649,7 +867,7 @@ function modifyStream(fn) {
|
|
|
649
867
|
}
|
|
650
868
|
}
|
|
651
869
|
});
|
|
652
|
-
}var io=/*#__PURE__*/Object.freeze({__proto__:null,clean:clean,copy:copy,ext:ext,find:find,home:home,modifyStream:modifyStream,untilde:untilde});const merge = Object.assign;
|
|
870
|
+
}var io=/*#__PURE__*/Object.freeze({__proto__:null,AssetImporter:AssetImporter,clean:clean,copy:copy,ext:ext,find:find,home:home,modifyStream:modifyStream,untilde:untilde});const merge = Object.assign;
|
|
653
871
|
|
|
654
872
|
/*!
|
|
655
873
|
* === @amekusa/util.js/test === *
|
|
@@ -800,7 +1018,8 @@ function testMethod(construct, method, cases, opts = {}) {
|
|
|
800
1018
|
// ---- instantiate ----
|
|
801
1019
|
let obj;
|
|
802
1020
|
if (opts.static) {
|
|
803
|
-
if ('initArgs' in c) invalid(`'initArgs' is not for static method`);
|
|
1021
|
+
if ('initArgs' in c) invalid(`'initArgs' is not available for a static method`);
|
|
1022
|
+
if ('prepare' in c) invalid(`'prepare' is not available for a static method`);
|
|
804
1023
|
obj = construct;
|
|
805
1024
|
} else {
|
|
806
1025
|
let initArgs = [];
|
|
@@ -814,6 +1033,11 @@ function testMethod(construct, method, cases, opts = {}) {
|
|
|
814
1033
|
} catch (e) {
|
|
815
1034
|
obj = construct(...initArgs);
|
|
816
1035
|
}
|
|
1036
|
+
if ('prepare' in c) {
|
|
1037
|
+
if (typeof c.prepare != 'function') invalid(`'prepare' must be a function`);
|
|
1038
|
+
c.prepare(obj);
|
|
1039
|
+
delete c.prepare;
|
|
1040
|
+
}
|
|
817
1041
|
}
|
|
818
1042
|
|
|
819
1043
|
// ---- call method ----
|
|
@@ -923,4 +1147,4 @@ function testInstance(construct, cases, opts = {}) {
|
|
|
923
1147
|
}
|
|
924
1148
|
}
|
|
925
1149
|
});
|
|
926
|
-
}var test=/*#__PURE__*/Object.freeze({__proto__:null,InvalidTest:InvalidTest,assertEqual:assertEqual,assertProps:assertProps,assertType:assertType,testFn:testFn,testInstance:testInstance,testMethod:testMethod});exports.arr=arr;exports.clean=clean$1;exports.gen=gen;exports.io=io;exports.is=is;exports.isEmpty=isEmpty;exports.isEmptyOrFalsey=isEmptyOrFalsey;exports.isEmptyOrFalsy=isEmptyOrFalsy;exports.merge=merge$1;exports.sh=sh;exports.test=test;exports.time=time;exports.web=web;
|
|
1150
|
+
}var test=/*#__PURE__*/Object.freeze({__proto__:null,InvalidTest:InvalidTest,assertEqual:assertEqual,assertProps:assertProps,assertType:assertType,testFn:testFn,testInstance:testInstance,testMethod:testMethod});exports.arr=arr;exports.clean=clean$1;exports.dig=dig;exports.gen=gen;exports.io=io;exports.is=is;exports.isEmpty=isEmpty;exports.isEmptyOrFalsey=isEmptyOrFalsey;exports.isEmptyOrFalsy=isEmptyOrFalsy;exports.merge=merge$1;exports.sh=sh;exports.subst=subst;exports.test=test;exports.time=time;exports.web=web;
|
package/dist/amekusa.util.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import os from'node:os';import fs from'node:fs';import*as fsp from'node:fs/promises';import path
|
|
1
|
+
import os from'node:os';import fs from'node:fs';import*as fsp from'node:fs/promises';import path,{join,basename,dirname}from'node:path';import {Transform}from'node:stream';import {env}from'node:process';import {exec as exec$1}from'node:child_process';import assert from'node:assert';/*!
|
|
2
2
|
* === @amekusa/util.js/gen === *
|
|
3
3
|
* MIT License
|
|
4
4
|
*
|
|
@@ -160,7 +160,43 @@ function merge$1(x, y, opts = {}) {
|
|
|
160
160
|
return x.concat(y);
|
|
161
161
|
}
|
|
162
162
|
return y;
|
|
163
|
-
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Gets a property from the given object by the given string path.
|
|
167
|
+
* @param {object} obj - Object to traverse
|
|
168
|
+
* @param {string} path - Property names separated with '.'
|
|
169
|
+
* @return {any} value of the found property, or undefined if it's not found
|
|
170
|
+
*/
|
|
171
|
+
function dig(obj, path) {
|
|
172
|
+
path = path.split('.');
|
|
173
|
+
for (let i = 0; i < path.length; i++) {
|
|
174
|
+
let p = path[i];
|
|
175
|
+
if (typeof obj == 'object' && p in obj) obj = obj[p];
|
|
176
|
+
else return undefined;
|
|
177
|
+
}
|
|
178
|
+
return obj;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Substitutes the properties of the given data for the references in the given string.
|
|
183
|
+
* @param {string} str - String that contains references to the properties
|
|
184
|
+
* @param {object} data - Object that contains properties to replace the references
|
|
185
|
+
* @param {object} [opts] - Options
|
|
186
|
+
* @return {string} a modified `str`
|
|
187
|
+
*/
|
|
188
|
+
function subst(str, data, opts = {}) {
|
|
189
|
+
let {
|
|
190
|
+
modifier = null,
|
|
191
|
+
start = '{{',
|
|
192
|
+
end = '}}',
|
|
193
|
+
} = opts;
|
|
194
|
+
let ref = new RegExp(start + '\\s*([-.\\w]+)\\s*' + end, 'g');
|
|
195
|
+
return str.replaceAll(ref, modifier
|
|
196
|
+
? (_, m1) => (modifier(dig(data, m1), m1, data) || '')
|
|
197
|
+
: (_, m1) => (dig(data, m1) || '')
|
|
198
|
+
);
|
|
199
|
+
}var gen=/*#__PURE__*/Object.freeze({__proto__:null,arr:arr,clean:clean$1,dig:dig,is:is,isEmpty:isEmpty,isEmptyOrFalsey:isEmptyOrFalsey,isEmptyOrFalsy:isEmptyOrFalsy,merge:merge$1,subst:subst});/*!
|
|
164
200
|
* === @amekusa/util.js/web === *
|
|
165
201
|
* MIT License
|
|
166
202
|
*
|
|
@@ -478,7 +514,7 @@ function dev(set = undefined) {
|
|
|
478
514
|
if (set != undefined) env.NODE_ENV = set ? value : '';
|
|
479
515
|
return env.NODE_ENV == value;
|
|
480
516
|
}var sh=/*#__PURE__*/Object.freeze({__proto__:null,args:args,dev:dev,exec:exec,prod:prod});/*!
|
|
481
|
-
* === @amekusa/util.js/io === *
|
|
517
|
+
* === @amekusa/util.js/io/AssetImporter === *
|
|
482
518
|
* MIT License
|
|
483
519
|
*
|
|
484
520
|
* Copyright (c) 2024 Satoshi Soma
|
|
@@ -503,6 +539,188 @@ function dev(set = undefined) {
|
|
|
503
539
|
*/
|
|
504
540
|
|
|
505
541
|
/**
|
|
542
|
+
* This is for copying styles or scripts to a certain HTML directory.
|
|
543
|
+
* @author Satoshi Soma (github.com/amekusa)
|
|
544
|
+
*/
|
|
545
|
+
class AssetImporter {
|
|
546
|
+
/**
|
|
547
|
+
* @param {object} config
|
|
548
|
+
* @param {boolean} [config.minify=false] - Prefer `*.min.*` version
|
|
549
|
+
* @param {string} config.src - Source dir to search
|
|
550
|
+
* @param {string} config.dst - Destination dir
|
|
551
|
+
*/
|
|
552
|
+
constructor(config) {
|
|
553
|
+
this.config = Object.assign({
|
|
554
|
+
minify: false,
|
|
555
|
+
src: '', // source dir to search
|
|
556
|
+
dst: '', // destination dir
|
|
557
|
+
}, config);
|
|
558
|
+
this.queue = [];
|
|
559
|
+
this.results = {
|
|
560
|
+
script: [],
|
|
561
|
+
style: [],
|
|
562
|
+
asset: [],
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* Adds a new item to import.
|
|
567
|
+
* @param {string|string[]|object|object[]} newImport
|
|
568
|
+
*/
|
|
569
|
+
add(newImport) {
|
|
570
|
+
if (!Array.isArray(newImport)) newImport = [newImport];
|
|
571
|
+
for (let i = 0; i < newImport.length; i++) {
|
|
572
|
+
let item = newImport[i];
|
|
573
|
+
switch (typeof item) {
|
|
574
|
+
case 'string':
|
|
575
|
+
item = {src: item};
|
|
576
|
+
break;
|
|
577
|
+
case 'object':
|
|
578
|
+
if (Array.isArray(item)) throw `invalid type: array`;
|
|
579
|
+
break;
|
|
580
|
+
default:
|
|
581
|
+
throw `invalid type: ${typeof item}`;
|
|
582
|
+
}
|
|
583
|
+
if (!('src' in item)) throw `'src' property is missing`;
|
|
584
|
+
this.queue.push(Object.assign({
|
|
585
|
+
order: 0,
|
|
586
|
+
resolve: 'local',
|
|
587
|
+
private: false,
|
|
588
|
+
}, item));
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
592
|
+
* Resolves the location of the given file path
|
|
593
|
+
* @param {string} file - File path
|
|
594
|
+
* @param {string} method - Resolution method
|
|
595
|
+
* @return {string} Resolved file path
|
|
596
|
+
*/
|
|
597
|
+
resolve(file, method) {
|
|
598
|
+
let find = [];
|
|
599
|
+
if (this.config.minify) {
|
|
600
|
+
let _ext = ext(file);
|
|
601
|
+
find.push(ext(file, '.min' + _ext));
|
|
602
|
+
}
|
|
603
|
+
find.push(file);
|
|
604
|
+
for (let i = 0; i < find.length; i++) {
|
|
605
|
+
let r;
|
|
606
|
+
switch (method) {
|
|
607
|
+
case 'module':
|
|
608
|
+
try {
|
|
609
|
+
r = require.resolve(find[i]);
|
|
610
|
+
} catch (e) {
|
|
611
|
+
if (e.code == 'MODULE_NOT_FOUND') continue;
|
|
612
|
+
throw e;
|
|
613
|
+
}
|
|
614
|
+
return r;
|
|
615
|
+
case 'local':
|
|
616
|
+
r = join(this.config.src, find[i]);
|
|
617
|
+
if (fs.existsSync(r)) return r;
|
|
618
|
+
break;
|
|
619
|
+
case 'local:absolute':
|
|
620
|
+
case 'local:abs':
|
|
621
|
+
r = find[i];
|
|
622
|
+
if (fs.existsSync(r)) return r;
|
|
623
|
+
break;
|
|
624
|
+
default:
|
|
625
|
+
throw `invalid resolution method: ${method}`;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
throw `cannot resolve '${file}'`;
|
|
629
|
+
}
|
|
630
|
+
/**
|
|
631
|
+
* Imports all items in the queue at once.
|
|
632
|
+
*/
|
|
633
|
+
import() {
|
|
634
|
+
let typeMap = {
|
|
635
|
+
'.css': 'style',
|
|
636
|
+
'.js': 'script',
|
|
637
|
+
};
|
|
638
|
+
this.queue.sort((a, b) => (Number(a.order) - Number(b.order))); // sort by order
|
|
639
|
+
while (this.queue.length) {
|
|
640
|
+
let item = this.queue.shift();
|
|
641
|
+
let {type, src} = item;
|
|
642
|
+
let url;
|
|
643
|
+
|
|
644
|
+
if (!item.resolve) { // no resolution
|
|
645
|
+
url = src;
|
|
646
|
+
if (!type) type = typeMap[ext(src)] || 'asset';
|
|
647
|
+
console.log('---- File Link ----');
|
|
648
|
+
console.log(' type:', type);
|
|
649
|
+
console.log(' src:', src);
|
|
650
|
+
|
|
651
|
+
} else { // needs resolution
|
|
652
|
+
let {dst:dstDir, as:dstFile} = item;
|
|
653
|
+
let create = item.resolve == 'create'; // needs creation?
|
|
654
|
+
if (create) {
|
|
655
|
+
if (!dstFile) throw `'as' property is required with {resolve: 'create'}`;
|
|
656
|
+
} else {
|
|
657
|
+
src = this.resolve(src, item.resolve);
|
|
658
|
+
if (!dstFile) dstFile = basename(src);
|
|
659
|
+
}
|
|
660
|
+
if (!type) type = typeMap[ext(dstFile)] || 'asset';
|
|
661
|
+
if (!dstDir) dstDir = type + 's';
|
|
662
|
+
|
|
663
|
+
// absolute destination
|
|
664
|
+
url = join(dstDir, dstFile);
|
|
665
|
+
let dst = join(this.config.dst, url);
|
|
666
|
+
dstDir = dirname(dst);
|
|
667
|
+
if (!fs.existsSync(dstDir)) fs.mkdirSync(dstDir, {recursive:true});
|
|
668
|
+
if (create) {
|
|
669
|
+
fs.writeFileSync(dst, src);
|
|
670
|
+
console.log('---- File Creation ----');
|
|
671
|
+
console.log(' type:', type);
|
|
672
|
+
console.log(' dst:', dst);
|
|
673
|
+
} else {
|
|
674
|
+
fs.copyFileSync(src, dst);
|
|
675
|
+
console.log('---- File Import ----');
|
|
676
|
+
console.log(' type:', type);
|
|
677
|
+
console.log(' src:', src);
|
|
678
|
+
console.log(' dst:', dst);
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
if (!item.private) {
|
|
683
|
+
if (!(type in this.results)) this.results[type] = [];
|
|
684
|
+
this.results[type].push({type, url});
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
/**
|
|
689
|
+
* Outputs HTML tags for imported items.
|
|
690
|
+
* @param {string} [type] - Type
|
|
691
|
+
* @return {string} HTML
|
|
692
|
+
*/
|
|
693
|
+
toHTML(type = null) {
|
|
694
|
+
let r;
|
|
695
|
+
if (type) {
|
|
696
|
+
let tmpl = templates[type];
|
|
697
|
+
if (!tmpl) return '';
|
|
698
|
+
let items = this.results[type];
|
|
699
|
+
r = new Array(items.length);
|
|
700
|
+
for (let i = 0; i < items.length; i++) {
|
|
701
|
+
r[i] = tmpl.replaceAll('%s', items[i].url || '');
|
|
702
|
+
}
|
|
703
|
+
} else {
|
|
704
|
+
let keys = Object.keys(this.results);
|
|
705
|
+
r = new Array(keys.length);
|
|
706
|
+
for (let i = 0; i < keys.length; i++) {
|
|
707
|
+
r[i] = this.toHTML(keys[i]);
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
return r.join('\n');
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
const templates = {
|
|
715
|
+
'script':
|
|
716
|
+
`<script src="%s"></script>`,
|
|
717
|
+
|
|
718
|
+
'script:module':
|
|
719
|
+
`<script type="module" src="%s"></script>`,
|
|
720
|
+
|
|
721
|
+
'style':
|
|
722
|
+
`<link rel="stylesheet" href="%s">`,
|
|
723
|
+
};/**
|
|
506
724
|
* Alias of `os.homedir()`.
|
|
507
725
|
* @type {string}
|
|
508
726
|
*/
|
|
@@ -649,7 +867,7 @@ function modifyStream(fn) {
|
|
|
649
867
|
}
|
|
650
868
|
}
|
|
651
869
|
});
|
|
652
|
-
}var io=/*#__PURE__*/Object.freeze({__proto__:null,clean:clean,copy:copy,ext:ext,find:find,home:home,modifyStream:modifyStream,untilde:untilde});const merge = Object.assign;
|
|
870
|
+
}var io=/*#__PURE__*/Object.freeze({__proto__:null,AssetImporter:AssetImporter,clean:clean,copy:copy,ext:ext,find:find,home:home,modifyStream:modifyStream,untilde:untilde});const merge = Object.assign;
|
|
653
871
|
|
|
654
872
|
/*!
|
|
655
873
|
* === @amekusa/util.js/test === *
|
|
@@ -800,7 +1018,8 @@ function testMethod(construct, method, cases, opts = {}) {
|
|
|
800
1018
|
// ---- instantiate ----
|
|
801
1019
|
let obj;
|
|
802
1020
|
if (opts.static) {
|
|
803
|
-
if ('initArgs' in c) invalid(`'initArgs' is not for static method`);
|
|
1021
|
+
if ('initArgs' in c) invalid(`'initArgs' is not available for a static method`);
|
|
1022
|
+
if ('prepare' in c) invalid(`'prepare' is not available for a static method`);
|
|
804
1023
|
obj = construct;
|
|
805
1024
|
} else {
|
|
806
1025
|
let initArgs = [];
|
|
@@ -814,6 +1033,11 @@ function testMethod(construct, method, cases, opts = {}) {
|
|
|
814
1033
|
} catch (e) {
|
|
815
1034
|
obj = construct(...initArgs);
|
|
816
1035
|
}
|
|
1036
|
+
if ('prepare' in c) {
|
|
1037
|
+
if (typeof c.prepare != 'function') invalid(`'prepare' must be a function`);
|
|
1038
|
+
c.prepare(obj);
|
|
1039
|
+
delete c.prepare;
|
|
1040
|
+
}
|
|
817
1041
|
}
|
|
818
1042
|
|
|
819
1043
|
// ---- call method ----
|
|
@@ -923,4 +1147,4 @@ function testInstance(construct, cases, opts = {}) {
|
|
|
923
1147
|
}
|
|
924
1148
|
}
|
|
925
1149
|
});
|
|
926
|
-
}var test=/*#__PURE__*/Object.freeze({__proto__:null,InvalidTest:InvalidTest,assertEqual:assertEqual,assertProps:assertProps,assertType:assertType,testFn:testFn,testInstance:testInstance,testMethod:testMethod});export{arr,clean$1 as clean,gen,io,is,isEmpty,isEmptyOrFalsey,isEmptyOrFalsy,merge$1 as merge,sh,test,time,web};
|
|
1150
|
+
}var test=/*#__PURE__*/Object.freeze({__proto__:null,InvalidTest:InvalidTest,assertEqual:assertEqual,assertProps:assertProps,assertType:assertType,testFn:testFn,testInstance:testInstance,testMethod:testMethod});export{arr,clean$1 as clean,dig,gen,io,is,isEmpty,isEmptyOrFalsey,isEmptyOrFalsy,merge$1 as merge,sh,subst,test,time,web};
|