diff --git a/.browserslistrc b/.browserslistrc index 3ea4d6b..5d1c5c6 100644 --- a/.browserslistrc +++ b/.browserslistrc @@ -1,3 +1,11 @@ >= 1% last 2 versions +Explorer >= 8 +Edge >= 12 +Firefox >= 21 +Chrome >= 23 +Safari >= 10 +Opera >= 10 +Android >= 3 +IOS >= 7 not dead \ No newline at end of file diff --git a/README.md b/README.md index e3d473c..28efc73 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,7 @@

Typescript 或者 JavaScript 的权限验证库

- Coverage Status + Coverage Status Size @@ -60,9 +57,9 @@ yarn add buession-shirojs ```vue diff --git a/package-lock.json b/package-lock.json index 1cda1ed..979745c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "buession-shirojs", - "version": "v1.0.0", + "version": "v1.0.1", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -13,6 +13,112 @@ "@babel/highlight": "^7.16.0" } }, + "@babel/compat-data": { + "version": "7.16.4", + "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.16.4.tgz", + "integrity": "sha512-1o/jo7D+kC9ZjHX5v+EHrdjl3PhxMrLSOTGsOdHJ+KL8HCaEK6ehrVL2RS6oHDZp+L7xLirLrPmQtEng769J/Q==", + "dev": true + }, + "@babel/core": { + "version": "7.16.0", + "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.16.0.tgz", + "integrity": "sha512-mYZEvshBRHGsIAiyH5PzCFTCfbWfoYbO/jcSdXQSUQu1/pW0xDZAUP7KEc32heqWTAfAHhV9j1vH8Sav7l+JNQ==", + "dev": true, + "requires": { + "@babel/code-frame": "^7.16.0", + "@babel/generator": "^7.16.0", + "@babel/helper-compilation-targets": "^7.16.0", + "@babel/helper-module-transforms": "^7.16.0", + "@babel/helpers": "^7.16.0", + "@babel/parser": "^7.16.0", + "@babel/template": "^7.16.0", + "@babel/traverse": "^7.16.0", + "@babel/types": "^7.16.0", + "convert-source-map": "^1.7.0", + "debug": "^4.1.0", + "gensync": "^1.0.0-beta.2", + "json5": "^2.1.2", + "semver": "^6.3.0", + "source-map": "^0.5.0" + }, + "dependencies": { + "source-map": { + "version": "0.5.7", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", + "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=", + "dev": true + } + } + }, + "@babel/generator": { + "version": "7.16.0", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.16.0.tgz", + "integrity": "sha512-RR8hUCfRQn9j9RPKEVXo9LiwoxLPYn6hNZlvUOR8tSnaxlD0p0+la00ZP9/SnRt6HchKr+X0fO2r8vrETiJGew==", + "dev": true, + "requires": { + "@babel/types": "^7.16.0", + "jsesc": "^2.5.1", + "source-map": "^0.5.0" + }, + "dependencies": { + "source-map": { + "version": "0.5.7", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", + "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=", + "dev": true + } + } + }, + "@babel/helper-compilation-targets": { + "version": "7.16.3", + "resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.16.3.tgz", + "integrity": "sha512-vKsoSQAyBmxS35JUOOt+07cLc6Nk/2ljLIHwmq2/NM6hdioUaqEXq/S+nXvbvXbZkNDlWOymPanJGOc4CBjSJA==", + "dev": true, + "requires": { + "@babel/compat-data": "^7.16.0", + "@babel/helper-validator-option": "^7.14.5", + "browserslist": "^4.17.5", + "semver": "^6.3.0" + } + }, + "@babel/helper-function-name": { + "version": "7.16.0", + "resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.16.0.tgz", + "integrity": "sha512-BZh4mEk1xi2h4HFjWUXRQX5AEx4rvaZxHgax9gcjdLWdkjsY7MKt5p0otjsg5noXw+pB+clMCjw+aEVYADMjog==", + "dev": true, + "requires": { + "@babel/helper-get-function-arity": "^7.16.0", + "@babel/template": "^7.16.0", + "@babel/types": "^7.16.0" + } + }, + "@babel/helper-get-function-arity": { + "version": "7.16.0", + "resolved": "https://registry.npmjs.org/@babel/helper-get-function-arity/-/helper-get-function-arity-7.16.0.tgz", + "integrity": "sha512-ASCquNcywC1NkYh/z7Cgp3w31YW8aojjYIlNg4VeJiHkqyP4AzIvr4qx7pYDb4/s8YcsZWqqOSxgkvjUz1kpDQ==", + "dev": true, + "requires": { + "@babel/types": "^7.16.0" + } + }, + "@babel/helper-hoist-variables": { + "version": "7.16.0", + "resolved": "https://registry.npmjs.org/@babel/helper-hoist-variables/-/helper-hoist-variables-7.16.0.tgz", + "integrity": "sha512-1AZlpazjUR0EQZQv3sgRNfM9mEVWPK3M6vlalczA+EECcPz3XPh6VplbErL5UoMpChhSck5wAJHthlj1bYpcmg==", + "dev": true, + "requires": { + "@babel/types": "^7.16.0" + } + }, + "@babel/helper-member-expression-to-functions": { + "version": "7.16.0", + "resolved": "https://registry.npmjs.org/@babel/helper-member-expression-to-functions/-/helper-member-expression-to-functions-7.16.0.tgz", + "integrity": "sha512-bsjlBFPuWT6IWhl28EdrQ+gTvSvj5tqVP5Xeftp07SEuz5pLnsXZuDkDD3Rfcxy0IsHmbZ+7B2/9SHzxO0T+sQ==", + "dev": true, + "requires": { + "@babel/types": "^7.16.0" + } + }, "@babel/helper-module-imports": { "version": "7.16.0", "resolved": "https://registry.npmmirror.com/@babel/helper-module-imports/download/@babel/helper-module-imports-7.16.0.tgz?cache=0&sync_timestamp=1635560941965&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2F%40babel%2Fhelper-module-imports%2Fdownload%2F%40babel%2Fhelper-module-imports-7.16.0.tgz", @@ -22,18 +128,90 @@ "@babel/types": "^7.16.0" } }, + "@babel/helper-module-transforms": { + "version": "7.16.0", + "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.16.0.tgz", + "integrity": "sha512-My4cr9ATcaBbmaEa8M0dZNA74cfI6gitvUAskgDtAFmAqyFKDSHQo5YstxPbN+lzHl2D9l/YOEFqb2mtUh4gfA==", + "dev": true, + "requires": { + "@babel/helper-module-imports": "^7.16.0", + "@babel/helper-replace-supers": "^7.16.0", + "@babel/helper-simple-access": "^7.16.0", + "@babel/helper-split-export-declaration": "^7.16.0", + "@babel/helper-validator-identifier": "^7.15.7", + "@babel/template": "^7.16.0", + "@babel/traverse": "^7.16.0", + "@babel/types": "^7.16.0" + } + }, + "@babel/helper-optimise-call-expression": { + "version": "7.16.0", + "resolved": "https://registry.npmjs.org/@babel/helper-optimise-call-expression/-/helper-optimise-call-expression-7.16.0.tgz", + "integrity": "sha512-SuI467Gi2V8fkofm2JPnZzB/SUuXoJA5zXe/xzyPP2M04686RzFKFHPK6HDVN6JvWBIEW8tt9hPR7fXdn2Lgpw==", + "dev": true, + "requires": { + "@babel/types": "^7.16.0" + } + }, "@babel/helper-plugin-utils": { "version": "7.14.5", "resolved": "https://registry.nlark.com/@babel/helper-plugin-utils/download/@babel/helper-plugin-utils-7.14.5.tgz?cache=0&sync_timestamp=1623280454367&other_urls=https%3A%2F%2Fregistry.nlark.com%2F%40babel%2Fhelper-plugin-utils%2Fdownload%2F%40babel%2Fhelper-plugin-utils-7.14.5.tgz", "integrity": "sha1-WsgizpfuxGdBq3ClF5ceRDpwxak=", "dev": true }, + "@babel/helper-replace-supers": { + "version": "7.16.0", + "resolved": "https://registry.npmjs.org/@babel/helper-replace-supers/-/helper-replace-supers-7.16.0.tgz", + "integrity": "sha512-TQxuQfSCdoha7cpRNJvfaYxxxzmbxXw/+6cS7V02eeDYyhxderSoMVALvwupA54/pZcOTtVeJ0xccp1nGWladA==", + "dev": true, + "requires": { + "@babel/helper-member-expression-to-functions": "^7.16.0", + "@babel/helper-optimise-call-expression": "^7.16.0", + "@babel/traverse": "^7.16.0", + "@babel/types": "^7.16.0" + } + }, + "@babel/helper-simple-access": { + "version": "7.16.0", + "resolved": "https://registry.npmjs.org/@babel/helper-simple-access/-/helper-simple-access-7.16.0.tgz", + "integrity": "sha512-o1rjBT/gppAqKsYfUdfHq5Rk03lMQrkPHG1OWzHWpLgVXRH4HnMM9Et9CVdIqwkCQlobnGHEJMsgWP/jE1zUiw==", + "dev": true, + "requires": { + "@babel/types": "^7.16.0" + } + }, + "@babel/helper-split-export-declaration": { + "version": "7.16.0", + "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.16.0.tgz", + "integrity": "sha512-0YMMRpuDFNGTHNRiiqJX19GjNXA4H0E8jZ2ibccfSxaCogbm3am5WN/2nQNj0YnQwGWM1J06GOcQ2qnh3+0paw==", + "dev": true, + "requires": { + "@babel/types": "^7.16.0" + } + }, "@babel/helper-validator-identifier": { "version": "7.15.7", "resolved": "https://registry.nlark.com/@babel/helper-validator-identifier/download/@babel/helper-validator-identifier-7.15.7.tgz?cache=0&sync_timestamp=1631920000984&other_urls=https%3A%2F%2Fregistry.nlark.com%2F%40babel%2Fhelper-validator-identifier%2Fdownload%2F%40babel%2Fhelper-validator-identifier-7.15.7.tgz", "integrity": "sha1-Ig35k7/pBKSmsCq08zhaXr9uI4k=", "dev": true }, + "@babel/helper-validator-option": { + "version": "7.14.5", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.14.5.tgz", + "integrity": "sha512-OX8D5eeX4XwcroVW45NMvoYaIuFI+GQpA2a8Gi+X/U/cDUIRsV37qQfF905F0htTRCREQIB4KqPeaveRJUl3Ow==", + "dev": true + }, + "@babel/helpers": { + "version": "7.16.3", + "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.16.3.tgz", + "integrity": "sha512-Xn8IhDlBPhvYTvgewPKawhADichOsbkZuzN7qz2BusOM0brChsyXMDJvldWaYMMUNiCQdQzNEioXTp3sC8Nt8w==", + "dev": true, + "requires": { + "@babel/template": "^7.16.0", + "@babel/traverse": "^7.16.3", + "@babel/types": "^7.16.0" + } + }, "@babel/highlight": { "version": "7.16.0", "resolved": "https://registry.npmmirror.com/@babel/highlight/download/@babel/highlight-7.16.0.tgz?cache=0&sync_timestamp=1635560940881&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2F%40babel%2Fhighlight%2Fdownload%2F%40babel%2Fhighlight-7.16.0.tgz", @@ -45,6 +223,12 @@ "js-tokens": "^4.0.0" } }, + "@babel/parser": { + "version": "7.16.4", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.16.4.tgz", + "integrity": "sha512-6V0qdPUaiVHH3RtZeLIsc+6pDhbYzHR8ogA8w+f+Wc77DuXto19g2QUwveINoS34Uw+W8/hQDGJCx+i4n7xcng==", + "dev": true + }, "@babel/plugin-proposal-nullish-coalescing-operator": { "version": "7.16.0", "resolved": "https://registry.npmmirror.com/@babel/plugin-proposal-nullish-coalescing-operator/download/@babel/plugin-proposal-nullish-coalescing-operator-7.16.0.tgz?cache=0&sync_timestamp=1635567364161&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2F%40babel%2Fplugin-proposal-nullish-coalescing-operator%2Fdownload%2F%40babel%2Fplugin-proposal-nullish-coalescing-operator-7.16.0.tgz", @@ -73,6 +257,34 @@ "@babel/helper-plugin-utils": "^7.8.0" } }, + "@babel/template": { + "version": "7.16.0", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.16.0.tgz", + "integrity": "sha512-MnZdpFD/ZdYhXwiunMqqgyZyucaYsbL0IrjoGjaVhGilz+x8YB++kRfygSOIj1yOtWKPlx7NBp+9I1RQSgsd5A==", + "dev": true, + "requires": { + "@babel/code-frame": "^7.16.0", + "@babel/parser": "^7.16.0", + "@babel/types": "^7.16.0" + } + }, + "@babel/traverse": { + "version": "7.16.3", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.16.3.tgz", + "integrity": "sha512-eolumr1vVMjqevCpwVO99yN/LoGL0EyHiLO5I043aYQvwOJ9eR5UsZSClHVCzfhBduMAsSzgA/6AyqPjNayJag==", + "dev": true, + "requires": { + "@babel/code-frame": "^7.16.0", + "@babel/generator": "^7.16.0", + "@babel/helper-function-name": "^7.16.0", + "@babel/helper-hoist-variables": "^7.16.0", + "@babel/helper-split-export-declaration": "^7.16.0", + "@babel/parser": "^7.16.3", + "@babel/types": "^7.16.0", + "debug": "^4.1.0", + "globals": "^11.1.0" + } + }, "@babel/types": { "version": "7.16.0", "resolved": "https://registry.npmmirror.com/@babel/types/download/@babel/types-7.16.0.tgz?cache=0&sync_timestamp=1635560908248&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2F%40babel%2Ftypes%2Fdownload%2F%40babel%2Ftypes-7.16.0.tgz", @@ -623,6 +835,19 @@ "concat-map": "0.0.1" } }, + "browserslist": { + "version": "4.18.1", + "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.18.1.tgz", + "integrity": "sha512-8ScCzdpPwR2wQh8IT82CA2VgDwjHyqMovPBZSNH54+tm4Jk2pCuv90gmAdH6J84OCRWi0b4gMe6O6XPXuJnjgQ==", + "dev": true, + "requires": { + "caniuse-lite": "^1.0.30001280", + "electron-to-chromium": "^1.3.896", + "escalade": "^3.1.1", + "node-releases": "^2.0.1", + "picocolors": "^1.0.0" + } + }, "buffer-from": { "version": "1.1.2", "resolved": "https://registry.nlark.com/buffer-from/download/buffer-from-1.1.2.tgz", @@ -651,6 +876,12 @@ "integrity": "sha1-s2MKvYlDQy9Us/BRkjjjPNffL3M=", "dev": true }, + "caniuse-lite": { + "version": "1.0.30001284", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001284.tgz", + "integrity": "sha512-t28SKa7g6kiIQi6NHeOcKrOrGMzCRrXvlasPwWC26TH2QNdglgzQIRUuJ0cR3NeQPH+5jpuveeeSFDLm2zbkEw==", + "dev": true + }, "chalk": { "version": "2.4.2", "resolved": "https://registry.npmmirror.com/chalk/download/chalk-2.4.2.tgz", @@ -707,6 +938,23 @@ "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", "dev": true }, + "convert-source-map": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.8.0.tgz", + "integrity": "sha512-+OQdjP49zViI/6i7nIJpA8rAl4sV/JdPfU9nZs3VqOwGIgizICvuN2ru6fMd+4llL0tar18UYJXfZ/TWtmhUjA==", + "dev": true, + "requires": { + "safe-buffer": "~5.1.1" + }, + "dependencies": { + "safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", + "dev": true + } + } + }, "cross-spawn": { "version": "6.0.5", "resolved": "https://registry.nlark.com/cross-spawn/download/cross-spawn-6.0.5.tgz", @@ -761,6 +1009,12 @@ "esutils": "^2.0.2" } }, + "electron-to-chromium": { + "version": "1.4.10", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.10.tgz", + "integrity": "sha512-tFgA40Iq2oy4k2PnZrLJowbgpij+lD6ZLxkw8Ht1NKTYyN8dvSvC5xlo8X0WW2jqhKSzITrbr5mpB4/AZ/8OUA==", + "dev": true + }, "emoji-regex": { "version": "8.0.0", "resolved": "https://registry.npmmirror.com/emoji-regex/download/emoji-regex-8.0.0.tgz?cache=0&sync_timestamp=1632751408145&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2Femoji-regex%2Fdownload%2Femoji-regex-8.0.0.tgz", @@ -806,6 +1060,12 @@ "is-symbol": "^1.0.2" } }, + "escalade": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", + "integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==", + "dev": true + }, "escape-string-regexp": { "version": "1.0.5", "resolved": "https://registry.nlark.com/escape-string-regexp/download/escape-string-regexp-1.0.5.tgz", @@ -1504,6 +1764,12 @@ "is-glob": "^4.0.1" } }, + "globals": { + "version": "11.12.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz", + "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==", + "dev": true + }, "graceful-fs": { "version": "4.2.8", "resolved": "https://registry.npmmirror.com/graceful-fs/download/graceful-fs-4.2.8.tgz", @@ -1897,6 +2163,12 @@ "esprima": "^4.0.0" } }, + "jsesc": { + "version": "2.5.2", + "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz", + "integrity": "sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==", + "dev": true + }, "json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.nlark.com/json-schema-traverse/download/json-schema-traverse-0.4.1.tgz", @@ -1909,6 +2181,15 @@ "integrity": "sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=", "dev": true }, + "json5": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.0.tgz", + "integrity": "sha512-f+8cldu7X/y7RAJurMEJmdoKXGB/X550w2Nr3tTbezL6RwEE/iMcm+tZnXeoZtKuOq6ft8+CqzEkrIgx1fPoQA==", + "dev": true, + "requires": { + "minimist": "^1.2.5" + } + }, "jsonfile": { "version": "4.0.0", "resolved": "https://registry.nlark.com/jsonfile/download/jsonfile-4.0.0.tgz", @@ -2021,6 +2302,12 @@ "integrity": "sha1-ozeKdpbOfSI+iPybdkvX7xCJ42Y=", "dev": true }, + "node-releases": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.1.tgz", + "integrity": "sha512-CqyzN6z7Q6aMeF/ktcMVTzhAHCEpf8SOarwpzpf8pNBY2k5/oM34UHldUwp8VKI7uxct2HxSRdJjBaZeESzcxA==", + "dev": true + }, "object-inspect": { "version": "1.11.0", "resolved": "https://registry.nlark.com/object-inspect/download/object-inspect-1.11.0.tgz?cache=0&sync_timestamp=1626120241132&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fobject-inspect%2Fdownload%2Fobject-inspect-1.11.0.tgz", @@ -2176,6 +2463,12 @@ } } }, + "picocolors": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz", + "integrity": "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==", + "dev": true + }, "picomatch": { "version": "2.3.0", "resolved": "https://registry.nlark.com/picomatch/download/picomatch-2.3.0.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fpicomatch%2Fdownload%2Fpicomatch-2.3.0.tgz", diff --git a/package.json b/package.json index 783abdc..3acd374 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "name": "buession-shirojs", "alias": "shirojs", - "version": "v1.0.0", + "version": "v1.0.1", "description": "A security framework for JavaScript or TypeScript.", - "homepage": "https://github.com/buession/buession-shirojs", + "homepage": "https://buession.github.io/buession-shirojs/", "author": { "name": "yong.teng", "email": "webmaster@buession.com" @@ -20,7 +20,7 @@ "scripts": { "build": "npm cache clean --force && rollup -c build/rollup.config.js", "lint": "eslint -c ./.eslintrc.js './{src,scripts,build}/**/*.{js,ts,tsx}'", - "release": "yarn build && yarn publishing" + "release": "yarn build && yarn publish" }, "keywords": [ "buession", @@ -42,6 +42,7 @@ ], "dependencies": {}, "devDependencies": { + "@babel/core": "^7.16.0", "@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0", "@babel/plugin-syntax-jsx": "^7.16.0", "@rollup/plugin-json": "^4.1.0", diff --git a/src/core/constants.ts b/src/core/constants.ts new file mode 100644 index 0000000..f94b777 --- /dev/null +++ b/src/core/constants.ts @@ -0,0 +1 @@ +export const ALL_PERMISSION = ':'; \ No newline at end of file diff --git a/src/core/types.ts b/src/core/types.ts index af2c28c..66ed4b8 100644 --- a/src/core/types.ts +++ b/src/core/types.ts @@ -1,3 +1,6 @@ +export type T_STRING = string | null | undefined; +export type T_STRING_ARRAY = string[] | null | undefined; + export interface Principal { /** @@ -13,7 +16,7 @@ export interface Principal { * @param id * 用户 ID */ - setId(id:string): void, + setId(id: string): void, /** * 返回用户角色名称列表 @@ -28,7 +31,7 @@ export interface Principal { * @param roleNames * 用户角色名称列表 */ - setRoles(roleNames:string[]): void, + setRoles(roleNames: string[]): void, /** * 添加用户角色 @@ -36,7 +39,7 @@ export interface Principal { * @param roleName * 用户角色名称 */ - addRole(roleName:string): void, + addRole(roleName: string): void, /** * 批量添加用户角色 @@ -44,7 +47,7 @@ export interface Principal { * @param roleNames * 用户角色名称列表 */ - addRoles(roleNames:string[]): void, + addRoles(roleNames: string[]): void, /** * 返回用户权限列表 @@ -59,7 +62,7 @@ export interface Principal { * @param permissions * 用户权限列表 */ - setPermissions(permissions:string[]): void, + setPermissions(permissions: string[]): void, /** * 添加用户权限 @@ -67,7 +70,7 @@ export interface Principal { * @param permission * 用户权限 */ - addPermission(permission:string): void, + addPermission(permission: string): void, /** * 批量添加用户权限 @@ -75,10 +78,10 @@ export interface Principal { * @param permissions * 用户权限列表 */ - addPermissions(permissions:string[]): void + addPermissions(permissions: string[]): void } -export interface Shiro { +export interface IShiro { /** * 验证是否为已认证通过的用户,不包含已记住的用户,这是与 isUser 标签方法的区别所在 @@ -116,7 +119,7 @@ export interface Shiro { * * @return 用户是否具备某角色 */ - hasRole(roleName:string): boolean; + hasRole(roleName: string): boolean; /** * 验证用户是否不具备某角色,与 hasRole 逻辑相反 @@ -126,7 +129,7 @@ export interface Shiro { * * @return 用户是否不具备某角色 */ - lacksRole(roleName:string): boolean; + lacksRole(roleName: string): boolean; /** * 验证用户是否具有以下任意一个角色 @@ -136,17 +139,17 @@ export interface Shiro { * * @return 用户是否具有以下任意一个角色 */ - hasAnyRole(roleNames:string[]): boolean; + hasAnyRole(roleNames: string[]): boolean; /** - * 验证用户是否具有以下所有角色。 + * 验证用户是否具有以下所有角色 * * @param roleNames * 角色列表 * * @return 用户是否具有以下所有角色 */ - hasRolesAll(roleNames:string[]): boolean; + hasRolesAll(roleNames: string[]): boolean; /** * 验证用户是否具备某权限 @@ -156,7 +159,7 @@ export interface Shiro { * * @return 用户是否具备某权限 */ - hasPermission(permission:string): boolean; + hasPermission(permission: string): boolean; /** * 验证用户是否不具备某权限,与 hasPermission 逻辑相反 @@ -166,7 +169,7 @@ export interface Shiro { * * @return 用户是否不具备某权限 */ - lacksPermission(permission:string): boolean; + lacksPermission(permission: string): boolean; /** * 验证用户是否具有以下任意一个权限 @@ -176,7 +179,7 @@ export interface Shiro { * * @return 用户是否具有以下任意一个权限 */ - hasAnyPermission(permissions:string[]): boolean; + hasAnyPermission(permissions: string[]): boolean; /** * 验证用户是否具有以下所有权限 @@ -186,6 +189,6 @@ export interface Shiro { * * @return 用户是否具有以下所有权限 */ - hasPermissionsAll(permissions:string[]): boolean; + hasPermissionsAll(permissions: string[]): boolean; } \ No newline at end of file diff --git a/src/index.d.ts b/src/index.d.ts index d6d82eb..bdf3500 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -1,5 +1,7 @@ -import { ShiroImpl as Shiro } from './shiro'; +import { IShiro } from './shiro'; -export declare const Shiro: ShiroImpl; +export { Principal } from './core/types'; + +export declare const Shiro: IShiro; export default Shiro; \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 38bf9a0..699cc13 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,5 @@ -import { ShiroImpl as Shiro } from './shiro'; +import { Shiro } from './shiro'; + +export { Principal } from './core/types'; export default Shiro; \ No newline at end of file diff --git a/src/shiro.ts b/src/shiro.ts index 229b181..691921b 100644 --- a/src/shiro.ts +++ b/src/shiro.ts @@ -1,13 +1,10 @@ -import { Principal, Shiro } from './core/types' - +import { ALL_PERMISSION } from './core/constants' +import { Principal, IShiro } from './core/types' import { hasAny, hasAll } from './utils/common' -export class ShiroImpl implements Shiro { - - private readonly $principal:Principal; +export class Shiro implements IShiro { - constructor(public principal:Principal) { - this.$principal = principal; + constructor(public readonly principal: Principal) { } /** @@ -16,7 +13,7 @@ export class ShiroImpl implements Shiro { * @return 用户是否已通过认证 */ isAuthenticated(): boolean { - return this.$principal !== null; + return this.principal !== null; } /** @@ -34,7 +31,7 @@ export class ShiroImpl implements Shiro { * @return 用户是否为访客 */ isGuest(): boolean { - return this.$principal === null; + return this.principal === null; } /** @@ -43,7 +40,7 @@ export class ShiroImpl implements Shiro { * @return 用户是否认证通过或已记住的用户 */ isUser(): boolean { - return this.$principal !== null; + return this.principal !== null; } /** @@ -54,8 +51,8 @@ export class ShiroImpl implements Shiro { * * @return 用户是否具备某角色 */ - hasRole(roleName:string): boolean { - return this.isAuthenticated() && hasAny(this.$principal.getRoles(), roleName); + hasRole(roleName: string): boolean { + return this.isAuthenticated() && hasAny(this.principal.getRoles(), roleName); } /** @@ -66,7 +63,7 @@ export class ShiroImpl implements Shiro { * * @return 用户是否不具备某角色 */ - lacksRole(roleName:string): boolean { + lacksRole(roleName: string): boolean { return this.hasRole(roleName) === false; } @@ -78,13 +75,13 @@ export class ShiroImpl implements Shiro { * * @return 用户是否具有以下任意一个角色 */ - hasAnyRole(roleNames:string[]): boolean { + hasAnyRole(roleNames: string[]): boolean { if (this.isAuthenticated() == false) { return false; } for (let roleName of roleNames) { - if (hasAny(this.$principal.getRoles(), roleName)) { + if (hasAny(this.principal.getRoles(), roleName)) { return true; } } @@ -100,8 +97,8 @@ export class ShiroImpl implements Shiro { * * @return 用户是否具有以下所有角色 */ - hasRolesAll(roleNames:string[]): boolean { - return this.isAuthenticated() && hasAll(this.$principal.getRoles(), roleNames); + hasRolesAll(roleNames: string[]): boolean { + return this.isAuthenticated() && hasAll(this.principal.getRoles(), roleNames); } /** @@ -112,8 +109,8 @@ export class ShiroImpl implements Shiro { * * @return 用户是否具备某权限 */ - hasPermission(permission:string): boolean { - return this.isAuthenticated() && hasAny(this.$principal.getPermissions(), permission); + hasPermission(permission: string): boolean { + return this.isAuthenticated() && (hasAny(this.principal.getPermissions(), permission) || hasAny(this.principal.getPermissions(), ALL_PERMISSION)); } /** @@ -124,7 +121,7 @@ export class ShiroImpl implements Shiro { * * @return 用户是否不具备某权限 */ - lacksPermission(permission:string): boolean { + lacksPermission(permission: string): boolean { return this.hasPermission(permission) === false; } @@ -136,13 +133,17 @@ export class ShiroImpl implements Shiro { * * @return 用户是否具有以下任意一个权限 */ - hasAnyPermission(permissions:string[]): boolean { + hasAnyPermission(permissions: string[]): boolean { if (this.isAuthenticated() == false) { return false; } + if (hasAny(this.principal.getPermissions(), ALL_PERMISSION)) { + return true; + } + for (let permission of permissions) { - if (hasAny(this.$principal.getPermissions(), permission)) { + if (hasAny(this.principal.getPermissions(), permission)) { return true; } } @@ -158,8 +159,8 @@ export class ShiroImpl implements Shiro { * * @return 用户是否具有以下所有权限 */ - hasPermissionsAll(permissions:string[]): boolean { - return hasAll(this.$principal.getPermissions(), permissions); + hasPermissionsAll(permissions: string[]): boolean { + return hasAny(this.principal.getPermissions(), ALL_PERMISSION) || hasAll(this.principal.getPermissions(), permissions); } } \ No newline at end of file diff --git a/src/utils/common.ts b/src/utils/common.ts index 02a9ae7..19014f3 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -1,10 +1,10 @@ -type FindTypes = string[] | null | undefined; +import { T_STRING, T_STRING_ARRAY } from '../core/types' -export const hasAny = (data:FindTypes, value:any) => { +export const hasAny = (data: T_STRING_ARRAY, value: any, all:T_STRING = null): boolean => { return typeof data !== 'undefined' && data != null ? data.indexOf(value) >= 0 : false; } -export const hasAll = (data:FindTypes, values:any[]) => { +export const hasAll = (data: T_STRING_ARRAY, values: any[], all:T_STRING = null): boolean => { if (typeof data !== 'undefined' && data != null) { for (let value of values) { if (data.indexOf(value) < 0) { diff --git a/tsconfig.json b/tsconfig.json index 5a869d0..7866909 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "baseUrl": "./", - "target": "esnext", + "target": "es5", "module": "esnext", "strict": true, "jsx": "preserve",