Socket
Socket
Sign inDemoInstall

@std-uritemplate/std-uritemplate

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@std-uritemplate/std-uritemplate - npm Package Compare versions

Comparing version 0.0.46 to 0.0.47

2

dist/index.d.ts

@@ -19,2 +19,4 @@ type Substitutions = {

private static isEmpty;
private static isNativeType;
private static convertNativeTypes;
private static expandToken;

@@ -21,0 +23,0 @@ private static addStringValue;

67

dist/index.js

@@ -17,5 +17,6 @@ "use strict";

(function (SubstitutionType) {
SubstitutionType[SubstitutionType["STRING"] = 0] = "STRING";
SubstitutionType[SubstitutionType["LIST"] = 1] = "LIST";
SubstitutionType[SubstitutionType["MAP"] = 2] = "MAP";
SubstitutionType[SubstitutionType["EMPTY"] = 0] = "EMPTY";
SubstitutionType[SubstitutionType["STRING"] = 1] = "STRING";
SubstitutionType[SubstitutionType["LIST"] = 2] = "LIST";
SubstitutionType[SubstitutionType["MAP"] = 3] = "MAP";
})(SubstitutionType || (SubstitutionType = {}));

@@ -217,3 +218,3 @@ class StdUriTemplate {

case Operator.HASH:
StdUriTemplate.addExpandedValue(value, result, maxChar, false);
StdUriTemplate.addExpandedValue(null, value, result, maxChar, false);
break;

@@ -223,10 +224,7 @@ case Operator.QUESTION_MARK:

result.push(`${token}=`);
StdUriTemplate.addExpandedValue(value, result, maxChar, true);
StdUriTemplate.addExpandedValue(null, value, result, maxChar, true);
break;
case Operator.SEMICOLON:
result.push(token);
if (value.length > 0) {
result.push('=');
}
StdUriTemplate.addExpandedValue(value, result, maxChar, true);
StdUriTemplate.addExpandedValue('=', value, result, maxChar, true);
break;

@@ -236,3 +234,3 @@ case Operator.DOT:

case Operator.NO_OP:
StdUriTemplate.addExpandedValue(value, result, maxChar, true);
StdUriTemplate.addExpandedValue(null, value, result, maxChar, true);
break;

@@ -245,3 +243,3 @@ }

case Operator.HASH:
StdUriTemplate.addExpandedValue(value, result, maxChar, false);
StdUriTemplate.addExpandedValue(null, value, result, maxChar, false);
break;

@@ -254,11 +252,15 @@ case Operator.QUESTION_MARK:

case Operator.NO_OP:
StdUriTemplate.addExpandedValue(value, result, maxChar, true);
StdUriTemplate.addExpandedValue(null, value, result, maxChar, true);
break;
}
}
static addExpandedValue(value, result, maxChar, replaceReserved) {
const max = maxChar !== -1 ? Math.min(maxChar, value.length) : value.length;
static addExpandedValue(prefix, value, result, maxChar, replaceReserved) {
const stringValue = StdUriTemplate.convertNativeTypes(value);
const max = maxChar !== -1 ? Math.min(maxChar, stringValue.length) : stringValue.length;
let reservedBuffer = undefined;
if (max > 0 && prefix != null) {
result.push(prefix);
}
for (let i = 0; i < max; i++) {
const character = value.charAt(i);
const character = stringValue.charAt(i);
if (character === '%' && !replaceReserved) {

@@ -329,3 +331,6 @@ reservedBuffer = [];

static getSubstitutionType(value, col) {
if (typeof value === 'string' || value === undefined || value === null) {
if (value === undefined || value === null) {
return SubstitutionType.EMPTY;
}
else if (StdUriTemplate.isNativeType(value)) {
return SubstitutionType.STRING;

@@ -360,2 +365,22 @@ }

}
static isNativeType(value) {
return (typeof value === 'string' ||
typeof value === 'number' ||
typeof value === 'boolean' ||
value instanceof Date);
}
static convertNativeTypes(value) {
if (typeof value === 'string') {
return value;
}
else if (typeof value === 'number' || typeof value === 'boolean') {
return value.toString();
}
else if (value instanceof Date) {
return value.toISOString().split('.')[0] + "Z";
}
else {
throw new Error(`Illegal class passed as substitution, found ${typeof value}`);
}
}
static expandToken(operator, token, composite, maxChar, firstToken, substitutions, result, col) {

@@ -365,11 +390,5 @@ if (token.length === 0) {

}
let value = substitutions[token];
if (typeof value === 'number' || typeof value === 'boolean') {
value = value.toString();
}
else if (value instanceof Date) {
value = value.toISOString().split('.')[0] + "Z";
}
const value = substitutions[token];
const substType = StdUriTemplate.getSubstitutionType(value, col);
if (StdUriTemplate.isEmpty(substType, value)) {
if (substType === SubstitutionType.EMPTY || StdUriTemplate.isEmpty(substType, value)) {
return false;

@@ -376,0 +395,0 @@ }

{
"name": "@std-uritemplate/std-uritemplate",
"version": "0.0.46",
"version": "0.0.47",
"description": "std-uritemplate implementation for TS/JS",

@@ -5,0 +5,0 @@ "scripts": {

@@ -175,3 +175,3 @@ # std-uritemplate

url: "https://github.com/std-uritemplate/std-uritemplate-swift.git",
from: "0.0.26"
from: "<version>"
)

@@ -178,0 +178,0 @@ ],

@@ -15,2 +15,3 @@ type Substitutions = { [key: string]: any };

enum SubstitutionType {
EMPTY,
STRING,

@@ -229,7 +230,7 @@ LIST,

private static addValue(op: Operator | null, token: string, value: string, result: string[], maxChar: number): void {
private static addValue(op: Operator | null, token: string, value: any, result: string[], maxChar: number): void {
switch (op) {
case Operator.PLUS:
case Operator.HASH:
StdUriTemplate.addExpandedValue(value, result, maxChar, false);
StdUriTemplate.addExpandedValue(null, value, result, maxChar, false);
break;

@@ -239,10 +240,7 @@ case Operator.QUESTION_MARK:

result.push(`${token}=`);
StdUriTemplate.addExpandedValue(value, result, maxChar, true);
StdUriTemplate.addExpandedValue(null, value, result, maxChar, true);
break;
case Operator.SEMICOLON:
result.push(token);
if (value.length > 0) {
result.push('=');
}
StdUriTemplate.addExpandedValue(value, result, maxChar, true);
StdUriTemplate.addExpandedValue('=', value, result, maxChar, true);
break;

@@ -252,3 +250,3 @@ case Operator.DOT:

case Operator.NO_OP:
StdUriTemplate.addExpandedValue(value, result, maxChar, true);
StdUriTemplate.addExpandedValue(null, value, result, maxChar, true);
break;

@@ -258,7 +256,7 @@ }

private static addValueElement(op: Operator | null, token: string, value: string, result: string[], maxChar: number): void {
private static addValueElement(op: Operator | null, token: string, value: any, result: string[], maxChar: number): void {
switch (op) {
case Operator.PLUS:
case Operator.HASH:
StdUriTemplate.addExpandedValue(value, result, maxChar, false);
StdUriTemplate.addExpandedValue(null, value, result, maxChar, false);
break;

@@ -271,3 +269,3 @@ case Operator.QUESTION_MARK:

case Operator.NO_OP:
StdUriTemplate.addExpandedValue(value, result, maxChar, true);
StdUriTemplate.addExpandedValue(null, value, result, maxChar, true);
break;

@@ -277,8 +275,13 @@ }

private static addExpandedValue(value: string, result: string[], maxChar: number, replaceReserved: boolean): void {
const max = maxChar !== -1 ? Math.min(maxChar, value.length) : value.length;
private static addExpandedValue(prefix: string | null, value: any, result: string[], maxChar: number, replaceReserved: boolean): void {
const stringValue = StdUriTemplate.convertNativeTypes(value);
const max = maxChar !== -1 ? Math.min(maxChar, stringValue.length) : stringValue.length;
let reservedBuffer: string[] | undefined = undefined;
if (max > 0 && prefix != null) {
result.push(prefix)
}
for (let i = 0; i < max; i++) {
const character = value.charAt(i);
const character = stringValue.charAt(i);

@@ -349,3 +352,5 @@ if (character === '%' && !replaceReserved) {

private static getSubstitutionType(value: any, col: number): SubstitutionType {
if (typeof value === 'string' || value === undefined || value === null) {
if (value === undefined || value === null) {
return SubstitutionType.EMPTY;
} else if (StdUriTemplate.isNativeType(value)) {
return SubstitutionType.STRING;

@@ -378,2 +383,21 @@ } else if (StdUriTemplate.isList(value)) {

private static isNativeType(value: any): boolean {
return (typeof value === 'string' ||
typeof value === 'number' ||
typeof value === 'boolean' ||
value instanceof Date);
}
private static convertNativeTypes(value: any): string {
if (typeof value === 'string') {
return value;
} else if (typeof value === 'number' || typeof value === 'boolean') {
return value.toString();
} else if (value instanceof Date) {
return value.toISOString().split('.')[0] + "Z";
} else {
throw new Error(`Illegal class passed as substitution, found ${typeof value}`);
}
}
private static expandToken(

@@ -393,11 +417,5 @@ operator: Operator | null,

let value = substitutions[token];
if (typeof value === 'number' || typeof value === 'boolean') {
value = value.toString();
} else if (value instanceof Date) {
value = value.toISOString().split('.')[0] + "Z";
}
const value = substitutions[token];
const substType = StdUriTemplate.getSubstitutionType(value, col);
if (StdUriTemplate.isEmpty(substType, value)) {
if (substType === SubstitutionType.EMPTY || StdUriTemplate.isEmpty(substType, value)) {
return false;

@@ -427,3 +445,3 @@ }

private static addStringValue(operator: Operator | null, token: string, value: string, result: string[], maxChar: number): void {
private static addStringValue(operator: Operator | null, token: string, value: any, result: string[], maxChar: number): void {
StdUriTemplate.addValue(operator, token, value, result, maxChar);

@@ -435,3 +453,3 @@ }

token: string,
value: string[],
value: any[],
result: string[],

@@ -461,3 +479,3 @@ maxChar: number,

token: string,
value: { [key: string]: string },
value: { [key: string]: any },
result: string[],

@@ -464,0 +482,0 @@ maxChar: number,

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