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

yo-fs

Package Overview
Dependencies
Maintainers
3
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yo-fs - npm Package Compare versions

Comparing version 1.0.5 to 2.0.0

60

index.js
var relative = require('relative-date')
var pretty = require('pretty-bytes')
var pretty = require('prettier-bytes')
var path = require('path')
var data = require('render-data')
var yo = require('yo-yo')
module.exports = render
module.exports = Tree
function render (widget, root, entries, onclick) {
var fresh = Tree(widget, root, entries, onclick)
if (widget) yo.update(widget, fresh)
return fresh
function Tree (root, entries, onclick) {
if (!(this instanceof Tree)) return new Tree(root, entries, onclick)
this.widget = this.render(root, entries, onclick)
}
function Tree (widget, root, entries, onclick) {
Tree.prototype.update = function (fresh) {
var self = this
console.log('widget', self.widget)
console.log('fresh', fresh)
yo.update(self.widget, fresh)
}
Tree.prototype.render = function (root, entries, onclick) {
console.log(root, entries)
var self = this
var visible = []

@@ -27,13 +37,19 @@ var roots = split(root)

})
var el = yo`<div id="yo-fs">
var displayId = 'display'
var display = yo`<div id="${displayId}"></div>`
var fs = yo`<div id="fs">
<ul id="file-widget">
${backRow()}
${visible.map(function (entry) {
return row(entry)
return row(entry)
})}
</ul>
</ul>
</div>`
var widget = yo`<div id="yo-fs">
${fs}
</div>`
return widget
function backButton (ev) {

@@ -45,4 +61,5 @@ var entry = {

onclick(ev, entry)
render(widget, entry.name, entries, onclick)
self.update(self.render(entry.name, entries, onclick))
}
function backRow () {

@@ -56,3 +73,2 @@ if (root === '/') return

}
return el

@@ -62,3 +78,16 @@ function row (entry) {

onclick(e, entry)
if (entry.type === 'directory') render(widget, entry.name, entries, onclick)
root = entry.name
console.log('click', entry)
if (entry.type === 'directory') {
//document.querySelector(displayId).innerHTML = ''
self.update(self.render(entry.name, entries, onclick))
}
if (entry.type === 'file') {
data.render({
name: entry.name,
createReadStream: entry.createReadStream
}, display, function (err) {
if (err) throw err
})
}
}

@@ -75,3 +104,2 @@ return yo`<li class='entry ${entry.type}' onclick=${click}>

function split (pathName) {

@@ -78,0 +106,0 @@ var fileArray = pathName.split('/')

{
"name": "yo-fs",
"version": "1.0.5",
"version": "2.0.0",
"description": "A client-side modular stream-friendly ui browser widget for navigating directories.",

@@ -31,3 +31,3 @@ "main": "index.js",

"dependencies": {
"pretty-bytes": "^3.0.1",
"prettier-bytes": "^1.0.3",
"relative-date": "^1.1.3",

@@ -34,0 +34,0 @@ "yo-yo": "^1.2.1"

@@ -9,5 +9,4 @@ # yo-fs

#### `yofs(widget, path, entries, onclick)`
#### `yofs(path, entries, onclick)`
* `widget`: if we already have a widget, update it, otherwise make a new one.
* `path`: the directory or filename to display

@@ -21,10 +20,20 @@ * `entries`: a list of entries with `name`, `size`, `modified`, `createReadStream`

var yofs = require('yo-fs')
var yo = require('yo-yo')
var onclick = function (event, entry) {
var entries = []
function onclick (event, entry) {
console.log('i clicked', entry)
}
var el = yofs(null, '/', entries, onclick)
// only create the top-level element once
var el = yofs('/', entries, onclick)
document.body.appendChild(el)
// update the tree's internal html widget using yo
function update () {
var fresh = tree.render('/', entries, onclick)
yo.update(tree.widget, fresh)
}
var stream = //stream that gives me some data...

@@ -34,4 +43,4 @@

entries.push(entry)
yofs(widget, '/', entries, onclick) // dynamically updates the widget
update()
}
```
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