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

dx-lib

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dx-lib - npm Package Compare versions

Comparing version 0.1.3 to 0.2.0

doc/loader.md

4

doc/json.md

@@ -6,6 +6,6 @@ # json

```
import { parseJSON } from 'dx-lib/lib/json'
import { parseJSON, stringifyJSON } from 'dx-lib/lib/json'
// 同JSON.parse,兼容低版本浏览器
parseJSON('{"a": "a", "b": "b"}')
stringifyJSON({a: "a", b: "b"})
```

@@ -1,54 +0,2 @@

/**
* https://code.jquery.com/jquery-1.11.3.js
*/
const rvalidtokens = /(,)|(\[|{)|(}|])|"(?:[^"\\\r\n]|\\["\\\/bfnrt]|\\u[\da-fA-F]{4})*"\s*:?|true|false|null|-?(?!0\d)\d+(?:\.\d+|)(?:[eE][+-]?\d+|)/g
const rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g
function trim(str) {
return str.replace(rtrim, "")
}
export const parseJSON = function(data) {
if (window.JSON && window.JSON.parse) {
return window.JSON.parse(data + "")
}
let requireNonComma
let depth = null
let str = trim(data + "")
// Guard against invalid (and possibly dangerous) input by ensuring that nothing remains
// after removing valid tokens
if (
str &&
!trim(
str.replace(rvalidtokens, function(token, comma, open, close) {
// Force termination if we see a misplaced comma
if (requireNonComma && comma) {
depth = 0
}
// Perform no more replacements after returning to outermost depth
if (depth === 0) {
return token
}
// Commas must not follow "[", "{", or ","
requireNonComma = open || comma
// Determine new depth
// array/object open ("[" or "{"): depth += true - false (increment)
// array/object close ("]" or "}"): depth += false - true (decrement)
// other cases ("," or primitive): depth += true - true (numeric cast)
depth += !close - !open
// Remove this token
return ""
})
)
) {
return Function("return " + str)()
} else {
throw new Error("Invalid JSON: " + data)
}
}
export * from './parse.js'
export * from './stringify.js'
{
"name": "dx-lib",
"version": "0.1.3",
"version": "0.2.0",
"description": "dx fe lib",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -15,2 +15,3 @@ # dx-lib

* [jsonp](doc/jsonp.md)
* [loader](doc/loader.md)
* [domready](doc/domready.md)

@@ -17,0 +18,0 @@ * [cookie](doc/cookie.md)

@@ -29,2 +29,11 @@ import puppeteer from 'puppeteer'

t.deepEqual(data, { a: "a", b: "b" })
let strs = await page.evaluate(() => {
return {
str1: stringifyJSON({ a: "a", b: "b" }),
str2: stringifyJSON({ a: "a", b: "b" }, null, 4),
str3: stringifyJSON({ a: "a", b: "b" }, null, '@')
}
})
t.is(strs.str1, '{"a":"a","b":"b"}')
})

Sorry, the diff of this file is not supported yet

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