78 lines
1.5 KiB
JavaScript
78 lines
1.5 KiB
JavaScript
const yaml = require('js-yaml')
|
|
const fs = require('fs')
|
|
const params = process.argv.splice(2)
|
|
const vocab = yaml.safeLoad( fs.readFileSync('legal.yaml', 'utf8') )
|
|
const po = fs.readFileSync( params[0], 'utf-8')
|
|
|
|
|
|
console.log(params)
|
|
//process.exit()
|
|
|
|
|
|
const capital = s=> /^[A-Z]/.test(s)
|
|
|
|
const replace = vocab=> text=>
|
|
Object.keys( vocab )
|
|
.reduce( (text, reg,s,mod)=>
|
|
text.replace( eval(reg)
|
|
// RegExp(
|
|
// ( s = reg.split('/').filter(s=>s),
|
|
// console.log(s),
|
|
// mod = s.pop(),
|
|
// s.join('/') )
|
|
// , mod )
|
|
, /=>/.test( vocab[reg] )
|
|
? eval( vocab[reg] )
|
|
: eval( "(_,$1,$2,$3,$4,$5,$6,$7,$8,$9)=> `"+vocab[reg]+"`" )
|
|
// , new Function('_,$1,$2,$3,$4,$5,$6,$7,$8,$9', "return `"+vocab[reg]+"`")
|
|
)
|
|
, text
|
|
)
|
|
|
|
const legalize = replace( vocab )
|
|
|
|
|
|
console.log( legalize(po) )
|
|
process.exit()
|
|
|
|
|
|
replace({
|
|
|
|
[/test(s*)/ig]:
|
|
(_ ,s )=>
|
|
`${_.toUpperCase()}${s}`
|
|
|
|
, [/projet(s*)/ig]:
|
|
(_ ,s )=>
|
|
`projeeeeeet${s}`
|
|
|
|
})("coucou tests pRojets !!")
|
|
|
|
|
|
|
|
let legal = po.replace(
|
|
/d[ée]p[ôo]t(s*)/ig,
|
|
(depot ,s )=>
|
|
//console.log(depot,depot.test(capital),s)||
|
|
`${capital(depot)? 'I' : 'i'}nitiative${s}`
|
|
)
|
|
.replace(
|
|
/de initiative(s*)/ig,
|
|
(de_initiative,s )=>
|
|
`${s? 'des ' : "d'"}initiative${s}`
|
|
)
|
|
.replace(
|
|
/nouveau(x*) initiative(s*)/ig,
|
|
(nouveau,x ,s )=>
|
|
`${capital(nouveau)? 'N' : 'n'}ouvelle${x?'s':''} initiative${s}`
|
|
)
|
|
|
|
|
|
//ce initi.
|
|
//d'un init
|
|
//un init
|
|
//le init
|
|
//du init
|
|
|
|
console.log( legal )
|