Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@transloadit/analyze-step

Package Overview
Dependencies
Maintainers
3
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@transloadit/analyze-step - npm Package Compare versions

Comparing version 0.0.15 to 0.0.16

74

analyzeStep.js
const formatDurationMs = require('@transloadit/format-duration-ms')
const formatBytes = require('prettier-bytes')
const prettierBytes = require('@transloadit/prettier-bytes')
const inflect = require('inflect')
const _ = require('lodash')
const jp = require('jsonpath')
const jp = require('jsonpath')

@@ -40,17 +40,18 @@ function humanJoin (array, reduce = true, glueword = 'and') {

const templates = {
'<' : 'files with a {humanKey} below {humanVal}',
'<=' : 'files with a {humanKey} of {humanVal} or lower',
'>' : 'files with a {humanKey} above {humanVal}',
'>=' : 'files with a {humanKey} of {humanVal} or higher',
'=' : 'files with a {humanKey} of {humanVal}',
'==' : 'files with a {humanKey} of {humanVal}',
'===' : 'files with a {humanKey} of {humanVal}',
'!=' : 'files without a {humanKey} of {humanVal}',
'!==' : 'files without a {humanKey} of {humanVal}',
regex : 'files with a {humanKey} of {humanVal}',
'!regex' : 'files without a {humanKey} of {humanVal}',
includes : 'files that include a {humanKey} of {humanVal}',
'!includes': 'files that do not include a {humanKey} of {humanVal}',
'<' : 'files with {humanKey} below {humanVal}',
'<=' : 'files with {humanKey} of {humanVal} or lower',
'>' : 'files with {humanKey} above {humanVal}',
'>=' : 'files with {humanKey} of {humanVal} or higher',
'=' : 'files with {humanKey} of {humanVal}',
'==' : 'files with {humanKey} of {humanVal}',
'===' : 'files with {humanKey} of {humanVal}',
'!=' : 'files without {humanKey} of {humanVal}',
'!==' : 'files without {humanKey} of {humanVal}',
regex : 'files with {humanKey} of {humanVal}',
'!regex' : 'files without {humanKey} of {humanVal}',
includes : 'files that include {humanKey} of {humanVal}',
'!includes': 'files that do not include {humanKey} of {humanVal}',
}
let lastTemplate = ''
const types = ['declines', 'accepts']

@@ -86,6 +87,6 @@ for (const type of types) {

if (humanKey === 'filesize') {
humanVal = formatBytes(parseInt(humanVal, 10), 1)
humanVal = prettierBytes(parseInt(humanVal, 10), 1)
}
if (humanKey.match(/ bitrate$/) && humanVal) {
humanVal = `${formatBytes(parseInt(humanVal, 10), 1)}`.replace('B', 'bit/s')
humanVal = `${prettierBytes(parseInt(humanVal, 10), 1)}`.replace('B', 'bit/s')
}

@@ -99,3 +100,15 @@ if (humanKey === 'duration') {

let humanDescr = template
if (humanKey === `${humanKey}` && inflect.singularize(humanKey) === `${humanKey}` && !`${humanKey}`.match(/^\d+/) && humanKey !== '') {
humanKey = `a ${humanKey}`
}
if (humanVal === `${humanVal}` && inflect.singularize(humanVal) === `${humanVal}` && !`${humanVal}`.match(/^\d+/) && humanVal !== '') {
humanVal = `a ${humanVal}`
}
let useTemplate = template
if (lastTemplate === template) {
useTemplate = useTemplate.replace(/^[^{]+({.*)$/, '$1')
}
let humanDescr = useTemplate
.replace(/{humanKey}/g, humanKey)

@@ -105,2 +118,3 @@ .replace(/{humanVal}/g, humanVal)

if (humanVal === '' || humanVal === false || humanVal === 'false') {
// Swap with & without via an intermediary step:
humanDescr = humanDescr.replace('without', 'wi2th')

@@ -118,2 +132,3 @@ humanDescr = humanDescr.replace('with', 'without')

collection[type].push(humanDescr)
lastTemplate = template
}

@@ -134,3 +149,3 @@ }

total.push('Filter ' + joinacc)
total.push('Pick ' + joinacc)
}

@@ -140,11 +155,18 @@

return strTotal
.replace(/files with a mime-type of application\/x-subripg/g, 'subtitles')
.replace(/files with a mime-type of image\/jpe?g/g, 'JPEG images')
.replace(/files with a mime-type of image/g, 'images')
.replace(/files with a mime-type of audio/g, 'audio files')
.replace(/files with a mime-type of video/g, 'videos')
.replace(/files with a mime-type of archives/g, 'archives')
.replace(/(\W)a audio/g, '$1an audio')
.replace(/(\W)a image/g, '$1an image')
.replace(/files with a (mime-)?type of a application\/x-subripg/g, 'subtitles')
.replace(/files with a (mime-)?type of an image\/jpe?g/g, 'JPEG images')
.replace(/files with a (mime-)?type of an image/g, 'images')
.replace(/files with a (mime-)?type of an audio/g, 'audio files')
.replace(/files with a (mime-)?type of a video/g, 'videos')
.replace(/files with a (mime-)?type of archives/g, 'archives')
.replace(/and a (mime-)?type of a application\/x-subripg/g, 'and subtitles')
.replace(/and a (mime-)?type of an image\/jpe?g/g, 'and JPEG images')
.replace(/and a (mime-)?type of an image/g, 'and images')
.replace(/and a (mime-)?type of an audio/g, 'audio and files')
.replace(/and a (mime-)?type of a video/g, 'and videos')
.replace(/and a (mime-)?type of archives/g, 'and archives')
.replace(/files with a filesize above/g, 'files bigger than')
.replace(/files with a filesize below/g, 'files smaller than')
.replace(/a audio/g, 'an audio')
}

@@ -151,0 +173,0 @@

@@ -9,4 +9,13 @@ const analyzeStep = require('./analyzeStep.js')

rname : '/image/resize',
purpose_words: 'foobar',
purpose_words: 'Convert, resize, or watermark images',
},
'/file/filter': {
rname : '/file/filter',
purpose_words: 'Filter files',
},
'/image/describe': {
rname : '/image/describe',
purpose_words: 'Recognize objects in images',
},
}

@@ -38,4 +47,223 @@ expect(analyzeStep({

expect(analyzeStep({ robot: '/image/resize', width: '75', height: '75' }, robots)).toMatch('Resize images to 75×75')
expect(analyzeStep({
result : true,
use : 'described',
robot : '/file/filter',
accepts: [
[
'${file.meta.descriptions}',
'includes',
'Bridge',
],
],
}, robots)).toMatch('Pick files that include descriptions of a Bridge')
expect(analyzeStep({
use : ':original',
robot : '/file/filter',
accepts: [
[
'${file.type}',
'===',
'video',
],
],
}, robots)).toMatch('Pick videos')
expect(analyzeStep({
use : ':original',
robot : '/file/filter',
declines: [
[
'${file.meta.audio_bitrate}',
'<',
'65536',
],
],
result: true,
}, robots)).toMatch('Reject files with an audio bitrate below 64 Kbit/s')
expect(analyzeStep({
use : ':original',
robot : '/file/filter',
declines: [
[
'${file.meta.width}',
'!=',
'1920',
],
[
'${file.meta.height}',
'!=',
'1080',
],
],
condition_type: 'and',
result : true,
}, robots)).toMatch('Reject files without a width of 1920 and a height of 1080')
expect(analyzeStep({
use : ':original',
robot : '/file/filter',
result : true,
accepts: [
[
'${file.mime}',
'regex',
'image',
],
],
error_on_decline: true,
}, robots)).toMatch('Pick images')
expect(analyzeStep({
use : ':original',
robot : '/file/filter',
result : true,
accepts: [
[
'${file.mime}',
'regex',
'image',
],
[
'${file.mime}',
'regex',
'video',
],
],
error_on_decline: true,
}, robots)).toMatch('Pick images and videos')
expect(analyzeStep({
use : ':original',
robot : '/file/filter',
accepts: [
[
'${file.size}',
'>=',
'1024',
],
],
result: true,
}, robots)).toMatch('Pick files with a filesize of 1 KB or higher')
expect(analyzeStep({
use : ':original',
robot : '/file/filter',
result : true,
accepts: [
[
'${file.meta.aspect_ratio}',
'>',
'1.0',
],
[
'${file.mime}',
'regex',
'image',
],
],
condition_type: 'and',
}, robots)).toMatch('Pick files with a aspect ratio above 1.0 and images')
expect(analyzeStep({
use : ':original',
robot : '/file/filter',
result : true,
declines: [
[
'${file.size}',
'>',
'20971520',
],
[
'${file.meta.duration}',
'>=',
'300',
],
],
error_on_decline: true,
}, robots)).toMatch('Reject files bigger than 20 MB and files with a duration of 5m or higher')
expect(analyzeStep({
use : ':original',
robot : '/file/filter',
result : true,
accepts: [
[
'${file.meta.width}',
'<=',
'2048',
],
[
'${file.meta.height}',
'<=',
'2048',
],
],
condition_type: 'or',
}, robots)).toMatch('Pick files with a width of 2048 or lower or a height of 2048 or lower')
expect(analyzeStep({
use : ':original',
robot : '/file/filter',
result : true,
declines: [
[
'${file.mime}',
'regex',
'application/(rar|x-7z-compressed|x-cab|x-cpio|x-debian-package|x-gtar-compressed|x-gzip|x-lzh|x-redhat-package-manager|x-tar|zip)',
],
],
error_on_decline: false,
}, robots)).toMatch('Reject archives')
expect(analyzeStep({
use : ':original',
robot : '/file/filter',
result : true,
declines: [
[
'${file.meta.audio_bitrate}',
'==',
'',
],
],
error_on_decline: true,
}, robots)).toMatch('Reject files without an audio bitrate')
expect(analyzeStep({
use : ':original',
robot : '/file/filter',
accepts: [
[
'${file.type}',
'===',
'image',
],
[
'${file.type}',
'===',
'video',
],
],
}, robots)).toMatch('Pick images and videos')
expect(analyzeStep({
use : ':original',
robot : '/image/describe',
provider : 'aws',
format : 'meta',
granularity: 'list',
result : true,
}, robots)).toMatch('Recognize objects in images')
expect(analyzeStep({
robot : '/image/resize',
width : '75',
height: '75',
},
robots)).toMatch('Resize images to 75×75')
})
})

@@ -16,9 +16,9 @@ {

"@transloadit/format-duration-ms": "^0.0.28",
"@transloadit/prettier-bytes": "^0.0.6",
"inflect": "0.4.0",
"jsonpath": "1.0.2",
"lodash": "4.17.15",
"prettier-bytes": "1.0.4"
"lodash": "4.17.15"
},
"version": "0.0.15",
"gitHead": "5f289155f9dc269ff69b66b2cb87a67338a3e2c4"
"version": "0.0.16",
"gitHead": "b92d69208409c6b3aebf2ff78b34a0a61a07da46"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc