UNPKG

@stdlib/esm

Version:

ES module distribution for Stdlib, a standard library for JavaScript and Node.js.

3 lines 2.94 kB
// This file is a part of stdlib. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 import r from"./../assert/is-string.js";import e from"./../assert/is-nonnegative-integer.js";import o from"./../assert/is-boolean.js";import t from"./../assert/is-plain-object.js";import n from"./../assert/has-own-property.js";import i from"./../string/left-pad.js";var s={0:"rwx",1:"rw",2:"rx",3:"r",4:"wx",5:"w",6:"x",7:""},a=i,l=s;function f(r){var e;return r=r.toString(8),r=a(r,4,"0"),e="",e+="u="+l[r[1]],e+=",",e+="g="+l[r[2]],e+=",",e+="o="+l[r[3]]}var u=i,m=/^(u{0,1}g{0,1}o{0,1}a{0,1}|)([+\-=])(r{0,1}w{0,1}x{0,1})$/,g={r:2,w:1,x:0},p={s:0,u:1,g:2,o:3};function c(r){return 1<<r>>>0}function h(r,e){return(r|c(e))>>>0}function b(r,e){return(r&~c(e))>>>0}function y(r,e){var o,t,n,i,s,a,l,f,c,y,w,v;for(o=u(r.toString(8),4,"0").split(""),y=0;y<o.length;y++)o[y]=parseInt(o[y],10);for(t=e.split(","),y=0;y<t.length;y++){if(null===(s=t[y].match(m)))return new Error('invalid argument. Unable to parse mask expression. Ensure the expression is properly formatted, only uses the class letters "u", "g", "o", and "a", only uses the operators "+", "-", and "=", and only uses the permission symbols "r", "w", and "x". Value: `'+e+"`.");if(""===(i=s[1]))i="ugo";else{for(f="",v=0;v<i.length;v++)"a"===i[v]?f+="ugo":f+=i[v];i=f}if(l=s[2],n=s[3],"-"===l){if(""===n)continue;for(w=0;w<n.length;w++)for(c=g[n[w]],v=0;v<i.length;v++)o[a=p[i[v]]]=h(o[a],c)}else if("+"===l){if(""===n)continue;for(w=0;w<n.length;w++)for(c=g[n[w]],v=0;v<i.length;v++)o[a=p[i[v]]]=b(o[a],c)}else if(""===n)for(v=0;v<i.length;v++)o[a=p[i[v]]]=7;else{for(v=0;v<i.length;v++)o[a=p[i[v]]]=7;for(w=0;w<n.length;w++)for(c=g[n[w]],v=0;v<i.length;v++)o[a=p[i[v]]]=b(o[a],c)}}for(y=0;y<o.length;y++)o[y]=o[y].toString();return parseInt(o.join(""),8)}var w=r.isPrimitive,v=e.isPrimitive,d=o.isPrimitive,j=t,x=n,E=f,T=y,V=0;function O(){var r,e,o,t,n;if(0===(e=arguments.length))return V;if(t={},n=arguments[0],1===e){if(w(n)){if((o=T(V,n))instanceof Error)throw o;return V}if(v(n))return V;if(j(n)){if(x(n,"symbolic")&&(t.symbolic=n.symbolic,!d(t.symbolic)))throw new TypeError("invalid option. `symbolic` option must be a boolean. Option: `"+t.symbolic+"`.");return o=V,t.symbolic&&(o=E(o)),o}throw new TypeError("invalid argument. Must provide either a string, nonnegative integer, or an options object. Value: `"+n+"`.")}if(!j(r=arguments[1]))throw new TypeError("invalid argument. Options argument must be an object. Value: `"+r+"`.");if(x(r,"symbolic")&&(t.symbolic=r.symbolic,!d(t.symbolic)))throw new TypeError("invalid option. `symbolic` option must be a boolean. Option: `"+t.symbolic+"`.");if(w(n)){if((o=T(V,n))instanceof Error)throw o}else{if(!v(n))throw new TypeError("invalid argument. First argument must be either a string or nonnegative integer. Value: `"+n+"`.");o=n}return o=V,t.symbolic&&(o=E(o)),o}export default O; //# sourceMappingURL=umask.js.map