Removed GopherJS, basic frontend completed, need backend changes for

torrent storage
This commit is contained in:
2017-11-30 18:12:11 -05:00
parent 67fdef16b1
commit e98ad2cc88
69321 changed files with 5498914 additions and 337 deletions

View File

@@ -0,0 +1,13 @@
*.bat
.htaccess
xeno/**
node_modules
scripts/dist
-p
npm-debug.log
!*.gitkeep
pg

View File

@@ -0,0 +1,86 @@
exec = require('child_process').exec
fs = require 'fs'
sysPath = require 'path'
task 'compile:coffee', ->
unless fs.existsSync './scripts/js'
fs.mkdirSync './scripts/js'
exec 'node ./node_modules/coffee-script/bin/coffee -bco ./scripts/js ./scripts/coffee',
(error) ->
if fs.existsSync '-p'
fs.rmdirSync '-p'
if error?
console.log 'Compile failed: ' + error
return
task 'build', ->
invoke 'compile:coffee'
# This is in place until we replace the test suite runner with popo
task 'test', ->
runTestsIn 'scripts/coffee/test', '_prepare.coffee'
runInCoffee = (path, cb) ->
exec 'node ./node_modules/coffee-script/bin/coffee ' + path, cb
runTestsIn = (shortPath, except) ->
fullPath = sysPath.resolve shortPath
fs.readdir fullPath, (err, files) ->
if err then throw Error err
for file in files
return if file is except
fullFilePath = sysPath.resolve(fullPath, file)
shortFilePath = shortPath + '/' + file
if sysPath.extname(file) is '.coffee'
runAsTest shortFilePath, fullFilePath
else if fs.statSync(fullFilePath).isDirectory()
runTestsIn shortFilePath
return
didBeep = no
runAsTest = (shortPath, fullPath) ->
runInCoffee fullPath, (error, stdout, stderr) ->
output = 'Running ' + shortPath + '\n'
if stderr
unless didBeep
`console.log("\007")`
didBeep = yes
output += 'Error\n' + stdout + stderr + '\n'
else if stdout
output += '\n' + stdout
console.log output

View File

@@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2013 Aria Minaei
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.

View File

@@ -0,0 +1,3 @@
Converts bare objects to DOM objects, compatible with htmlparser2's DOM objects.
This is useful when you want to work with DOM without having to compose/parse html.

View File

@@ -0,0 +1,10 @@
*.bat
.htaccess
xeno/**
node_modules
-p
npm-debug.log
!*.gitkeep

View File

@@ -0,0 +1,86 @@
exec = require('child_process').exec
fs = require 'fs'
sysPath = require 'path'
task 'compile:coffee', ->
unless fs.existsSync './scripts/js'
fs.mkdirSync './scripts/js'
exec 'node ./node_modules/coffee-script/bin/coffee -bco ./scripts/js ./scripts/coffee',
(error) ->
if fs.existsSync '-p'
fs.rmdirSync '-p'
if error?
console.log 'Compile failed: ' + error
return
task 'build', ->
invoke 'compile:coffee'
# This is in place until we replace the test suite runner with popo
task 'test', ->
runTestsIn 'scripts/coffee/test', '_prepare.coffee'
runInCoffee = (path, cb) ->
exec 'node ./node_modules/coffee-script/bin/coffee ' + path, cb
runTestsIn = (shortPath, except) ->
fullPath = sysPath.resolve shortPath
fs.readdir fullPath, (err, files) ->
if err then throw Error err
for file in files
return if file is except
fullFilePath = sysPath.resolve(fullPath, file)
shortFilePath = shortPath + '/' + file
if sysPath.extname(file) is '.coffee'
runAsTest shortFilePath, fullFilePath
else if fs.statSync(fullFilePath).isDirectory()
runTestsIn shortFilePath
return
didBeep = no
runAsTest = (shortPath, fullPath) ->
runInCoffee fullPath, (error, stdout, stderr) ->
output = 'Running ' + shortPath + '\n'
if stderr
unless didBeep
`console.log("\007")`
didBeep = yes
output += 'Error\n' + stdout + stderr + '\n'
else if stdout
output += '\n' + stdout
console.log output

View File

@@ -0,0 +1,7 @@
notareplacementforunderscore
# Installation
**npm**: `npm install utila`
**bower**: available via bower as in `bower install utila`, but you should run `npm install` before you can use it.

View File

@@ -0,0 +1,58 @@
{
"_args": [
[
"utila@0.3.3",
"C:\\Users\\deranjer\\GoglandProjects\\torrent-project\\torrent-project"
]
],
"_from": "utila@0.3.3",
"_id": "utila@0.3.3",
"_inBundle": false,
"_integrity": "sha1-1+jn1+MJEHCSsF+NloiCTWM6QiY=",
"_location": "/react-scripts/dom-converter/utila",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "utila@0.3.3",
"name": "utila",
"escapedName": "utila",
"rawSpec": "0.3.3",
"saveSpec": null,
"fetchSpec": "0.3.3"
},
"_requiredBy": [
"/react-scripts/dom-converter"
],
"_resolved": "https://registry.npmjs.org/utila/-/utila-0.3.3.tgz",
"_spec": "0.3.3",
"_where": "C:\\Users\\deranjer\\GoglandProjects\\torrent-project\\torrent-project",
"author": {
"name": "Aria Minaei"
},
"bugs": {
"url": "https://github.com/AriaMinaei/utila/issues"
},
"dependencies": {},
"description": "notareplacementforunderscore",
"devDependencies": {
"coffee-script": "~1.6.3",
"little-popo": "~0.1"
},
"homepage": "https://github.com/AriaMinaei/utila#readme",
"keywords": [
"utilities"
],
"license": "MIT",
"main": "scripts/js/lib/utila.js",
"name": "utila",
"repository": {
"type": "git",
"url": "git+https://github.com/AriaMinaei/utila.git"
},
"scripts": {
"prepublish": "node ./node_modules/coffee-script/bin/cake build",
"test": "node ./node_modules/coffee-script/bin/cake test"
},
"version": "0.3.3"
}

View File

@@ -0,0 +1,145 @@
array = require './array'
module.exports = class Emitter
constructor: ->
@_listeners = {}
@_listenersForAnyEvent = []
@_disabledEmitters = {}
on: (eventName, listener) ->
unless @_listeners[eventName]?
@_listeners[eventName] = []
@_listeners[eventName].push listener
@
once: (eventName, listener) ->
ran = no
cb = =>
return if ran
ran = yes
do listener
setTimeout =>
@removeEvent eventName, cb
, 0
@on eventName, cb
@
onAnyEvent: (listener) ->
@_listenersForAnyEvent.push listener
@
removeEvent: (eventName, listener) ->
return @ unless @_listeners[eventName]?
array.pluckOneItem @_listeners[eventName], listener
@
removeListeners: (eventName) ->
return @ unless @_listeners[eventName]?
@_listeners[eventName].length = 0
@
removeAllListeners: ->
for name, listeners of @_listeners
listeners.length = 0
@
_emit: (eventName, data) ->
for listener in @_listenersForAnyEvent
listener.call @, data, eventName
return unless @_listeners[eventName]?
for listener in @_listeners[eventName]
listener.call @, data
return
# this makes sure that all the calls to this class's method 'fnName'
# are throttled
_throttleEmitterMethod: (fnName, time = 1000) ->
originalFn = @[fnName]
if typeof originalFn isnt 'function'
throw Error "this class does not have a method called '#{fnName}'"
lastCallArgs = null
pending = no
timer = null
@[fnName] = =>
lastCallArgs = arguments
do pend
pend = =>
if pending
clearTimeout timer
timer = setTimeout runIt, time
pending = yes
runIt = =>
pending = no
originalFn.apply @, lastCallArgs
_disableEmitter: (fnName) ->
if @_disabledEmitters[fnName]?
throw Error "#{fnName} is already a disabled emitter"
@_disabledEmitters[fnName] = @[fnName]
@[fnName] = ->
_enableEmitter: (fnName) ->
fn = @_disabledEmitters[fnName]
unless fn?
throw Error "#{fnName} is not a disabled emitter"
@[fnName] = fn
delete @_disabledEmitters[fnName]

View File

@@ -0,0 +1,99 @@
module.exports = common =
###
Checks to see if o is an object, and it isn't an instance
of some class.
###
isBareObject: (o) ->
if o? and o.constructor is Object
return true
false
###
Returns type of an object, including:
undefined, null, string, number, array,
arguments, element, textnode, whitespace, and object
###
typeOf: (item) ->
return 'null' if item is null
return typeof item if typeof item isnt 'object'
return 'array' if Array.isArray item
# From MooTools
# - do we even need this?
if item.nodeName
if item.nodeType is 1 then return 'element'
if item.nodeType is 3 then return (/\S/).test(item.nodeValue) ? 'textnode' : 'whitespace'
else if typeof item.length is 'number'
if item.callee then return 'arguments'
return typeof item
# Deep clone of any variable.
# From MooTools
clone: (item, includePrototype = false) ->
switch common.typeOf item
when 'array' then return common._cloneArray item, includePrototype
when 'object' then return common._cloneObject item, includePrototype
else return item
###
Deep clone of an object.
From MooTools
###
_cloneObject: (o, includePrototype = false) ->
if common.isBareObject o
clone = {}
for key of o
clone[key] = common.clone o[key], includePrototype
return clone
else
return o unless includePrototype
return o if o instanceof Function
clone = Object.create o.constructor.prototype
for key of o
if o.hasOwnProperty key
clone[key] = common.clone o[key], includePrototype
clone
###
Deep clone of an array.
From MooTools
###
_cloneArray: (a, includePrototype = false) ->
i = a.length
clone = new Array i
while i--
clone[i] = common.clone a[i], includePrototype
clone

View File

@@ -0,0 +1,186 @@
module.exports = array =
###
Tries to turn anything into an array.
###
from: (r) ->
Array::slice.call r
###
Clone of an array. Properties will be shallow copies.
###
simpleClone: (a) ->
a.slice 0
shallowEqual: (a1, a2) ->
return no unless Array.isArray(a1) and Array.isArray(a2) and a1.length is a2.length
for val, i in a1
return no unless a2[i] is val
yes
pluck: (a, i) ->
return a if a.length < 1
for value, index in a
if index > i
a[index - 1] = a[index]
a.length = a.length - 1
a
pluckItem: (a, item) ->
return a if a.length < 1
removed = 0
for value, index in a
if value is item
removed++
continue
if removed isnt 0
a[index - removed] = a[index]
a.length = a.length - removed if removed > 0
a
pluckOneItem: (a, item) ->
return a if a.length < 1
reached = no
for value, index in a
if not reached
if value is item
reached = yes
continue
else
a[index - 1] = a[index]
a.length = a.length - 1 if reached
a
pluckByCallback: (a, cb) ->
return a if a.length < 1
removed = 0
for value, index in a
if cb value, index
removed++
continue
if removed isnt 0
a[index - removed] = a[index]
if removed > 0
a.length = a.length - removed
a
pluckMultiple: (array, indexesToRemove) ->
return array if array.length < 1
removedSoFar = 0
indexesToRemove.sort()
for i in indexesToRemove
@pluck array, i - removedSoFar
removedSoFar++
array
injectByCallback: (a, toInject, shouldInject) ->
valA = null
valB = null
len = a.length
if len < 1
a.push toInject
return a
for val, i in a
valA = valB
valB = val
if shouldInject valA, valB, toInject
return a.splice i, 0, toInject
a.push toInject
a
injectInIndex: (a, index, toInject) ->
len = a.length
i = index
if len < 1
a.push toInject
return a
toPut = toInject
toPutNext = null
`for(; i <= len; i++){
toPutNext = a[i];
a[i] = toPut;
toPut = toPutNext;
}`
# a[i] = toPut
null

View File

@@ -0,0 +1,87 @@
module.exports = classic = {}
# Little helper for mixins from CoffeeScript FAQ,
# courtesy of Sethaurus (http://github.com/sethaurus)
classic.implement = (mixins..., classReference) ->
for mixin in mixins
classProto = classReference::
for member of mixin::
unless Object.getOwnPropertyDescriptor classProto, member
desc = Object.getOwnPropertyDescriptor mixin::, member
Object.defineProperty classProto, member, desc
classReference
classic.mix = (mixins..., classReference) ->
classProto = classReference::
classReference.__mixinCloners = []
classReference.__applyClonersFor = (instance, args = null) ->
for cloner in classReference.__mixinCloners
cloner.apply instance, args
return
classReference.__mixinInitializers = []
classReference.__initMixinsFor = (instance, args = null) ->
for initializer in classReference.__mixinInitializers
initializer.apply instance, args
return
classReference.__mixinQuitters = []
classReference.__applyQuittersFor = (instance, args = null) ->
for quitter in classReference.__mixinQuitters
quitter.apply instance, args
return
for mixin in mixins
unless mixin.constructor instanceof Function
throw Error "Mixin should be a function"
for member of mixin::
if member.substr(0, 11) is '__initMixin'
classReference.__mixinInitializers.push mixin::[member]
continue
else if member.substr(0, 11) is '__clonerFor'
classReference.__mixinCloners.push mixin::[member]
continue
else if member.substr(0, 12) is '__quitterFor'
classReference.__mixinQuitters.push mixin::[member]
continue
unless Object.getOwnPropertyDescriptor classProto, member
desc = Object.getOwnPropertyDescriptor mixin::, member
Object.defineProperty classProto, member, desc
classReference

View File

@@ -0,0 +1,170 @@
_common = require './_common'
module.exports = object =
isBareObject: _common.isBareObject.bind _common
###
if object is an instance of a class
###
isInstance: (what) ->
not @isBareObject what
###
Alias to _common.typeOf
###
typeOf: _common.typeOf.bind _common
###
Alias to _common.clone
###
clone: _common.clone.bind _common
###
Empties an object of its properties.
###
empty: (o) ->
for prop of o
delete o[prop] if o.hasOwnProperty prop
o
###
Empties an object. Doesn't check for hasOwnProperty, so it's a tiny
bit faster. Use it for plain objects.
###
fastEmpty: (o) ->
delete o[property] for property of o
o
###
Overrides values fomr `newValues` on `base`, as long as they
already exist in base.
###
overrideOnto: (base, newValues) ->
return base if not @isBareObject(newValues) or not @isBareObject(base)
for key, oldVal of base
newVal = newValues[key]
continue if newVal is undefined
if typeof newVal isnt 'object' or @isInstance newVal
base[key] = @clone newVal
# newVal is a plain object
else
if typeof oldVal isnt 'object' or @isInstance oldVal
base[key] = @clone newVal
else
@overrideOnto oldVal, newVal
base
###
Takes a clone of 'base' and runs #overrideOnto on it
###
override: (base, newValues) ->
@overrideOnto @clone(base), newValues
append: (base, toAppend) ->
@appendOnto @clone(base), toAppend
# Deep appends values from `toAppend` to `base`
appendOnto: (base, toAppend) ->
return base if not @isBareObject(toAppend) or not @isBareObject(base)
for own key, newVal of toAppend
continue unless newVal isnt undefined
if typeof newVal isnt 'object' or @isInstance newVal
base[key] = newVal
else
# newVal is a bare object
oldVal = base[key]
if typeof oldVal isnt 'object' or @isInstance oldVal
base[key] = @clone newVal
else
@appendOnto oldVal, newVal
base
# Groups
groupProps: (obj, groups) ->
grouped = {}
for name, defs of groups
grouped[name] = {}
grouped['rest'] = {}
`top: //`
for key, val of obj
shouldAdd = no
for name, defs of groups
unless Array.isArray defs
defs = [defs]
for def in defs
if typeof def is 'string'
if key is def
shouldAdd = yes
else if def instanceof RegExp
if def.test key
shouldAdd = yes
else if def instanceof Function
if def key
shouldAdd = yes
else
throw Error 'Group definitions must either
be strings, regexes, or functions.'
if shouldAdd
grouped[name][key] = val
`continue top`
grouped['rest'][key] = val
grouped

View File

@@ -0,0 +1,16 @@
module.exports =
# pads a number with leading zeroes
#
# http://stackoverflow.com/a/10073788/607997
pad: (n, width, z = '0') ->
n = n + ''
if n.length >= width
n
else
new Array(width - n.length + 1).join(z) + n

View File

@@ -0,0 +1,7 @@
module.exports = utila =
array: require './array'
classic: require './classic'
object: require './object'
string: require './string'
Emitter: require './Emitter'

View File

@@ -0,0 +1,5 @@
path = require 'path'
pathToLib = path.resolve __dirname, '../lib'
require('little-popo')(pathToLib)

View File

@@ -0,0 +1,143 @@
require './_prepare'
array = mod 'array'
test 'from', ->
array.from([1]).should.be.an.instanceOf Array
array.from([1])[0].should.equal 1
# test 'clone', ->
# a = [0, 1, 2]
# b = array.clone a
# b[0].should.equal 0
# b[1].should.equal 1
# b[0] = 3
# a[0].should.equal 0
test 'pluck', ->
a = [0, 1, 2, 3]
after = array.pluck a, 1
after.length.should.equal 3
after[0].should.equal 0
after[1].should.equal 2
after[2].should.equal 3
after.should.equal a
test 'pluckMultiple', ->
a = [0, 1, 2, 3, 4, 5, 6]
array.pluckMultiple a, [0, 4, 2, 6]
a.length.should.equal 3
a[0].should.equal 1
a[1].should.equal 3
a[2].should.equal 5
test 'pluckItem', ->
a = [0, 1, 2, 3, 2, 4, 2]
array.pluckItem a, 2
a[0].should.equal 0
a[1].should.equal 1
a[2].should.equal 3
a[3].should.equal 4
array.pluckItem([1], 2).length.should.equal 1
test 'pluckOneItem', ->
a = [0, 1, 2, 3, 2, 4, 2]
array.pluckOneItem a, 2
a[0].should.equal 0
a[1].should.equal 1
a[2].should.equal 3
a[3].should.equal 2
a[4].should.equal 4
a[5].should.equal 2
a = [1, 2]
array.pluckOneItem a, 1
a.length.should.equal 1
a[0].should.equal 2
array.pluckOneItem([], 1).length.should.equal 0
array.pluckOneItem([1], 2).length.should.equal 1
test 'plcukByCallback', ->
a = [0, 1, 2, 3]
array.pluckByCallback a, (val, i) ->
return yes if val is 2
return no
a[0].should.equal 0
a[1].should.equal 1
a[2].should.equal 3
test 'injectByCallback', ->
shouldInject = (valA, valB, toInject) ->
unless valA?
return yes if toInject <= valB
return no
unless valB?
return yes if valA <= toInject
return no
return yes if valA <= toInject <= valB
return no
a = [0.5, 1, 2.5, 2.5, 2.75, 2.75, 3]
array.injectByCallback a, 0, shouldInject
a[0].should.equal 0
a[1].should.equal 0.5
a[7].should.equal 3
a = [0.5, 1, 2.5, 2.5, 2.75, 2.75, 3]
array.injectByCallback a, 2.7, shouldInject
a[0].should.equal 0.5
a[4].should.equal 2.7
a[5].should.equal 2.75
a[7].should.equal 3
a = [0.5, 1, 2.5, 2.5, 2.75, 2.75, 3]
array.injectByCallback a, 3.2, shouldInject
a[0].should.equal 0.5
a[4].should.equal 2.75
a[6].should.equal 3
a[7].should.equal 3.2

View File

@@ -0,0 +1,233 @@
require './_prepare'
object = mod 'object'
test 'isBareObject', ->
object.isBareObject('a').should.equal false
object.isBareObject({'a': 'a'}).should.equal true
test 'typeOf', ->
object.typeOf('s').should.equal 'string'
object.typeOf(0).should.equal 'number'
object.typeOf(false).should.equal 'boolean'
object.typeOf({}).should.equal 'object'
object.typeOf(arguments).should.equal 'arguments'
object.typeOf([]).should.equal 'array'
test 'empty', ->
o =
a: 1
b: 2
object.empty o
o.should.not.have.property 'a'
o.should.not.have.property 'b'
test 'fastEmpty', ->
o =
a: 1
b: 2
object.fastEmpty o
o.should.not.have.property 'a'
o.should.not.have.property 'b'
test 'clone', ->
object.clone([1])[0].should.equal 1
object.clone({a:1}).a.should.equal 1
o = {a: 1}
object.clone(o).should.not.equal o
test 'clone [include prototype]', ->
class C
constructor: (@a) ->
sayA: -> @a + 'a'
a = new C 'a'
a.sayA().should.equal 'aa'
b = object.clone a, yes
b.should.not.equal a
b.constructor.should.equal C
b.a.should.equal 'a'
b.a = 'a2'
b.sayA().should.equal 'a2a'
test 'clone [without prototype]', ->
class C
constructor: (@a) ->
sayA: -> @a + 'a'
a = new C 'a'
a.sayA().should.equal 'aa'
b = object.clone a, no
b.should.equal a
test 'overrideOnto [basic]', ->
onto =
a: 'a'
b:
c: 'c'
d:
e: 'e'
what =
a: 'a2'
b:
c: 'c2'
d:
f: 'f2'
object.overrideOnto onto, what
onto.a.should.equal 'a2'
onto.b.should.have.property 'c'
onto.b.c.should.equal 'c2'
onto.b.d.should.not.have.property 'f'
onto.b.d.e.should.equal 'e'
test 'override', ->
onto =
a: 'a'
b:
c: 'c'
d:
e: 'e'
what =
a: 'a2'
b:
c: 'c2'
d:
f: 'f2'
onto2 = object.override onto, what
onto2.a.should.equal 'a2'
onto2.b.should.have.property 'c'
onto2.b.c.should.equal 'c2'
onto2.b.d.should.not.have.property 'f'
onto2.b.d.e.should.equal 'e'
onto.should.not.equal onto2
do ->
what =
a: 'a2'
c: ->
z: 'z'
y:
a: 'a'
onto =
a: 'a'
b: 'b'
test 'appendOnto [basic]', ->
object.appendOnto onto, what
onto.a.should.equal 'a2'
onto.b.should.equal 'b'
onto.z.should.equal 'z'
test "appendOnto [shallow copies instances]", ->
onto.c.should.be.instanceof Function
onto.c.should.equal what.c
test "appendOnto [clones objects]", ->
onto.should.have.property 'y'
onto.y.a.should.equal 'a'
onto.y.should.not.equal what.y
test 'groupProps', ->
obj =
a1: '1'
a2: '2'
b1: '1'
b2: '2'
c1: '1'
c2: '2'
rest1: '1'
rest2: '2'
groups = object.groupProps obj,
a: ['a1', 'a2']
b: [/^b[0-9]+$/]
c: (key) -> key[0] is 'c'
groups.a.should.have.property 'a1'
groups.a.a1.should.equal '1'
groups.a.should.have.property 'a2'
groups.b.should.have.property 'b1'
groups.b.should.have.property 'b2'
groups.c.should.have.property 'c1'
groups.c.should.have.property 'c2'
groups.rest.should.have.property 'rest1'
groups.rest.should.have.property 'rest1'
groups.rest.should.not.have.property 'c1'

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,57 @@
{
"_args": [
[
"dom-converter@0.1.4",
"C:\\Users\\deranjer\\GoglandProjects\\torrent-project\\torrent-project"
]
],
"_from": "dom-converter@0.1.4",
"_id": "dom-converter@0.1.4",
"_inBundle": false,
"_integrity": "sha1-pF71cnuJDJv/5tfIduexnLDhfzs=",
"_location": "/react-scripts/dom-converter",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "dom-converter@0.1.4",
"name": "dom-converter",
"escapedName": "dom-converter",
"rawSpec": "0.1.4",
"saveSpec": null,
"fetchSpec": "0.1.4"
},
"_requiredBy": [
"/react-scripts/renderkid"
],
"_resolved": "https://registry.npmjs.org/dom-converter/-/dom-converter-0.1.4.tgz",
"_spec": "0.1.4",
"_where": "C:\\Users\\deranjer\\GoglandProjects\\torrent-project\\torrent-project",
"author": {
"name": "Aria Minaei"
},
"bugs": {
"url": "https://github.com/AriaMinaei/dom-converter/issues"
},
"dependencies": {
"utila": "~0.3"
},
"description": "converts bare objects to DOM objects or xml representations",
"devDependencies": {
"coffee-script": "~1.6.3",
"little-popo": "~0.1"
},
"homepage": "https://github.com/AriaMinaei/dom-converter#readme",
"license": "MIT",
"main": "scripts/js/lib/domConverter.js",
"name": "dom-converter",
"repository": {
"type": "git",
"url": "git+https://github.com/AriaMinaei/dom-converter.git"
},
"scripts": {
"prepublish": "node ./node_modules/coffee-script/bin/cake build",
"test": "node ./node_modules/coffee-script/bin/cake test"
},
"version": "0.1.4"
}

View File

@@ -0,0 +1,32 @@
objectToSaneObject = require './objectToSaneObject'
saneObjectToDom = require './saneObjectToDom'
domToMarkup = require './domToMarkup'
{object} = require 'utila'
module.exports = self =
objectToDom: (o) ->
o = self._object2SaneObject o
saneObjectToDom.convert o
object2markup: (o) ->
dom = self.toDom o
domToMarkup.convert dom
domToMarkup: (dom) ->
domToMarkup.convert dom
_object2SaneObject: (o) ->
unless Array.isArray o
unless object.isBareObject o
throw Error "toDom() only accepts arrays and bare objects as input"
objectToSaneObject.sanitize o

View File

@@ -0,0 +1,80 @@
{object} = require 'utila'
module.exports = self =
sanitize: (val) ->
self._toChildren val
_toChildren: (val) ->
if object.isBareObject val
return self._objectToChildren val
else if Array.isArray val
return self._arrayToChildren val
else if val is null or typeof val is 'undefined'
return []
else if typeof val in ['string', 'number']
return [String val]
else
throw Error "not a valid child node: `#{val}"
_objectToChildren: (o) ->
a = []
for own key, val of o
cur = {}
cur[key] = self.sanitize val
a.push cur
a
_arrayToChildren: (a) ->
ret = []
for v in a
ret.push self._toNode v
ret
_toNode: (o) ->
if typeof o in ['string', 'number']
return String o
else if object.isBareObject o
keys = Object.keys(o)
if keys.length isnt 1
throw Error "a node must only have one key as tag name"
key = keys[0]
obj = {}
obj[key] = self._toChildren o[key]
return obj
else
throw Error "not a valid node: `#{o}`"

View File

@@ -0,0 +1,148 @@
module.exports = self =
convert: (obj) ->
self._arrayToChildren obj
_arrayToChildren: (a, parent = null) ->
children = []
prev = null
for v in a
if typeof v is 'string'
node = self._getTextNodeFor v
else
node = self._objectToNode v, parent
node.prev = null
node.next = null
node.parent = parent
if prev?
node.prev = prev
prev.next = node
prev = node
children.push node
children
_objectToNode: (o) ->
i = 0
for own k, v of o
if i > 0
throw Error "_objectToNode() only accepts an object with one key/value"
key = k
val = v
i++
node = {}
if typeof key isnt 'string'
throw Error "_objectToNode()'s key must be a string of tag name and classes"
if typeof val is 'string'
children = [self._getTextNodeFor(val)]
else if Array.isArray val
children = self._arrayToChildren val, node
else
inspect o
throw Error "_objectToNode()'s key's value must only be a string or an array"
node.type = 'tag'
{name, attribs} = self._parseTag key
node.name = name
node.attribs = attribs
node.children = children
node
_getTextNodeFor: (s) ->
{type: 'text', data: s}
_nameRx: /^[a-zA-Z\-\_]{1}[a-zA-Z0-9\-\_]*$/
_parseTag: (k) ->
# validate
if not k.match(/^[a-zA-Z0-9\#\-\_\.\[\]\"\'\=\,\s]+$/) or k.match(/^[0-9]+/)
throw Error "cannot parse tag `#{k}`"
attribs = {}
parts =
name: ''
attribs: attribs
# tag name
if m = k.match /^([^\.#]+)/
name = m[1]
unless name.match self._nameRx
throw Error "tag name `#{name}` is not valid"
parts.name = name
k = k.substr name.length, k.length
# tag id
if m = k.match /^#([a-zA-Z0-9\-]+)/
id = m[1]
unless id.match self._nameRx
throw Error "tag id `#{id}` is not valid"
attribs.id = id
k = k.substr id.length + 1, k.length
classes = []
# the class attrib
while m = k.match /\.([a-zA-Z0-9\-\_]+)/
cls = m[1]
unless cls.match self._nameRx
throw Error "tag class `#{cls}` is not valid"
classes.push cls
k = k.replace '.' + cls, ''
if classes.length
attribs.class = classes.join " "
# TODO: match attributes like [a=b]
parts

View File

@@ -0,0 +1,5 @@
path = require 'path'
pathToLib = path.resolve __dirname, '../../js/lib'
require('little-popo')(pathToLib, no)

View File

@@ -0,0 +1,17 @@
require './_prepare'
domConverter = mod 'domConverter'
describe "input types"
it "should work with objects", ->
domConverter.objectToDom {}
it "should work with arrays", ->
domConverter.objectToDom []
it "should not work with other types", ->
(-> domConverter.objectToDom 'a').should.throw Error

View File

@@ -0,0 +1,73 @@
require './_prepare'
objectToSaneObject = mod 'objectToSaneObject'
describe "sanitize()"
test "case: 'text'", ->
input = 'text'
expectation = ['text']
ret = objectToSaneObject.sanitize input
ret.should.be.like expectation
test "case: ['text']", ->
input = ['text']
expectation = ['text']
ret = objectToSaneObject.sanitize input
ret.should.be.like expectation
test "case: {a:b}", ->
input = a: 'b'
expectation = [{a: ['b']}]
ret = objectToSaneObject.sanitize input
ret.should.be.like expectation
test "case: {a:[b: 'c']}", ->
input = a: [b: 'c']
expectation = [{a: [{b: ['c']}]}]
ret = objectToSaneObject.sanitize input
ret.should.be.like expectation
test "case: {a:b: 'c'}", ->
input = a: b: 'c'
expectation = [{
a: [{
b: ['c']
}]
}]
ret = objectToSaneObject.sanitize input
ret.should.be.like expectation
test "case: {a:b: ['c', d: 'e']}", ->
input = a: b: ['c', d: 'e']
expectation = [{
a: [{
b: ['c', {d: ['e']}]
}]
}]
ret = objectToSaneObject.sanitize input
ret.should.be.like expectation

View File

@@ -0,0 +1,79 @@
require './_prepare'
s2d = mod 'saneObjectToDom'
describe "_arrayToChildren()"
it "should work", ->
ret = s2d._arrayToChildren [
{
a: 'text'
}
{
'b.someClass': ['b1', 'b2']
}
{
c: [
{d: 'text'}
{e: []}
]
}
]
ret.should.be.an 'array'
ret.should.have.length.of 3
for node in ret
node.should.be.an 'object'
node.should.have
.keys ['type', 'name', 'attribs', 'children', 'next', 'prev', 'parent']
a = ret[0]
a.children.should.be.an 'array'
a.children.should.have.length.of 1
aChild = a.children[0]
aChild.should.be.an 'object'
aChild.should.be.like {type: 'text', data: 'text'}
expect(a.prev).to.equal null
expect(a.parent).to.equal null
b = ret[1]
a.next.should.equal b
b.prev.should.equal a
b.attribs.should.be.like
class: 'someClass'
bChildren = b.children
bChildren[0].should.be.like {type: 'text', data: 'b1'}
bChildren[1].should.be.like {type: 'text', data: 'b2'}
ret.should.have.deep.property '[2].children[1].name', 'e'
describe "_parseTag"
it "should work", ->
s2d.
_parseTag('tagName#id.c1.c2[a=b, d="1 2 3"]')
.should.be.like
name: 'tagName'
attribs:
id: 'id'
class: 'c1 c2'

View File

@@ -0,0 +1,33 @@
// Generated by CoffeeScript 1.6.3
var domToMarkup, object, objectToSaneObject, saneObjectToDom, self;
objectToSaneObject = require('./objectToSaneObject');
saneObjectToDom = require('./saneObjectToDom');
domToMarkup = require('./domToMarkup');
object = require('utila').object;
module.exports = self = {
objectToDom: function(o) {
o = self._object2SaneObject(o);
return saneObjectToDom.convert(o);
},
object2markup: function(o) {
var dom;
dom = self.toDom(o);
return domToMarkup.convert(dom);
},
domToMarkup: function(dom) {
return domToMarkup.convert(dom);
},
_object2SaneObject: function(o) {
if (!Array.isArray(o)) {
if (!object.isBareObject(o)) {
throw Error("toDom() only accepts arrays and bare objects as input");
}
}
return objectToSaneObject.sanitize(o);
}
};

View File

@@ -0,0 +1,2 @@
// Generated by CoffeeScript 1.6.3

View File

@@ -0,0 +1,123 @@
var dummer, object, sanitizer,
__hasProp = {}.hasOwnProperty;
object = require('utila').object;
sanitizer = require('./sanitizer');
module.exports = dummer = {
toDom: function(o) {
if (!Array.isArray(o)) {
if (!object.isBareObject(o)) {
throw Error("toDom() only accepts arrays and bare objects as input");
}
}
o = sanitizer.sanitize(o);
return dummer._children(o);
},
_children: function(a, parent) {
var children, node, prev, v, _i, _len;
if (parent == null) {
parent = null;
}
children = [];
prev = null;
for (_i = 0, _len = a.length; _i < _len; _i++) {
v = a[_i];
if (typeof v === 'string') {
node = dummer._textNode(v);
} else {
node = dummer._objectToDom(v, parent);
node.prev = null;
node.next = null;
node.parent = parent;
if (prev != null) {
node.prev = prev;
prev.next = node;
}
prev = node;
}
children.push(node);
}
return children;
},
_objectToDom: function(o) {
var attribs, children, i, k, key, name, node, v, val, _ref;
i = 0;
for (k in o) {
if (!__hasProp.call(o, k)) continue;
v = o[k];
if (i > 0) {
throw Error("_objectToDom() only accepts an object with one key/value");
}
key = k;
val = v;
i++;
}
node = {};
if (typeof key !== 'string') {
throw Error("_objectToDom()'s key must be a string of tag name and classes");
}
if (typeof val === 'string') {
children = [dummer._textNode(val)];
} else if (Array.isArray(val)) {
children = dummer._children(val, node);
} else {
inspect(o);
throw Error("_objectToDom()'s key's value must only be a string or an array");
}
node.type = 'tag';
_ref = dummer._parseTag(key), name = _ref.name, attribs = _ref.attribs;
node.name = name;
node.attribs = attribs;
node.children = children;
return node;
},
_textNode: function(s) {
return {
type: 'text',
data: s
};
},
_nameRx: /^[a-zA-Z\-\_]{1}[a-zA-Z0-9\-\_]*$/,
_parseTag: function(k) {
var attribs, classes, cls, id, m, name, parts;
if (!k.match(/^[a-zA-Z0-9\#\-\_\.\[\]\"\'\=\,\s]+$/) || k.match(/^[0-9]+/)) {
throw Error("cannot parse tag `" + k + "`");
}
attribs = {};
parts = {
name: '',
attribs: attribs
};
if (m = k.match(/^([^\.#]+)/)) {
name = m[1];
if (!name.match(dummer._nameRx)) {
throw Error("tag name `" + name + "` is not valid");
}
parts.name = name;
k = k.substr(name.length, k.length);
}
if (m = k.match(/^#([a-zA-Z0-9\-]+)/)) {
id = m[1];
if (!id.match(dummer._nameRx)) {
throw Error("tag id `" + id + "` is not valid");
}
attribs.id = id;
k = k.substr(id.length + 1, k.length);
}
classes = [];
while (m = k.match(/\.([a-zA-Z0-9\-\_]+)/)) {
cls = m[1];
if (!cls.match(dummer._nameRx)) {
throw Error("tag class `" + cls + "` is not valid");
}
classes.push(cls);
k = k.replace('.' + cls, '');
}
if (classes.length) {
attribs["class"] = classes.join(" ");
}
return parts;
}
};

View File

@@ -0,0 +1,63 @@
// Generated by CoffeeScript 1.6.3
var object, self,
__hasProp = {}.hasOwnProperty;
object = require('utila').object;
module.exports = self = {
sanitize: function(val) {
return self._toChildren(val);
},
_toChildren: function(val) {
var _ref;
if (object.isBareObject(val)) {
return self._objectToChildren(val);
} else if (Array.isArray(val)) {
return self._arrayToChildren(val);
} else if (val === null || typeof val === 'undefined') {
return [];
} else if ((_ref = typeof val) === 'string' || _ref === 'number') {
return [String(val)];
} else {
throw Error("not a valid child node: `" + val);
}
},
_objectToChildren: function(o) {
var a, cur, key, val;
a = [];
for (key in o) {
if (!__hasProp.call(o, key)) continue;
val = o[key];
cur = {};
cur[key] = self.sanitize(val);
a.push(cur);
}
return a;
},
_arrayToChildren: function(a) {
var ret, v, _i, _len;
ret = [];
for (_i = 0, _len = a.length; _i < _len; _i++) {
v = a[_i];
ret.push(self._toNode(v));
}
return ret;
},
_toNode: function(o) {
var key, keys, obj, _ref;
if ((_ref = typeof o) === 'string' || _ref === 'number') {
return String(o);
} else if (object.isBareObject(o)) {
keys = Object.keys(o);
if (keys.length !== 1) {
throw Error("a node must only have one key as tag name");
}
key = keys[0];
obj = {};
obj[key] = self._toChildren(o[key]);
return obj;
} else {
throw Error("not a valid node: `" + o + "`");
}
}
};

View File

@@ -0,0 +1,114 @@
// Generated by CoffeeScript 1.6.3
var self,
__hasProp = {}.hasOwnProperty;
module.exports = self = {
convert: function(obj) {
return self._arrayToChildren(obj);
},
_arrayToChildren: function(a, parent) {
var children, node, prev, v, _i, _len;
if (parent == null) {
parent = null;
}
children = [];
prev = null;
for (_i = 0, _len = a.length; _i < _len; _i++) {
v = a[_i];
if (typeof v === 'string') {
node = self._getTextNodeFor(v);
} else {
node = self._objectToNode(v, parent);
node.prev = null;
node.next = null;
node.parent = parent;
if (prev != null) {
node.prev = prev;
prev.next = node;
}
prev = node;
}
children.push(node);
}
return children;
},
_objectToNode: function(o) {
var attribs, children, i, k, key, name, node, v, val, _ref;
i = 0;
for (k in o) {
if (!__hasProp.call(o, k)) continue;
v = o[k];
if (i > 0) {
throw Error("_objectToNode() only accepts an object with one key/value");
}
key = k;
val = v;
i++;
}
node = {};
if (typeof key !== 'string') {
throw Error("_objectToNode()'s key must be a string of tag name and classes");
}
if (typeof val === 'string') {
children = [self._getTextNodeFor(val)];
} else if (Array.isArray(val)) {
children = self._arrayToChildren(val, node);
} else {
inspect(o);
throw Error("_objectToNode()'s key's value must only be a string or an array");
}
node.type = 'tag';
_ref = self._parseTag(key), name = _ref.name, attribs = _ref.attribs;
node.name = name;
node.attribs = attribs;
node.children = children;
return node;
},
_getTextNodeFor: function(s) {
return {
type: 'text',
data: s
};
},
_nameRx: /^[a-zA-Z\-\_]{1}[a-zA-Z0-9\-\_]*$/,
_parseTag: function(k) {
var attribs, classes, cls, id, m, name, parts;
if (!k.match(/^[a-zA-Z0-9\#\-\_\.\[\]\"\'\=\,\s]+$/) || k.match(/^[0-9]+/)) {
throw Error("cannot parse tag `" + k + "`");
}
attribs = {};
parts = {
name: '',
attribs: attribs
};
if (m = k.match(/^([^\.#]+)/)) {
name = m[1];
if (!name.match(self._nameRx)) {
throw Error("tag name `" + name + "` is not valid");
}
parts.name = name;
k = k.substr(name.length, k.length);
}
if (m = k.match(/^#([a-zA-Z0-9\-]+)/)) {
id = m[1];
if (!id.match(self._nameRx)) {
throw Error("tag id `" + id + "` is not valid");
}
attribs.id = id;
k = k.substr(id.length + 1, k.length);
}
classes = [];
while (m = k.match(/\.([a-zA-Z0-9\-\_]+)/)) {
cls = m[1];
if (!cls.match(self._nameRx)) {
throw Error("tag class `" + cls + "` is not valid");
}
classes.push(cls);
k = k.replace('.' + cls, '');
}
if (classes.length) {
attribs["class"] = classes.join(" ");
}
return parts;
}
};

View File

@@ -0,0 +1,62 @@
var object, sanitizer,
__hasProp = {}.hasOwnProperty;
object = require('utila').object;
module.exports = sanitizer = {
sanitize: function(val) {
return sanitizer._sanitizeAsChildren(val);
},
_sanitizeAsChildren: function(val) {
var _ref;
if (object.isBareObject(val)) {
return sanitizer._sanitizeObjectAsChildren(val);
} else if (Array.isArray(val)) {
return sanitizer._sanitizeArrayAsChildren(val);
} else if (val === null || typeof val === 'undefined') {
return [];
} else if ((_ref = typeof val) === 'string' || _ref === 'number') {
return [String(val)];
} else {
throw Error("not a valid child node: `" + val);
}
},
_sanitizeObjectAsChildren: function(o) {
var a, cur, key, val;
a = [];
for (key in o) {
if (!__hasProp.call(o, key)) continue;
val = o[key];
cur = {};
cur[key] = sanitizer.sanitize(val);
a.push(cur);
}
return a;
},
_sanitizeArrayAsChildren: function(a) {
var ret, v, _i, _len;
ret = [];
for (_i = 0, _len = a.length; _i < _len; _i++) {
v = a[_i];
ret.push(sanitizer._sanitizeAsNode(v));
}
return ret;
},
_sanitizeAsNode: function(o) {
var key, keys, obj, _ref;
if ((_ref = typeof o) === 'string' || _ref === 'number') {
return String(o);
} else if (object.isBareObject(o)) {
keys = Object.keys(o);
if (keys.length !== 1) {
throw Error("a node must only have one key as tag name");
}
key = keys[0];
obj = {};
obj[key] = sanitizer._sanitizeAsChildren(o[key]);
return obj;
} else {
throw Error("not a valid node: `" + o + "`");
}
}
};

View File

@@ -0,0 +1,8 @@
// Generated by CoffeeScript 1.6.3
var path, pathToLib;
path = require('path');
pathToLib = path.resolve(__dirname, '../../js/lib');
require('little-popo')(pathToLib, false);

View File

@@ -0,0 +1,22 @@
// Generated by CoffeeScript 1.6.3
var domConverter;
require('./_prepare');
domConverter = mod('domConverter');
describe("input types");
it("should work with objects", function() {
return domConverter.objectToDom({});
});
it("should work with arrays", function() {
return domConverter.objectToDom([]);
});
it("should not work with other types", function() {
return (function() {
return domConverter.objectToDom('a');
}).should["throw"](Error);
});

View File

@@ -0,0 +1,108 @@
// Generated by CoffeeScript 1.6.3
var objectToSaneObject;
require('./_prepare');
objectToSaneObject = mod('objectToSaneObject');
describe("sanitize()");
test("case: 'text'", function() {
var expectation, input, ret;
input = 'text';
expectation = ['text'];
ret = objectToSaneObject.sanitize(input);
return ret.should.be.like(expectation);
});
test("case: ['text']", function() {
var expectation, input, ret;
input = ['text'];
expectation = ['text'];
ret = objectToSaneObject.sanitize(input);
return ret.should.be.like(expectation);
});
test("case: {a:b}", function() {
var expectation, input, ret;
input = {
a: 'b'
};
expectation = [
{
a: ['b']
}
];
ret = objectToSaneObject.sanitize(input);
return ret.should.be.like(expectation);
});
test("case: {a:[b: 'c']}", function() {
var expectation, input, ret;
input = {
a: [
{
b: 'c'
}
]
};
expectation = [
{
a: [
{
b: ['c']
}
]
}
];
ret = objectToSaneObject.sanitize(input);
return ret.should.be.like(expectation);
});
test("case: {a:b: 'c'}", function() {
var expectation, input, ret;
input = {
a: {
b: 'c'
}
};
expectation = [
{
a: [
{
b: ['c']
}
]
}
];
ret = objectToSaneObject.sanitize(input);
return ret.should.be.like(expectation);
});
test("case: {a:b: ['c', d: 'e']}", function() {
var expectation, input, ret;
input = {
a: {
b: [
'c', {
d: 'e'
}
]
}
};
expectation = [
{
a: [
{
b: [
'c', {
d: ['e']
}
]
}
]
}
];
ret = objectToSaneObject.sanitize(input);
return ret.should.be.like(expectation);
});

View File

@@ -0,0 +1,73 @@
// Generated by CoffeeScript 1.6.3
var s2d;
require('./_prepare');
s2d = mod('saneObjectToDom');
describe("_arrayToChildren()");
it("should work", function() {
var a, aChild, b, bChildren, node, ret, _i, _len;
ret = s2d._arrayToChildren([
{
a: 'text'
}, {
'b.someClass': ['b1', 'b2']
}, {
c: [
{
d: 'text'
}, {
e: []
}
]
}
]);
ret.should.be.an('array');
ret.should.have.length.of(3);
for (_i = 0, _len = ret.length; _i < _len; _i++) {
node = ret[_i];
node.should.be.an('object');
node.should.have.keys(['type', 'name', 'attribs', 'children', 'next', 'prev', 'parent']);
}
a = ret[0];
a.children.should.be.an('array');
a.children.should.have.length.of(1);
aChild = a.children[0];
aChild.should.be.an('object');
aChild.should.be.like({
type: 'text',
data: 'text'
});
expect(a.prev).to.equal(null);
expect(a.parent).to.equal(null);
b = ret[1];
a.next.should.equal(b);
b.prev.should.equal(a);
b.attribs.should.be.like({
"class": 'someClass'
});
bChildren = b.children;
bChildren[0].should.be.like({
type: 'text',
data: 'b1'
});
bChildren[1].should.be.like({
type: 'text',
data: 'b2'
});
return ret.should.have.deep.property('[2].children[1].name', 'e');
});
describe("_parseTag");
it("should work", function() {
return s2d._parseTag('tagName#id.c1.c2[a=b, d="1 2 3"]').should.be.like({
name: 'tagName',
attribs: {
id: 'id',
"class": 'c1 c2'
}
});
});