7

Releasing < validate-access > Validate project accessibility files

 4 years ago
source link: https://github.com/jalal246/validate-access
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

validate-access

Validate project accessibility files
npm install validate-access

API

validateAccess

/**
 * Validates access for `package.json` and project entry if
 * provided.
 *
 * @param {string} [dir="."] - project directory
 * @param {boolean} [isValidateEntry=false] - if false, it only validate `package.json`
 * @param {string} [entry="index"]
 * @param {string} [srcName="src"]
 *
 * @returns {Object} result
 * @returns {boolean} result.isValid - true, if access is valid
 * @returns {boolean} result.isSrc - true, if project contains src folder
 * @returns {string} result.ext - entry file extension
 */
function validateAccess({
  dir,
  isValidateEntry,
  entry,
  srcName
})

Example(1)

import { validateAccess } from "validate-access";

const { isValid, isSrc, ext } = validateAccess({
  dir: "path/to/valid",
  isValidateEntry: true
});

// { isValid: true, isSrc: true, ext: js }

getFileExtension

getFileExtension is used internally by validateAccess however it is exported for further use.

/**
 * Gets extension used in for given entry
 *
 * @param {string} dir - project directory
 * @param {string} entry - project file entry name
 * @returns {string|undefined} extension if exist
 */
function getFileExtension(dir, entry)

Example(2)

import { validateAccess } from "validate-access";

const extension = getFileExtension("path/to/valid", "index");

// extension > js

Related projects

Test

npm test

License

This project is licensed under the GPL-3.0 License


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK