How to use path-parse - 10 common examples

To help you get started, we’ve selected a few path-parse examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Wildhoney / Switzerland / src / middleware / include.js View on Github external
const fetchInclude = memoize(file => {

    const cssPath = parsePath(file).dir;

    const transformPaths = content => {

        const urls = parseUrls(content);

        // Update the URLs to make them relative to the CSS document.
        return urls.length ? urls.map(url => {
            const replacer = new RegExp(escapeRegExp(url), 'ig');
            return content.replace(replacer, `${cssPath}/${url}`);
        }).toString() : content;

    };

    return new Promise(resolve => {

        global.fetch(file).then(response => response.text())
github microsoft / ConversationLearner-UI / cypress / support / TestList.js View on Github external
export function AddToCypressTestList() {
  var funcName = `AddToCypressTestList()`
  //                                                                              test group name--\      /--Test function name
  // callerFileName looks like: http://localhost:5050/__cypress/tests?p=cypress\integration\Tests\Train\WhatsYourName1.js-044
  var callerFileName = GetCallerFileName()
  callerFileName = path.normalize(callerFileName.substring(callerFileName.lastIndexOf("p=") + 2, callerFileName.lastIndexOf("-"))).replace(/\\/g, path.sep)
  helpers.ConLog(funcName, `callerFileName: ${callerFileName}`)

  const parsed = pathParse.posix(callerFileName)
  const testName = parsed.name
  const testGroupName = parsed.dir.substr(parsed.dir.lastIndexOf(path.sep) + 1)

  var allTests = (testName == '(All)')
  var allGroups = (allTests && testGroupName == 'Tests')
  var toFind = `function ${testName}(`
  helpers.ConLog(funcName, `testGroup: ${testGroupName} - testName: ${testName} - allTests: ${allTests} - allGroups ${allGroups} - toFind: ${toFind}`)

  var group
  for (var i = 0; i < testGroups.length; i++) {
    if (allGroups || testGroups[i].name == testGroupName) {
      group = testGroups[i]

      var test
      describe(group.name, () => {
        helpers.ConLog(funcName, `Added Group: ${group.name}`)
github js-dxtools / webpack-validator / test / passing-configs / index.js View on Github external
const filePathToConfigObj = (filepath) => {
  let config = require(filepath)
  if (config.default) {
    config = config.default
  }
  return {
    config,
    filepath,
    name: pathParse(filepath).name,
  }
}
github kentcdodds / webpack-validator-DEPRECATED / tests / passing-configs / index.js View on Github external
export function filePathToConfigObj(filepath) {
  let config = require(filepath)
  if (config.default) {
    config = config.default
  }
  return {
    config,
    filepath,
    name: pathParse(filepath).name,
  }
}
github keybase / client / shared / util / file.shared.tsx View on Github external
function findAvailableFilename(
  checkExists: (arg0: string) => Promise,
  filepath: string
): Promise {
  const {name, ext, dir} = pathParse(filepath)

  return new Promise((resolve, reject) => {
    let i = 1
    let fp = filepath
    function tryNextFilepath() {
      if (i > 1000) {
        throw new Error('unable to find available filename')
      }
      checkExists(fp)
        .then(filepathExists => {
          if (!filepathExists) {
            resolve(fp)
            return
          }

          fp = [dir, `${name} (${i})${ext}`].join('/')
github theKashey / rewiremock / src / mocks.js View on Github external
const getMock = (name, scope = getScope()) => {
  const {mocks} = scope;
  const fn = parse(name);
  const shortName = join(fn.dir, fn.name);
  const wshortName = fn.dir + '/' + fn.name;
  const indexName = fn.name === 'index' ? fn.dir : null;

  const mock =
    pickFrom(mocks, name) || (indexName && pickFrom(mocks, indexName)) ||
    pickFrom(mocks, shortName) || pickFrom(mocks, wshortName);


  if (!mock && scope.parentScope) {
    return getMock(name, scope.parentScope);
  }
  return mock;
};
github Wildhoney / Switzerland / src / helpers / path.js View on Github external
const scriptPath = (() => {

    try {
        return parsePath(document.currentScript.getAttribute('src')).dir;
    } catch (err) {}

    try {
        return parsePath(self.location.href).dir;
    } catch (err) {}

    return '';

})();
github Wildhoney / Switzerland / src / helpers / path.js View on Github external
const scriptPath = (() => {

    try {
        return parsePath(document.currentScript.getAttribute('src')).dir;
    } catch (err) {}

    try {
        return parsePath(self.location.href).dir;
    } catch (err) {}

    return '';

})();
github heartbeatua / Pulse-Boilerplate / styleguide / routes.js View on Github external
const routes = context.keys().map(key => {
  const { dir, ext, name } = pathParse(key.replace(/\.\//, ''));
  const path = key
    .replace(ext, '')
    .replace(/\./, '')
    .replace(/\/index/, '');

  return {
    key,
    dirname: dir,
    name: name === 'index' && dir ? dir : name,
    path: path || '/',
    component: context(key).default,
  };
});
github OctoLinker / OctoLinker / packages / plugin-sass / index.js View on Github external
resolve(path, [target]) {
    const { dir, name } = pathParse(target);
    const prefixedTarget = join(dir, `_${name}`);

    return [
      relativeFile({ path, target: `${prefixedTarget}.scss` }),
      relativeFile({ path, target: `${prefixedTarget}.sass` }),
      githubSearch({ path, target: `${prefixedTarget}.scss` }),
      githubSearch({ path, target: `${prefixedTarget}.sass` }),
    ];
  },

path-parse

Node.js path.parse() ponyfill

MIT
Latest version published 3 years ago

Package Health Score

67 / 100
Full package analysis

Popular path-parse functions