UNPKG

unix-permissions

Version:
36 lines (21 loc) 504 B
import{NONE}from"./constants.js"; export const tokenize=(octal)=>{ if(typeof octal!=="string"){ return{} } const tokens=OCTAL_REGEXP.exec(octal); if(tokens===null){ return{} } const[,operator,string]=tokens; const operatorA=addDefaultOperator({operator}); return{operator:operatorA,string} }; const OCTAL_REGEXP=/^\s*([=+-]?)\\?0?[oO]?([0-7]{1,4})\s*$/u; const addDefaultOperator=({operator})=>{ if(operator===NONE){ return DEFAULT_OPERATOR } return operator }; const DEFAULT_OPERATOR="=";