web-one 0.0.9 → 0.0.10

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/lib/index.js CHANGED
@@ -753,3 +753,43 @@ function getOffset(limit, page, firstLimit) {
753
753
  }
754
754
  }
755
755
  exports.getOffset = getOffset;
756
+ function isValidPath(path) {
757
+ const len = path.length;
758
+ if (len === 0) {
759
+ return false;
760
+ }
761
+ for (let i = 0; i < len; i++) {
762
+ const c = path.charCodeAt(i);
763
+ if (c >= 97 && c <= 122)
764
+ continue;
765
+ if (c >= 65 && c <= 90)
766
+ continue;
767
+ if (c >= 48 && c <= 57)
768
+ continue;
769
+ if (c === 95 || c === 45 || c === 47)
770
+ continue;
771
+ return false;
772
+ }
773
+ return true;
774
+ }
775
+ exports.isValidPath = isValidPath;
776
+ function isValidSlug(path) {
777
+ const len = path.length;
778
+ if (len === 0) {
779
+ return false;
780
+ }
781
+ for (let i = 0; i < len; i++) {
782
+ const c = path.charCodeAt(i);
783
+ if (c >= 97 && c <= 122)
784
+ continue;
785
+ if (c >= 65 && c <= 90)
786
+ continue;
787
+ if (c >= 48 && c <= 57)
788
+ continue;
789
+ if (c === 95 || c === 45)
790
+ continue;
791
+ return false;
792
+ }
793
+ return true;
794
+ }
795
+ exports.isValidSlug = isValidSlug;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-one",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "description": "Web utilities",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./src/index.ts",
package/src/index.ts CHANGED
@@ -759,3 +759,42 @@ export function getOffset(limit: number, page?: number, firstLimit?: number): nu
759
759
  return offset < 0 ? 0 : offset
760
760
  }
761
761
  }
762
+
763
+ export function isValidPath(path: string): boolean {
764
+ const len = path.length;
765
+ if (len === 0) {
766
+ return false;
767
+ }
768
+ for (let i = 0; i < len; i++) {
769
+ const c = path.charCodeAt(i);
770
+ // a-z
771
+ if (c >= 97 && c <= 122) continue;
772
+ // A-Z
773
+ if (c >= 65 && c <= 90) continue;
774
+ // 0-9
775
+ if (c >= 48 && c <= 57) continue;
776
+ // _, -, /
777
+ if (c === 95 || c === 45 || c === 47) continue;
778
+ return false;
779
+ }
780
+ return true;
781
+ }
782
+ export function isValidSlug(path: string): boolean {
783
+ const len = path.length;
784
+ if (len === 0) {
785
+ return false;
786
+ }
787
+ for (let i = 0; i < len; i++) {
788
+ const c = path.charCodeAt(i);
789
+ // a-z
790
+ if (c >= 97 && c <= 122) continue;
791
+ // A-Z
792
+ if (c >= 65 && c <= 90) continue;
793
+ // 0-9
794
+ if (c >= 48 && c <= 57) continue;
795
+ // _, -, /
796
+ if (c === 95 || c === 45) continue;
797
+ return false;
798
+ }
799
+ return true;
800
+ }