mirror of
https://github.com/arthur-pbty/portfolio2023.git
synced 2026-06-15 15:56:58 +02:00
modified
This commit is contained in:
-21
@@ -1,21 +0,0 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016-2019 David Mark Clements
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
var bench = require('fastbench')
|
||||
var utilFormat = require('util').format
|
||||
var quickFormat = require('./')
|
||||
|
||||
var run = bench([
|
||||
function util(cb) {
|
||||
utilFormat('%s %j %d', 'a', {a: {x: 1}}, 1)
|
||||
setImmediate(cb)
|
||||
},
|
||||
function quick(cb) {
|
||||
quickFormat('%s %j %d', 'a', [{a: {x: 1}}, 1], null)
|
||||
setImmediate(cb)
|
||||
},
|
||||
function utilWithTailObj(cb) {
|
||||
utilFormat('hello %s %j %d', 'world', {obj: true}, 4, {another: 'obj'})
|
||||
setImmediate(cb)
|
||||
},
|
||||
function quickWithTailObj(cb) {
|
||||
quickFormat('hello %s %j %d', 'world', [{obj: true}, 4, {another: 'obj'}], null)
|
||||
setImmediate(cb)
|
||||
}
|
||||
], 100000)
|
||||
|
||||
run(run)
|
||||
-109
@@ -1,109 +0,0 @@
|
||||
'use strict'
|
||||
function tryStringify (o) {
|
||||
try { return JSON.stringify(o) } catch(e) { return '"[Circular]"' }
|
||||
}
|
||||
|
||||
module.exports = format
|
||||
|
||||
function format(f, args, opts) {
|
||||
var ss = (opts && opts.stringify) || tryStringify
|
||||
var offset = 1
|
||||
if (typeof f === 'object' && f !== null) {
|
||||
var len = args.length + offset
|
||||
if (len === 1) return f
|
||||
var objects = new Array(len)
|
||||
objects[0] = ss(f)
|
||||
for (var index = 1; index < len; index++) {
|
||||
objects[index] = ss(args[index])
|
||||
}
|
||||
return objects.join(' ')
|
||||
}
|
||||
if (typeof f !== 'string') {
|
||||
return f
|
||||
}
|
||||
var argLen = args.length
|
||||
if (argLen === 0) return f
|
||||
var str = ''
|
||||
var a = 1 - offset
|
||||
var lastPos = -1
|
||||
var flen = (f && f.length) || 0
|
||||
for (var i = 0; i < flen;) {
|
||||
if (f.charCodeAt(i) === 37 && i + 1 < flen) {
|
||||
lastPos = lastPos > -1 ? lastPos : 0
|
||||
switch (f.charCodeAt(i + 1)) {
|
||||
case 100: // 'd'
|
||||
case 102: // 'f'
|
||||
if (a >= argLen)
|
||||
break
|
||||
if (args[a] == null) break
|
||||
if (lastPos < i)
|
||||
str += f.slice(lastPos, i)
|
||||
str += Number(args[a])
|
||||
lastPos = i + 2
|
||||
i++
|
||||
break
|
||||
case 105: // 'i'
|
||||
if (a >= argLen)
|
||||
break
|
||||
if (args[a] == null) break
|
||||
if (lastPos < i)
|
||||
str += f.slice(lastPos, i)
|
||||
str += Math.floor(Number(args[a]))
|
||||
lastPos = i + 2
|
||||
i++
|
||||
break
|
||||
case 79: // 'O'
|
||||
case 111: // 'o'
|
||||
case 106: // 'j'
|
||||
if (a >= argLen)
|
||||
break
|
||||
if (args[a] === undefined) break
|
||||
if (lastPos < i)
|
||||
str += f.slice(lastPos, i)
|
||||
var type = typeof args[a]
|
||||
if (type === 'string') {
|
||||
str += '\'' + args[a] + '\''
|
||||
lastPos = i + 2
|
||||
i++
|
||||
break
|
||||
}
|
||||
if (type === 'function') {
|
||||
str += args[a].name || '<anonymous>'
|
||||
lastPos = i + 2
|
||||
i++
|
||||
break
|
||||
}
|
||||
str += ss(args[a])
|
||||
lastPos = i + 2
|
||||
i++
|
||||
break
|
||||
case 115: // 's'
|
||||
if (a >= argLen)
|
||||
break
|
||||
if (lastPos < i)
|
||||
str += f.slice(lastPos, i)
|
||||
str += String(args[a])
|
||||
lastPos = i + 2
|
||||
i++
|
||||
break
|
||||
case 37: // '%'
|
||||
if (lastPos < i)
|
||||
str += f.slice(lastPos, i)
|
||||
str += '%'
|
||||
lastPos = i + 2
|
||||
i++
|
||||
a--
|
||||
break
|
||||
}
|
||||
++a
|
||||
}
|
||||
++i
|
||||
}
|
||||
if (lastPos === -1)
|
||||
return f
|
||||
else if (lastPos < flen) {
|
||||
str += f.slice(lastPos)
|
||||
}
|
||||
|
||||
return str
|
||||
}
|
||||
-29
@@ -1,29 +0,0 @@
|
||||
{
|
||||
"name": "quick-format-unescaped",
|
||||
"version": "4.0.4",
|
||||
"description": "Solves a problem with util.format",
|
||||
"main": "index.js",
|
||||
"directories": {
|
||||
"test": "test"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "nyc -- node test",
|
||||
"test:html": "nyc --reporter=html -- node test"
|
||||
},
|
||||
"author": "David Mark Clements",
|
||||
"devDependencies": {
|
||||
"fastbench": "^1.0.1",
|
||||
"nyc": "^15.0.0"
|
||||
},
|
||||
"dependencies": {},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/davidmarkclements/quick-format.git"
|
||||
},
|
||||
"keywords": [],
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/davidmarkclements/quick-format/issues"
|
||||
},
|
||||
"homepage": "https://github.com/davidmarkclements/quick-format#readme"
|
||||
}
|
||||
-66
@@ -1,66 +0,0 @@
|
||||
# quick-format-unescaped
|
||||
|
||||
## unescaped ?
|
||||
|
||||
Sometimes you want to embed the results of quick-format into another string,
|
||||
and then escape the whole string.
|
||||
|
||||
## usage
|
||||
|
||||
```js
|
||||
var format = require('quick-format-unescaped')
|
||||
format('hello %s %j %d', ['world', [{obj: true}, 4, {another: 'obj'}]])
|
||||
```
|
||||
|
||||
## format(fmt, parameters, [options])
|
||||
|
||||
### fmt
|
||||
|
||||
A `printf`-like format string. Example: `'hello %s %j %d'`
|
||||
|
||||
### parameters
|
||||
|
||||
Array of values to be inserted into the `format` string. Example: `['world', {obj:true}]`
|
||||
|
||||
### options.stringify
|
||||
|
||||
Passing an options object as the third parameter with a `stringify` will mean
|
||||
any objects will be passed to the supplied function instead of an the
|
||||
internal `tryStringify` function. This can be useful when using augmented
|
||||
capability serializers such as [`fast-safe-stringify`](http://github.com/davidmarkclements/fast-safe-stringify) or [`fast-redact`](http://github.com/davidmarkclements/fast-redact).
|
||||
|
||||
## caveats
|
||||
|
||||
By default `quick-format-unescaped` uses `JSON.stringify` instead of `util.inspect`, this means functions *will not be serialized*.
|
||||
|
||||
## Benchmarks
|
||||
|
||||
### Node 8.11.2
|
||||
|
||||
```
|
||||
util*100000: 350.325ms
|
||||
quick*100000: 268.141ms
|
||||
utilWithTailObj*100000: 586.387ms
|
||||
quickWithTailObj*100000: 280.200ms
|
||||
util*100000: 325.735ms
|
||||
quick*100000: 270.251ms
|
||||
utilWithTailObj*100000: 492.270ms
|
||||
quickWithTailObj*100000: 261.797ms
|
||||
```
|
||||
|
||||
### Node 10.4.0
|
||||
|
||||
```
|
||||
util*100000: 301.035ms
|
||||
quick*100000: 217.005ms
|
||||
utilWithTailObj*100000: 404.778ms
|
||||
quickWithTailObj*100000: 236.176ms
|
||||
util*100000: 286.349ms
|
||||
quick*100000: 214.646ms
|
||||
utilWithTailObj*100000: 388.574ms
|
||||
quickWithTailObj*100000: 226.036ms
|
||||
```
|
||||
|
||||
## Acknowledgements
|
||||
|
||||
Sponsored by [nearForm](http://www.nearform.com)
|
||||
Reference in New Issue
Block a user