npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@shencom/utils-oss

v1.2.0

Published

oss静态资源工具

Downloads

64

Readme

@shencom/utils-oss

oss 静态资源工具,处理各种环境的 oss 静态路径和 CDN

Install

pnpm add @shencom/utils

# or

pnpm add @shencom/utils-oss

Basic Usage

const oss = new ScOssBase(Option);

Option

interface Option {
  /** 环境 */
  env: 'pro' | 'uat' | 'tst';
  /** pro环境下是否使用CDN,默认为: true */
  isCDN?: boolean;
  /** oss 项目路径 */
  projectPath: string;
  /** 开发静态资源路径,为空则是测试服链接 */
  devAssetsPath?: string;
}

| 参数 | 说明 | 类型 | 可选值 | 默认值 | | ------------- | ------------------------------------------------ | -------- | --------------------- | ------ | | env | 环境 | String | pro / uat / tst | 必填 | | isCDN | pro 环境下是否使用 CDN | Boolean | - | true | | projectPath | oss 项目路径 | String | - | 必填 | | devAssetsPath | 开发静态资源路径,为空则是测试服链接 | String | - | - | | urlList | oss 域名列表,只有符合域名的链接才能进行文件处理 | String[] | - | - |

urlList 默认存在 ['aliyuncs.com', 'filesvr.shencom.cn', 'oss.shencom.cn'] 设置 urlList 属性进行添加

Props

path

  • 说明: 项目路径
  • 类型: string
  • 示例:
    oss.path;

zoom

  • 说明: 图片缩放,默认: m:mfit w:100 h:100
  • 类型: string
  • 示例:
    oss.zoom;

Methods

zoomPercent

  • 说明: 图片百分比缩放,默认: 50%
  • 类型: zoomPercent(percent?: number): string
  • 参数:
    • percent: 缩放百分比
  • 示例:
    const zoom = oss.zoomPercent(percent);

zoomCustom

  • 说明: 自定义图片缩放,参考链接
  • 类型: zoomCustom(param?: {w?: string;h?: string;m?: string;}): string
  • 参数:
    • param: 缩放配置
  • 示例:
    const zoom = oss.zoomCustom(); // '?x-oss-process=image/resize,m_mfit,w_100,h_100'
    const zoom = oss.zoomCustom({ w: '50' }); // '?x-oss-process=image/resize,m_mfit,w_50,h_100'
    const zoom = oss.zoomCustom({ h: '50' }); // '?x-oss-process=image/resize,m_mfit,w_100,h_50'
    const zoom = oss.zoomCustom({ h: '200', w: '200' }); // '?x-oss-process=image/resize,m_mfit,w_200,h_200'
    const zoom = oss.zoomCustom({ m: 'lfit' }); // '?x-oss-process=image/resize,m_lfit,w_100,h_100'

isOssHost

  • 说明: 是否为 oss 链接
  • 类型: isOssHost(url: string): boolean
  • 参数:
    • url: 链接
  • 示例:
    const isOssHost = oss.isOssHost(url);

isImageZoom

  • 说明: 图片是否可缩放
  • 类型: isImageZoom(url: string): boolean
  • 参数:
    • url: 链接
  • 示例:
    const isImageZoom = oss.isImageZoom(url);

handleImageExt

  • 说明: 图片是否可缩放
  • 类型: handleImageExt(url: string, fileExt?: string): string
  • 参数:
    • url: 链接
    • fileExt: 默认处理为图片后缀名,默认: jpg
  • 示例:
    const url = oss.handleImageExt(url);

handleImageZoom

  • 说明: 处理 oss 图片缩放
    • 对链接进行验证 oss 文件验证,图片格式进行兼容处理
  • 类型: handleImageZoom(url: string, zoom?: string): string
  • 参数:
    • 图片链接: 链接
    • zoom: 图片缩放参数,默认: 30%
  • 示例:
    const url = oss.handleImageZoom(url);

Example

import { ScOssBase } from '@shencom/utils';
// import ScOssBase from '@shencom/utils-oss';

const oss = new ScOssBase({
  env: (IsPro ? 'pro' : IsDev) ? 'tst' : 'uat',
  projectPath: `app/${name}`,
  devAssetsPath: './assets',
});

export default oss;