time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

regexp.js (3003B)


      1 /**
      2 * @license Apache-2.0
      3 *
      4 * Copyright (c) 2018 The Stdlib Authors.
      5 *
      6 * Licensed under the Apache License, Version 2.0 (the "License");
      7 * you may not use this file except in compliance with the License.
      8 * You may obtain a copy of the License at
      9 *
     10 *    http://www.apache.org/licenses/LICENSE-2.0
     11 *
     12 * Unless required by applicable law or agreed to in writing, software
     13 * distributed under the License is distributed on an "AS IS" BASIS,
     14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15 * See the License for the specific language governing permissions and
     16 * limitations under the License.
     17 */
     18 
     19 'use strict';
     20 
     21 // MODULES //
     22 
     23 var reDirnamePosix = require( './main.js' );
     24 
     25 
     26 // MAIN //
     27 
     28 /**
     29 * Captures a POSIX path dirname. Modified from Node.js [source][1].
     30 *
     31 * Regular expression: `/^((?:\.(?![^\/]))|(?:(?:\/?|)(?:[\s\S]*?)))(?:\/+?|)(?:(?:\.{1,2}|[^\/]+?|)(?:\.[^.\/]*|))(?:[\/]*)$/`
     32 *
     33 * -   `\^`
     34 *     -   match any string which begins with
     35 *
     36 * -   `()`
     37 *     -   capture (includes root and dirname)
     38 *
     39 * -   `(?:)`
     40 *     -   capture but do not remember (handles `'.'` and `'./'` cases)
     41 *
     42 * -   `\.(?![^\/])`
     43 *     -   a `.` literal if the `.` literal is NOT followed by something other than a `/` literal
     44 *
     45 * -   `|`
     46 *     -   OR
     47 *
     48 * -   `(?:)`
     49 *     -   capture but do not remember (handles root+dirname case)
     50 *
     51 * -   `(?:)`
     52 *     -   capture but do not remember (root)
     53 *
     54 * -   `\/?`
     55 *     -   match a `/` literal zero or one time
     56 *
     57 * -   `|)`
     58 *     -   OR capture nothing
     59 *
     60 * -   `(?:)`
     61 *     -   capture but do not remember (directory)
     62 *
     63 * -   `[\s\S]`
     64 *     -   any space or non-space character
     65 *
     66 * -   `*?`
     67 *     -   zero or more times, but non-greedily (shortest possible match)
     68 *
     69 * -   `(?:)`
     70 *     -   capture but do not remember (slash)
     71 *
     72 * -   `\/+?`
     73 *     -   a `/` literal one or more times, but do so non-greedily
     74 *
     75 * -   `|)`
     76 *     -   OR capture nothing
     77 *
     78 * -   `(?:)`
     79 *     -   capture but do not remember (basename)
     80 *
     81 * -   `\.{1,2}`
     82 *     -   match a `.` literal one or two times
     83 *
     84 * -   `|`
     85 *     -   OR
     86 *
     87 * -   `[^\/]+?`
     88 *     -   match anything which is not a `/` literal one or more times, but do so non-greedily
     89 *
     90 * -   `|)`
     91 *     -   OR capture nothing
     92 *
     93 * -   `(?:)`
     94 *     -   capture but do not remember (extname)
     95 *
     96 * -   `\.`
     97 *     -   match a `.` literal
     98 *
     99 * -   `[^.\/]`
    100 *     -   match anything which is not a `.` or `/` literal
    101 *
    102 * -   `*`
    103 *     -   zero or more times
    104 *
    105 * -   `|)`
    106 *     -   OR capture nothing
    107 *
    108 * -   `(?:)`
    109 *     -   capture but do not remember (trailing slash)
    110 *
    111 * -   `[\/]`
    112 *     -   match a `/` literal
    113 *
    114 * -   `*`
    115 *     -   zero or more times
    116 *
    117 * -   `$`
    118 *     -   end of string
    119 *
    120 * [1]: https://github.com/nodejs/node/blob/1a3b295d0f46b2189bd853800b1e63ab4d106b66/lib/path.js#L406
    121 *
    122 * @constant
    123 * @type {RegExp}
    124 * @default /^((?:\.(?![^\/]))|(?:(?:\/?|)(?:[\s\S]*?)))(?:\/+?|)(?:(?:\.{1,2}|[^\/]+?|)(?:\.[^.\/]*|))(?:[\/]*)$/
    125 */
    126 var RE_DIRNAME_POSIX = reDirnamePosix();
    127 
    128 
    129 // EXPORTS //
    130 
    131 module.exports = RE_DIRNAME_POSIX;