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

process-model

v1.0.0

Published

obs,oss 等对象处理模型序列化

Downloads

14

Readme

ProcessModel

ProcessModel 定义了一些实用的方法来处理类似 /resize,w_200,h_200,m_fill,limit_0/format,webp/imageslim 的字符串。

api 类似URLSearchParams

使用场景

oss 数据处理

类似:https://image-demo.oss-cn-hangzhou.aliyuncs.com/example.jpg?x-oss-process=image/crop,x_100,y_50

obs 图片处理

类似:https://e-share.obs.cn-north-1.myhuaweicloud.com/example.jpg?x-image-process=image/resize,w_500,limit_0

其他...

使用

npm

npm install process-model -S

cdn

unpkg

https://www.unpkg.com/browse/process-model

jsdelivr

https://www.jsdelivr.com/package/npm/process-model
import ProcessModel from 'process-model'

const model = new ProcessModel()

model.append('resize', {
  w: 200,
  height: 200
})

model.delete('format')

model.has('resize')

model.set('resize', {
  w: 300
})

model.append('resize', 'w_400,h_500,limit_0')

model.sort()

model.toString() // /resize,w_400,h_500,limit_0

构造函数

ProcessModel(model, config)

返回一个ProcessModel 对象

model

字符串或者数组。对于同命令参数,后面的会覆盖前面的。

字符串

const modelInit = `/crop,x_100,y_50/format,webp`
const model = new ProcessModel(modelInit)

数组模型

const modelInit = [
  {
    name: 'crop', // 命令名称
    value: { // 命令值
      x: 100,
      y: 500
    }
  },
  {
    name: 'resize',
    value: 'w_200,h_200' // 命令值也可以是一个多参数字符串
  },
  {
    name: 'format',
    value: 'png'
  },
  {
    name: 'imageslim'
  }
]

const model = new ProcessModel(modelInit)

config

默认参数

  // 无参数命令合集
  withoutParamsCommand: ['info', 'average-hue', ...],
  // 多个参数的命令合集
  multipleArgCommand: ['resize', 'crop', 'circle', ...],
  // 命令排序规则
  commandSort: ['resize', 'crop', ..., 'info', 'average-hue'],
  // 管道分隔符
  PIPE_SEPARATOR: '/',
  // 参数分隔符
  PARAMETER_SEPARATOR: '_',
  // 命令分隔符
  COMMAND_SEPARATOR: ','

将参数分为三类

  1. 没有参数的命令; 例如 info,imageslim
  2. 只有一个参数的命令; 例如 format, interlace
  3. 多个参数的命令;例如resize

分别表示在上边的配置里

方法

append

追加参数。如果有同一个命令,参数会合并

model.append(name, value)

name: 命令名称;

value: 命令值;对象或者参数字符串;

model.append('resize', 'w_200,h_300,limit_0')
model.append('resize', {
	w: 400,
	h: 500,
	m: 'fill'
})
// 空值会被清除
model.append('resize', {
	m: null
})
model.append('info')
model.append('format', 'png')

model.toString() //  /resize,w_400,h_500,limit_0/format,png/info

set

设置参数。如果有同一个命令,会覆盖

model.set(name, value)

name: 命令名称;

value: 命令值;对象或者参数字符串;

model.set('resize', 'w_200,h_300,limit_0')
model.set('resize', {
	w: 400
})
model.set('info')
model.set('format', 'png')

model.toString() //  /resize,w_400/format,png/info

delete

删除指定命令

model.delete(name)

name: 命令名称;

model.set('resize', 'w_200,h_300,limit_0')
model.set('resize', {
	w: 400
})
model.set('info')
model.set('format', 'png')

model.delete('resize')

model.toString() //  /format,png/info

has

判断是否存在指定命令

model.has(name)

name: 命令名称;

model.set('resize', 'w_200,h_300,limit_0')
model.set('resize', {
	w: 400
})
model.set('info')
model.set('format', 'png')

model.delete('resize')

model.has('resize') //  false

sort

按照 config.commandSort 排序规则进行排序

model.sort()

toString

返回序列化字符串;已经按照 config.commandSort 排序规则进行排序过。在使用appendset 等命令时,无需关注顺序。

model.toString()

属性

VERSION

返回版本号

model.VERSION // 1.0.0