Sha256: 167d43bb763d32168f3e0b142c824f1055f0a1ca4154e13faa4f3ee85ed25714

Contents?: true

Size: 927 Bytes

Versions: 3

Compression:

Stored size: 927 Bytes

Contents

# frozen_string_literal: true

module JsDependency
  module PathnameUtility
    # @param [Pathname] pathname
    # @return [Pathname]
    def self.complement_extname(pathname)
      return pathname if pathname.exist? || pathname.extname != ""

      %w[.js .jsx .vue].each do |ext|
        next unless pathname.sub_ext(ext).file?

        return pathname.sub_ext(ext)
      end

      pathname
    end

    # @param [String] target_path
    # @return [Pathname]
    def self.to_target_pathname(target_path)
      if Pathname.new(target_path).relative? && Pathname.new(target_path).exist?
        Pathname.new(target_path).realpath
      else
        Pathname.new(target_path)
      end
    end

    # @param [Pathname] pathname
    # @param [Integer] level
    def self.parse(pathname, level = -1)
      pathname.each_filename.with_object([]) { |filename, array| array << filename }.reverse[0..level].reverse
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
js_dependency-0.3.4 lib/js_dependency/pathname_utility.rb
js_dependency-0.3.3.1 lib/js_dependency/pathname_utility.rb
js_dependency-0.3.3 lib/js_dependency/pathname_utility.rb